Exemple #1
0
 public Task <Admin_users> AuthenticateAysnc(string username, string password)
 {
     return(Task.Run(() =>
     {
         Admin_users user = null;
         if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
         {
             user = _context.admin_users.SingleOrDefault(x => x.userName == username);
         }
         if (user != null && VerifyPasswordHash(password, user.passwordHash, user.passwordSalt))
         {
             return user;
         }
         return null;
     }));
 }
Exemple #2
0
 public Task <Admin_users> CreateAysnc(Admin_users user, string password)
 {
     return(Task.Run(() =>
     {
         if (string.IsNullOrWhiteSpace(password))
         {
             throw new AppException("请输入密码");
         }
         if (_context.admin_users.Any(x => x.userName == user.userName))
         {
             throw new AppException("用户名 \"" + user.userName + "\" 已存在");
         }
         CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt);
         user.passwordHash = passwordHash;
         user.passwordSalt = passwordSalt;
         _context.admin_users.Add(user);
         _context.SaveChanges();
         return user;
     }));
 }
Exemple #3
0
 public Task UpdateAysnc(Admin_users userParam, string password = null)
 {
     return(Task.Run(() =>
     {
         var user = _context.admin_users.Find(userParam.id);
         if (user == null)
         {
             throw new AppException("未找到该用户");
         }
         if (userParam.userName != user.userName)
         {
             if (_context.admin_users.Any(x => x.userName == userParam.userName))
             {
                 throw new AppException("用户名 " + userParam.userName + " 已存在");
             }
             user.userName = userParam.userName;
         }
         user.phone = userParam.phone;
         user.roleId = userParam.roleId;
         user.roleKey = userParam.roleKey;
         user.name = userParam.name;
         user.avatar = userParam.avatar;
         user.email = userParam.email;
         user.introduction = userParam.introduction;
         user.updateTime = userParam.updateTime;
         user.status = userParam.status;
         if (!string.IsNullOrWhiteSpace(password))
         {
             CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt);
             user.passwordHash = passwordHash;
             user.passwordSalt = passwordSalt;
         }
         _context.admin_users.Update(user);
         _context.SaveChanges();
     }));
 }