Esempio n. 1
0
        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            if (model != null)
            {
                string currentUserName = User.Identity.Name;

                if (!ModelState.IsValid
                    ||
                    (!currentUserName.Equals(model.UserName) && !_accountManager.IsAdmin(HttpContext.GetOwinContext(), currentUserName)))
                {
                    model.Password = model.OldPassword = model.PasswordConfirm = "";
                    return(View(model));
                }

                IdentityResult res = _accountManager.ChangePassword(HttpContext.GetOwinContext(), model);

                if (!res.Succeeded)
                {
                    foreach (var error in res.Errors)
                    {
                        ModelState.AddModelError("", error);
                    }
                    model.Password = model.OldPassword = model.PasswordConfirm = "";
                    return(View(model));
                }

                if (!string.IsNullOrEmpty(model.ReturnUrl))
                {
                    return(Redirect(model.ReturnUrl));
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
        public IActionResult Post([FromBody] ChangePassDto changePass)
        {
            string userName = "";

            if (User != null)
            {
                try
                {
                    userName = User.FindFirst(ClaimTypes.Name).Value;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                    Console.WriteLine(new Response("401", "Error: Unauthorized"));
                    return(Unauthorized(new Response("401", "Error: Unauthorized")));
                }
            }
            try
            {
                string mess = _account.ChangePassword(userName, changePass);
                return(Ok(new Response("200", mess)));
            }catch (Exception ex)
            {
                return(BadRequest(new Response("400", ex.Message)));
            }
        }
Esempio n. 3
0
        public BaseResponse ChangePassword(string customerCode, string oldPassword, string newPassword, string useScope)
        {
            PasswordUseScope scope = useScope.Equals(PasswordUseScope.OptionTrade.InternalValue)
                                ? PasswordUseScope.OptionTrade
                                : PasswordUseScope.OptionFund;

            return(_accountManager.ChangePassword(customerCode, scope, oldPassword, newPassword));
        }
        public async Task <ChangePasswordResponse> Handle(ChangePasswordRequest request,
                                                          CancellationToken cancellationToken)
        {
            var(token, email, newPassword) = (cryptoService.Decrypt(request.Token),
                                              cryptoService.Decrypt(request.Email), cryptoService.Decrypt(request.NewPassword));

            return(await accountManager.ChangePassword(newPassword, email, token)
                ? new ChangePasswordResponse()
                : throw new ChangePasswordException("Error occured during changing password"));
        }
Esempio n. 5
0
 public async Task <CommandResult <bool> > ChangePassword([FromBody] ChangePasswordModel changePassword)
 {
     try
     {
         return(await _accountManager.ChangePassword(changePassword.CurrentPassword, changePassword.NewPassword));
     }
     catch (Exception ex)
     {
         return(new CommandResult <bool>(ex.Message));
     }
 }
Esempio n. 6
0
        public async Task <IActionResult> ChangePassword(int id, UserToChangePasswordDto userToChangePasswordDto)
        {
            var user = await accountManager.GetUser(id);

            if (await accountManager.ChangePassword(user, userToChangePasswordDto.OldPassword, userToChangePasswordDto.NewPassword))
            {
                return(NoContent());
            }

            return(BadRequest("Stare hasło jest niepoprawne"));
        }
        public async Task <IActionResult> ChangePassword(ChangePasswordViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            var result = await _accountManager.ChangePassword(User, vm);

            if (!result.Succeeded)
            {
                AddErrors(result);
                return(View(vm));
            }

            StatusMessage = "Your password has been changed.";
            return(RedirectToAction(nameof(ChangePassword)));
        }
Esempio n. 8
0
        public IActionResult ProfileEdit(string Name, string Surname, string Description, string OldPassword, string NewPassword, string AnsString)
        {
            if (AnsString == "Cancel")
            {
                return(View(new ProfileEditViewModel("Cancel")));
            }

            if (OldPassword == null && NewPassword != null || OldPassword != null && NewPassword == null)
            {
                return(View(new ProfileEditViewModel("EmptyPassword")));
            }

            var user = repository.GetById(accountManager.GetUserId(User));

            if (OldPassword != null && NewPassword != null)
            {
                if (!accountManager.CheckPassword(user, OldPassword))
                {
                    return(View(new ProfileEditViewModel("WrongPassword")));
                }
            }

            if (OldPassword == NewPassword && OldPassword != null && NewPassword != null)
            {
                return(View(new ProfileEditViewModel("SamePassword")));
            }

            if (AnsString == "Confirm")
            {
                if (OldPassword != null && NewPassword != null)
                {
                    if (accountManager.CheckPassword(user, OldPassword))
                    {
                        var ValidationResult = accountManager.ValidatePassword(user, NewPassword);
                        if (ValidationResult.Succeeded)
                        {
                            accountManager.ChangePassword(user, OldPassword, NewPassword);
                        }
                        else
                        {
                            return(View(new ProfileEditViewModel("ValidationError", ValidationResult.Errors)));
                        }
                    }
                }

                if (Name != null)
                {
                    user.Name = Name;
                }
                if (Surname != null)
                {
                    user.Surname = Surname;
                }
                if (Description != null)
                {
                    user.Description = Description;
                }
                repository.Update(user);
                return(View(new ProfileEditViewModel("Confirm")));
            }
            return(View(new ProfileEditViewModel("")));
        }