Ejemplo n.º 1
0
        public async Task <bool> ResetPassword(PassordResetDTO model)
        {
            if (string.IsNullOrEmpty(model.UserNameOrEmail))
            {
                throw await _svcHelper.GetExceptionAsync(ErrorConstants.USER_ACCOUNT_NOT_EXIST);
            }

            var user = await FindByNameAsync(model.UserNameOrEmail) ?? await FindByEmailAsync(model.UserNameOrEmail);

            await ValidateUser(user);

            if (user.OTP != model.Code)
            {
                throw new LMEGenericException("Invalid OTP");
                // throw await _svcHelper.GetExceptionAsync(ErrorConstants.USER_ACCOUNT_WRONG_OTP);
            }

            var changeToken = await _userManager.GeneratePasswordResetTokenAsync(user);

            var result = await _userManager.ResetPasswordAsync(user, changeToken, model.NewPassword);

            if (!result.Succeeded)
            {
                throw await _svcHelper.GetExceptionAsync(result.Errors?.FirstOrDefault().Description);
            }

            user.OTP = null;
            await _userManager.UpdateAsync(user);

            return(true);
        }
Ejemplo n.º 2
0
 public async Task <ServiceResponse <bool> > ResetPassword(PassordResetDTO model)
 {
     return(await HandleApiOperationAsync(async() => {
         var result = await _userSvc.ResetPassword(model);
         return new ServiceResponse <bool>(result);
     }));
 }