diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index c393935..1d3786f 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,14 +4,12 @@
-
-
-
+
+
-
-
-
+
+
@@ -157,7 +155,6 @@
-
@@ -182,7 +179,8 @@
-
+
+
true
diff --git a/pkg/internal/server/admin/index.go b/pkg/internal/server/admin/index.go
index b26b3ea..d3557c6 100644
--- a/pkg/internal/server/admin/index.go
+++ b/pkg/internal/server/admin/index.go
@@ -13,5 +13,6 @@ func MapAdminAPIs(app *fiber.App) {
admin.Post("/notify/all", notifyAllUser)
admin.Put("/users/:user/permissions", editUserPermission)
+ admin.Post("/users/:user/confirm", forceConfirmAccount)
}
}
diff --git a/pkg/internal/server/admin/permissions_api.go b/pkg/internal/server/admin/permissions_api.go
index 4db3148..192c684 100644
--- a/pkg/internal/server/admin/permissions_api.go
+++ b/pkg/internal/server/admin/permissions_api.go
@@ -37,6 +37,7 @@ func editUserPermission(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
} else {
services.AddAuditRecord(operator, "user.permissions.edit", c.IP(), c.Get(fiber.HeaderUserAgent), map[string]any{
+ "user_id": user.ID,
"previous_permissions": prev,
"new_permissions": data.PermNodes,
})
diff --git a/pkg/internal/server/admin/user_api.go b/pkg/internal/server/admin/user_api.go
new file mode 100644
index 0000000..84c3277
--- /dev/null
+++ b/pkg/internal/server/admin/user_api.go
@@ -0,0 +1,35 @@
+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)
+}
diff --git a/pkg/internal/services/accounts.go b/pkg/internal/services/accounts.go
index ea62583..c1f82eb 100644
--- a/pkg/internal/services/accounts.go
+++ b/pkg/internal/services/accounts.go
@@ -11,7 +11,6 @@ import (
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
"github.com/google/uuid"
"github.com/samber/lo"
- "gorm.io/gorm"
)
func GetAccount(id uint) (models.Account, error) {
@@ -112,28 +111,33 @@ func ConfirmAccount(code string) error {
return err
}
- return database.C.Transaction(func(tx *gorm.DB) error {
- user.ConfirmedAt = lo.ToPtr(time.Now())
+ if err = ForceConfirmAccount(user); err != nil {
+ return err
+ } else {
+ database.C.Delete(&token)
+ }
- for k, v := range viper.GetStringMap("permissions.verified") {
- if val, ok := user.PermNodes[k]; !ok {
- user.PermNodes[k] = v
- } else {
- user.PermNodes[k] = val
- }
+ return nil
+}
+
+func ForceConfirmAccount(user models.Account) error {
+ user.ConfirmedAt = lo.ToPtr(time.Now())
+
+ for k, v := range viper.GetStringMap("permissions.verified") {
+ if val, ok := user.PermNodes[k]; !ok {
+ user.PermNodes[k] = v
+ } else {
+ user.PermNodes[k] = val
}
+ }
- if err := database.C.Delete(&token).Error; err != nil {
- return err
- }
- if err := database.C.Save(&user).Error; err != nil {
- return err
- }
+ if err := database.C.Save(&user).Error; err != nil {
+ return err
+ }
- InvalidAuthCacheWithUser(user.ID)
+ InvalidAuthCacheWithUser(user.ID)
- return nil
- })
+ return nil
}
func CheckAbleToResetPassword(user models.Account) error {