public async Task <ActionResult> EditPassword(EditPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _userService.GetAsync(Utility.Helpers.IdentityHelpers.GetUserId(this.HttpContext.User.Identity));

                if (_userService.VerifyPassword(user, model.CurrentPassword))
                {
                    ServiceOperationResult result = _userService.SetPassword(user, model.NewPassword);

                    if (result.Succeeded)
                    {
                        _uow.Commit();

                        await _userService.SendEmailAsync(user, EmailHelpers.UserEmails.AccountPropertyChanged("Password"));

                        TempData.Add(KeyTempDataAccountUpdates, new List <String>()
                        {
                            "Password has been changed successfully."
                        });

                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    ModelState.AddErrorForProperty <EditPasswordViewModel>(m => m.CurrentPassword, "Password is invalid.");
                }
            }

            //If we got this far something failed
            return(View(model));
        }
        public async Task <ActionResult> EditPasswordForgot(EditPasswordForgotViewModel model)
        {
            if (ModelState.IsValid)
            {
                User forgottenUser = await _userService.GetByUsernameAsync(model.Username);

                if (forgottenUser != null)
                {
                    //If the password verification token has not expired
                    if (forgottenUser.PasswordVerificationTokenExpiration > DateTime.Now)
                    {
                        if (model.ConfirmationToken == forgottenUser.PasswordVerificationToken)
                        {
                            ServiceOperationResult setPasswordResult =
                                _userService.SetPassword(forgottenUser, model.NewPassword);

                            if (setPasswordResult.Succeeded)
                            {
                                _uow.Commit();

                                await _userService.SendEmailAsync(forgottenUser, EmailHelpers.UserEmails.AccountPropertyChanged("Password"));

                                TempData.Add(KeyTempDataAccountUpdates, new List <String>()
                                {
                                    "Account password has been changed."
                                });

                                return(RedirectToAction("AnonymousAccountUpdates"));
                            }
                            else
                            {
                                ModelState.MergeErrors(setPasswordResult.Errors);
                            }

                            return(View(model));
                        }
                    }

                    return(RedirectToAction("ForgotPassword", new { passwordVerificationTokenExpired = true }));
                }

                ModelState.AddErrorForProperty <EditPasswordForgotViewModel>(m => m.Username, "Invalid username.");
            }

            return(View(model));
        }
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                User forgottenPasswordUser = await _userService.GetByEmailAsync(model.Email);

                if (forgottenPasswordUser != null)
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        try
                        {
                            String token = _userService.GeneratePasswordVerificationToken(forgottenPasswordUser);

                            _uow.Commit();

                            String changePasswordLink = Url.Action("EditPasswordForgot", "Account", new { confirmationToken = token }, Request.Url.Scheme);

                            await _userService.SendEmailAsync(forgottenPasswordUser, EmailHelpers.UserEmails.ForgottenPasswordRequest(token, changePasswordLink));

                            scope.Complete();

                            TempData.Add(KeyTempDataAccountUpdates, new List <String>()
                            {
                                "An email has been sent detailing how to recover your account."
                            });

                            return(RedirectToAction("AnonymousAccountUpdates"));
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                }

                ModelState.AddErrorForProperty <ForgotPasswordViewModel>(m => m.Email, "Invalid Email.");
            }

            return(View(model));
        }
        public async Task <ActionResult> EditEmail(EditEmailViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _userService.GetAsync(Utility.Helpers.IdentityHelpers.GetUserId(this.HttpContext.User.Identity));

                if (_userService.VerifyPassword(user, model.Password))
                {
                    user.EmailAddress = model.NewEmailAddress;

                    ServiceOperationResult result = await _userService.UpdateAsync(user);

                    if (result.Succeeded)
                    {
                        _uow.Commit();

                        await _userService.SendEmailAsync(user, EmailHelpers.UserEmails.AccountPropertyChanged("Email Address"));

                        TempData.Add(KeyTempDataAccountUpdates, new List <String>()
                        {
                            "Your email address has been changed."
                        });

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.MergeErrors(result.Errors);
                    }
                }
                else
                {
                    ModelState.AddErrorForProperty <EditEmailViewModel>(m => m.Password, "Invalid password.");
                }
            }

            //We got this far, something failed
            return(View(model));
        }