Пример #1
0
        public async Task <ActionResult> PasswordChange(ChangePasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var oldPassValid = false;

                var user = await userManager.FindByIdAsync(model.Id);

                if (user != null && (oldPassValid = await userManager.CheckPasswordAsync(user, model.OldPassword)))
                {
                    var opResult =
                        await userManager.ChangePasswordAsync(user.Id, model.OldPassword, model.Password);

                    if (opResult.Succeeded)
                    {
                        var baseUser = await employerManager.GetBaseUserByGuid(user.Id);

                        if (baseUser.Employer != null)
                        {
                            var alert = new Alert();
                            {
                                alert.AlertId        = Guid.NewGuid();
                                alert.EmployerId     = baseUser.UserId;
                                alert.AlertType      = AlertType.Employer_ChangePassw;
                                alert.AlertIsDeleted = false;
                                alert.AlertCreateTS  = DateTime.Now;
                                alert.AlertUpdateTS  = DateTime.Now;
                                alert.UserId         = baseUser.UserId;
                            }
                            await alertManager.CreateAsync(alert);
                        }
                        return(View("PasswordChanged"));
                    }
                }
                else if (!oldPassValid)
                {
                    ModelState.AddModelError(nameof(model.OldPassword), "Old password is invalid");
                }
            }
            else
            {
                ModelState.AddModelError("", "Server probleem(Probeer a.u.b.later)");
            }

            return(View("PasswordChange"));
        }