コード例 #1
0
 public async Task<ApiJsonResult> ResetPassword(ResetPasswordParams resetPasswordParams)
 {
     try {
         await new AccountManager().ResetPassword(resetPasswordParams);
         return new ApiJsonResult { Success = true };
     }
     catch (Exception ex) {
         return ProcessException(ex);
     }
 }
コード例 #2
0
        public async Task ResetPassword(ResetPasswordParams resetPasswordParams)
        {
            Utils.CheckNullOrEmpty(new List<string> { "ConfirmationCode", "Password" }, resetPasswordParams.ConfirmationCode, resetPasswordParams.Password);
            using (AppDbContext context = new AppDbContext())
            {
                User user = await context.Users.FirstOrDefaultAsync(p => p.ConfirmationCode == resetPasswordParams.ConfirmationCode);
                if (user == null)
                {
                    throw new UserException(ErrorCode.INVALID.ToString());
                }

                user.ConfirmationCode = null;
                user.Password = UtilsCryptography.GenerateBCryptHash(resetPasswordParams.Password);
                await context.SaveChangesAsync();
            }
        }