36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
|
package admin
|
||
|
|
||
|
import "C"
|
||
|
import (
|
||
|
"fmt"
|
||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/server/exts"
|
||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||
|
"github.com/gofiber/fiber/v2"
|
||
|
)
|
||
|
|
||
|
func forceConfirmAccount(c *fiber.Ctx) error {
|
||
|
userId, _ := c.ParamsInt("user")
|
||
|
|
||
|
if err := exts.EnsureGrantedPerm(c, "AdminUserConfirmation", true); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
operator := c.Locals("user").(models.Account)
|
||
|
|
||
|
var user models.Account
|
||
|
if err := database.C.Where("id = ?", userId).First(&user).Error; err != nil {
|
||
|
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("account was not found: %v", err))
|
||
|
}
|
||
|
|
||
|
if err := services.ForceConfirmAccount(user); err != nil {
|
||
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||
|
} else {
|
||
|
services.AddAuditRecord(operator, "user.confirm", c.IP(), c.Get(fiber.HeaderUserAgent), map[string]any{
|
||
|
"user_id": user.ID,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return c.SendStatus(fiber.StatusOK)
|
||
|
}
|