Skip to content

Commit 673d84d

Browse files
authored
Merge pull request #349 from yokowu/feat-admin-password
feat: 支持修改 admin 密码
2 parents b4e9d86 + 5792cb0 commit 673d84d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

backend/internal/user/repo/user.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,20 @@ func NewUserRepo(
5454
}
5555

5656
func (r *UserRepo) InitAdmin(ctx context.Context, username, password string) error {
57-
_, err := r.AdminByName(ctx, username)
57+
admin, err := r.AdminByName(ctx, username)
5858
if db.IsNotFound(err) {
59-
_, err = r.CreateAdmin(ctx, &db.Admin{
59+
if _, err := r.CreateAdmin(ctx, &db.Admin{
6060
Username: username,
6161
Password: password,
6262
Status: consts.AdminStatusActive,
63-
}, 1)
63+
}, 1); err != nil {
64+
return err
65+
}
6466
}
6567
if err != nil {
6668
return err
6769
}
68-
return nil
70+
return r.db.Admin.UpdateOneID(admin.ID).SetPassword(password).Exec(ctx)
6971
}
7072

7173
func (r *UserRepo) CreateAdmin(ctx context.Context, admin *db.Admin, roleID int64) (*db.Admin, error) {

0 commit comments

Comments
 (0)