public async Task <ActionResult> PasswordResetRequest(PasswordLostVm passLostVm)
        {
            var result = View(passLostVm);

            if (ModelState.IsValid)
            {
                // Create and send the new token.
                var stggResult = await Managers.UserAccountManager.RequestPasswordResetTokenAsync(passLostVm);

                return(stggResult.Status == StggResultStatus.Succeeded
                                        ? RedirectToAction("PasswordResetTokenSent")
                                        : RedirectToAction("Status", "Error", new { @id = 500 }));
            }

            return(result);
        }
Example #2
0
        /// <summary>
        ///     Request a reset password token. Send it to the user's email.
        /// </summary>
        /// <param name="passLostVm">Forgot password view model.</param>
        public async Task <StggResult> RequestPasswordResetTokenAsync(PasswordLostVm passLostVm)
        {
            var stggResult = new StggResult();

            // Let's get more info about this user with the view model data.
            var user = passLostVm.ValidateByUserName
                                ? await AppUserManager.FindByNameAsync(passLostVm.UserName)
                                : await AppUserManager.FindByEmailAsync(passLostVm.Email);

            if (user != null)
            {
                // Create new confirmation token for this user.
                var token = await AppUserManager.GeneratePasswordResetTokenAsync(user.Id);

                if (string.IsNullOrEmpty(token))
                {
                    stggResult.AddError("The password reset token generation failed.");
                }
            }

            return(stggResult);
        }