|
@@ -250,13 +250,8 @@ func (a *Admin) QueryUserByUsername(ctx context.Context, username string) (*mode
|
|
|
// ChangePassword 修改管理员密码
|
|
|
func (a *Admin) ChangePassword(ctx context.Context, username string, password string) *code.Result {
|
|
|
// 更新密码
|
|
|
- newPassword, err := HashPassword(password)
|
|
|
- if err != nil {
|
|
|
- mhayaLogger.Warnf("ChangePassword HashPassword error:%v", err)
|
|
|
- return common.NewResult(code.InternalError)
|
|
|
- }
|
|
|
-
|
|
|
- _, err = mdb.MDB.Collection(a.GetDBName()).UpdateOne(ctx, bson.M{"username": username}, bson.M{"$set": bson.M{"password": newPassword}})
|
|
|
+ password, _ = HashPassword(password)
|
|
|
+ _, err := mdb.MDB.Collection(a.GetDBName()).UpdateOne(ctx, bson.M{"username": username}, bson.M{"$set": bson.M{"password": password}})
|
|
|
if err != nil {
|
|
|
mhayaLogger.Warnf("ChangePassword UpdateOne error:%v", err)
|
|
|
return common.NewResult(code.InternalError)
|
|
@@ -271,15 +266,10 @@ func (a *Admin) Add(ctx context.Context, username string, password string, realN
|
|
|
admin := model.Admin{}
|
|
|
err := mdb.MDB.Collection(a.GetDBName()).FindOne(ctx, bson.M{"username": username}).Decode(&admin)
|
|
|
if errors.Is(err, mongo.ErrNoDocuments) {
|
|
|
- newPassword, err := HashPassword(password)
|
|
|
- if err != nil {
|
|
|
- mhayaLogger.Warnf("Add HashPassword error:%v", err)
|
|
|
- return common.NewResult(code.InternalError)
|
|
|
- }
|
|
|
-
|
|
|
- _, err = mdb.MDB.Collection(a.GetDBName()).InsertOne(ctx, bson.M{
|
|
|
+ password, _ = HashPassword(password)
|
|
|
+ _, err := mdb.MDB.Collection(a.GetDBName()).InsertOne(ctx, bson.M{
|
|
|
"username": username,
|
|
|
- "password": newPassword,
|
|
|
+ "password": password,
|
|
|
"real_name": realName,
|
|
|
"pid": pid,
|
|
|
"role_id": roleId,
|