예제 #1
0
        public ActionResult ProcessLoginInput(string username, string password, int? rememberMe)
        {
            try
            {
                Account account = _accountService.GetAccount(username, password);

                bool persistCookie = rememberMe > 0;
                HttpCookie httpCookie = _webAuthenticationService.CreateAuthCookie(username, account.Role.ToString(),
                                                                                   persistCookie);
                Response.Cookies.Add(httpCookie);

                if (account.MustChangePassword)
                {
                    var changePasswordViewModel =
                        new ChangePasswordViewModel(new List<string> {"You must change your password"});
                    return View("ChangePassword", changePasswordViewModel);
                }

                return RedirectToAction("Dashboard", "Home");
            }
            catch (ObjectNotFoundException)
            {
                var viewModel = new LoginViewModel();
                viewModel.AddMessage("Invalid Username/Password combination.");
                return View("Login", viewModel);
            }
            catch (Exception exception)
            {
                _logger.LogException(exception);
                return RedirectToAction("Generic", "Error");
            }
        }
예제 #2
0
        public ActionResult ProcessChangePasswordInput(string currentPassword, string newPassword)
        {
            try
            {
                _accountService.ChangePassword(new ChangePasswordRequest
                                                   {
                                                       Username = User.Identity.Name,
                                                       CurrentPassword = currentPassword,
                                                       NewPassword = newPassword,
                                                   });

                return RedirectToAction("Dashboard", "Home");
            }
            catch (ObjectNotFoundException)
            {
                var viewModel = new ChangePasswordViewModel();
                viewModel.AddMessage("Invalid Username/Password combination.");
                return View("ChangePassword", viewModel);
            }
            catch (Exception exception)
            {
                _logger.LogException(exception);
                return RedirectToAction("Generic", "Error");
            }
        }