Пример #1
0
        public virtual async Task <ActionResult> ResetKlant(ResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await UserManager.FindByNameAsync(model.Email);

            if (user == null)
            {
                ModelState.AddModelError("", "De opgegeven klant bestaat niet");
                return(View("ResetKlant"));
            }
            string resetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

            var result = await UserManager.ResetPasswordAsync(user.Id, resetToken, model.NewPassword);

            if (result.Succeeded)
            {
                user.MustChangePassword      = true;
                user.LastPasswordChangedDate = DateTime.Now;
                UserManager.UpdateGebruiker(user);
                if (user.Toegestaan == false)
                {
                    mgr.UnblockKlant(user.GebruikerId);
                }
                return(RedirectToAction("Index", "Manage", new { Message = ManageMessageId.ChangePasswordSuccess }));
            }
            AddErrors(result);
            return(View());
        }
Пример #2
0
        public virtual async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await UserManager.FindByNameAsync(model.Email);

            if (user != null)
            {
                if (user.LastPasswordChangedDate.AddMonths(6) < DateTime.Now && user.Rol != RolType.Admin)
                {
                    //mgr.BlockKlant(user.GebruikerId);
                    user.MustChangePassword = true;
                    UserManager.UpdateGebruiker(user);
                    mgr.BlockKlant(user.GebruikerId);
                    ModelState.AddModelError("", "Uw passwoord is expired. Contacteer uw admin.");
                    return(View("Login"));
                }
                if (user.LastPasswordChangedDate.AddDays(7) < DateTime.Now && user.Rol != RolType.Admin)
                {
                    //mgr.BlockKlant(user.GebruikerId);
                    ViewBag.Melding = "Passwoord vervalt binnen 7 dagen!";
                    return(View(model));
                }
                if (user.Toegestaan == false)
                {
                    ModelState.AddModelError("", "Uw account is geblokkeerd. Contacteer uw admin.");
                    return(View("Login"));
                }
                var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

                switch (result)
                {
                case SignInStatus.Success:

                    if (user.Rol == RolType.KlantAccount)
                    {
                        if (user.MustChangePassword == true)
                        {
                            returnUrl = "~/Manage/ChangePassword";
                            return(RedirectToLocal(returnUrl));
                        }
                        else
                        {
                            returnUrl = "~/Home/Index";
                            return(RedirectToLocal(returnUrl));
                        }
                    }
                    if (user.Rol == RolType.Admin)
                    {
                        if (user.MustChangePassword == true)
                        {
                            returnUrl = "~/Manage/ChangePassword";
                            return(RedirectToLocal(returnUrl));
                        }
                        else
                        {
                            returnUrl = "~/Admin/Index";
                            return(RedirectToLocal(returnUrl));
                        }
                    }
                    if (user.MustChangePassword == true)
                    {
                        returnUrl = "~/Manage/ChangePassword";
                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        returnUrl = "~/Klant/Home";
                        return(RedirectToLocal(returnUrl));
                    }

                case SignInStatus.LockedOut:
                    return(View("Lockout"));

                case SignInStatus.RequiresVerification:
                    return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

                case SignInStatus.Failure:

                default:
                    ModelState.AddModelError("", "Ongeldige Login Gegevens.");
                    return(View(model));
                }
            }
            ModelState.AddModelError("", "Ongeldige inlog gegevens");
            // TempData["Melding"] = "Passwoord vervalt binnen 7 dagen!";
            return(View(model));
        }