diff options
Diffstat (limited to 'internal/route/admin/users.go')
-rw-r--r-- | internal/route/admin/users.go | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/internal/route/admin/users.go b/internal/route/admin/users.go index ebdaf460..c1891fc4 100644 --- a/internal/route/admin/users.go +++ b/internal/route/admin/users.go @@ -5,6 +5,7 @@ package admin import ( + "strconv" "strings" "github.com/unknwon/com" @@ -77,22 +78,20 @@ func NewUserPost(c *context.Context, f form.AdminCrateUser) { return } - u := &db.User{ - Name: f.UserName, - Email: f.Email, - Password: f.Password, - IsActive: true, + createUserOpts := db.CreateUserOptions{ + Password: f.Password, + Activated: true, } - if len(f.LoginType) > 0 { fields := strings.Split(f.LoginType, "-") if len(fields) == 2 { - u.LoginSource = com.StrTo(fields[1]).MustInt64() - u.LoginName = f.LoginName + createUserOpts.LoginSource, _ = strconv.ParseInt(fields[1], 10, 64) + createUserOpts.LoginName = f.LoginName } } - if err := db.CreateUser(u); err != nil { + user, err := db.Users.Create(c.Req.Context(), f.UserName, f.Email, createUserOpts) + if err != nil { switch { case db.IsErrUserAlreadyExist(err): c.Data["Err_UserName"] = true @@ -108,15 +107,15 @@ func NewUserPost(c *context.Context, f form.AdminCrateUser) { } return } - log.Trace("Account created by admin (%s): %s", c.User.Name, u.Name) + log.Trace("Account %q created by admin %q", user.Name, c.User.Name) // Send email notification. if f.SendNotify && conf.Email.Enabled { - email.SendRegisterNotifyMail(c.Context, db.NewMailerUser(u)) + email.SendRegisterNotifyMail(c.Context, db.NewMailerUser(user)) } - c.Flash.Success(c.Tr("admin.users.new_success", u.Name)) - c.Redirect(conf.Server.Subpath + "/admin/users/" + com.ToStr(u.ID)) + c.Flash.Success(c.Tr("admin.users.new_success", user.Name)) + c.Redirect(conf.Server.Subpath + "/admin/users/" + strconv.FormatInt(user.ID, 10)) } func prepareUserInfo(c *context.Context) *db.User { |