public async Task <IActionResult> RecoverPassword([FromBody] UserPasswordRecovery recoveryInfo)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser appUser = null;

                if (recoveryInfo.UsernameOrEmail.Contains("@"))
                {
                    appUser = await _accountManager.GetUserByEmailAsync(recoveryInfo.UsernameOrEmail);
                }

                if (appUser == null)
                {
                    appUser = await _accountManager.GetUserByUserNameAsync(recoveryInfo.UsernameOrEmail);
                }

                if (appUser == null || !(await _accountManager.IsEmailConfirmedAsync(appUser)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(Accepted());
                }

                string code = await _accountManager.GeneratePasswordResetTokenAsync(appUser);

                string callbackUrl = $"{Request.Scheme}://{Request.Host}/ResetPassword?code={code}";
                string message     = EmailTemplates.GetResetPasswordEmail(appUser.UserName, HtmlEncoder.Default.Encode(callbackUrl));

                await _emailSender.SendEmailAsync(appUser.UserName, appUser.Email, "Reset Password", message);

                return(Accepted());
            }

            return(BadRequest(ModelState));
        }
Esempio n. 2
0
        public async Task RecoverPassword()
        {
            IsBusy = true; FormValid = false;
            string ModalParams;
            var    result           = AuthService.RecoverPasswordAsync(UserRecovery);
            UserPasswordRecovery lr = await result;

            if (!string.IsNullOrEmpty(lr.UsernameOrEmail))
            {
                var m = new ModalSuccess
                {
                    Title   = Translate.Keys["Recover"],
                    Message = $"{ Translate.Keys["CheckYourEmail"] }"
                };
                ModalParams = JsonSerializer.Serialize(m);
            }
            else
            {
                var m = new ModalError
                {
                    Title   = Translate.Keys["Recover"],
                    Message = $"{ Translate.Keys["UNotFoundOrMNotConfirmed"] }"
                };
                ModalParams = JsonSerializer.Serialize(m);
            }
            await CloseLoginModal(true);

            await JsRuntime.InvokeVoidAsync("showModalDialog", ModalParams);
        }
        public IActionResult ResetPassword([FromBody] UserPasswordRecovery userParam)
        {
            try
            {
                var user = this.AuthService.PasswordReset(userParam.Username, userParam.NewPassword, userParam.OldPassword, userParam.PasswordResetHash);

                return(Ok(user));
            }
            catch (System.Exception ex)
            {
                if (ex.Message == "password-history")
                {
                    return(new UnauthorizedObjectResult(new { Message = ex.Message }));
                }
                else if (ex.Message == "wrong-password")
                {
                    return(BadRequest(new { message = "Username or password is incorrect" }));
                }
                else if (ex.Message == "invalid-password")
                {
                    return(BadRequest(new { message = "Password does not comply with minimal security rules" }));
                }
                else if (ex.Message == "user-not-valid")
                {
                    return(Forbid());
                }

                throw;
            }
        }
Esempio n. 4
0
        public async Task <UserPasswordRecovery> RecoverPasswordAsync(UserPasswordRecovery passwordRecovery)
        {
            try
            {
                var response = await _genericRepository.PostAsync <UserPasswordRecovery>("api/account/recoverpassword", passwordRecovery);

                return(response);
            }
            catch (HttpRequestExceptionEx e)
            {
                Debug.WriteLine(e.HttpCode);
                return(new UserPasswordRecovery());
            }
        }