Esempio n. 1
0
        public async Task <string> RedeemPasswordTokenAsync(string token, string emailAddress, string password)
        {
            var userToken = await _context.UserTokens.FirstOrDefaultAsync(x => x.Token.Equals(token, StringComparison.OrdinalIgnoreCase));

            if (userToken == null)
            {
                return("Invalid Token. Please Request Reset Password Token Again...");
            }

            if (!userToken.User.EmailAddress.Equals(emailAddress, StringComparison.OrdinalIgnoreCase))
            {
                return("Invalid Token. This Token does not match the Email Address you entered...");
            }

            if (userToken.DateRedeemed.HasValue)
            {
                return("Invalid Token. This Token has already been used");
            }

            await _registrationService.ChangePasswordAsync(userToken.User.UserId, password);

            userToken.DateRedeemed = DateTime.Now;
            await _context.SaveChangesAsync();

            return(string.Empty);
        }
Esempio n. 2
0
        public async Task <ActionResult> EditPassword(PasswordViewModel model)
        {
            if (ModelState.IsValid && !model.NewPassword.Equals(model.ConfirmPassword, StringComparison.OrdinalIgnoreCase))
            {
                ModelState.AddModelError("NewPasswordMismatch", "Your new password and confirm password do not match...");
            }

            if (!ModelState.IsValid)
            {
                model.NewPassword     = string.Empty;
                model.ConfirmPassword = string.Empty;

                return(View("_Password", model));
            }

            await _registrationService.ChangePasswordAsync(UserHelper.UserId.Value, model.NewPassword);

            var websiteAddress = $@"http://{System.Web.HttpContext.Current.Request.Url.Authority}";

            EmailHelper.Send(new List <string> {
                UserHelper.EmailAddress
            }, "Account Notice", $"<p>Hello {UserHelper.FullName}</p><p>We just wanted to let you know that your password was changed at {websiteAddress}. If you didn't change your password, please let us know");

            return(Content("Refresh"));
        }
        public async Task <IActionResult> ChangePassword(ChangePasswordParamsDTO changePasswordParams)
        {
            try
            {
                await _registrationService.ChangePasswordAsync(changePasswordParams);

                return(Ok());
            }
            catch (IncorrectParamsException e)
            {
                return(BadRequest(e.Message));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Esempio n. 4
0
        public async Task <ActionResult> EditPassword(PasswordViewModel model)
        {
            if (ModelState.IsValid && !model.NewPassword.Equals(model.ConfirmPassword, StringComparison.OrdinalIgnoreCase))
            {
                ModelState.AddModelError("NewPasswordMismatch", "Your new password and confirm password do not match...");
            }

            if (!ModelState.IsValid)
            {
                model.NewPassword     = string.Empty;
                model.ConfirmPassword = string.Empty;

                return(View("_Password", model));
            }

            await _registrationService.ChangePasswordAsync(UserHelper.Id, model.NewPassword);

            await EmailHelper.SendPasswordChangedAsync(UserHelper.Email, UserHelper.FullName);

            return(Content("Refresh"));
        }