コード例 #1
0
        public ActionResult Index(DeclarationViewModel model)
        {
            session.SetString("LastSubmittedPageSection", "Index");
            session.SetString("LastSubmittedPageId", "Declaration");

            if (!ModelState.IsValid)
            {
                return(View("Index", model));
            }

            licenceApplicationPostDataHandler.Update(session.GetCurrentLicenceId(), x => x, model);

            return(RedirectToAction("TaskList", "Licence"));
        }
コード例 #2
0
        public IActionResult Index(PublicRegisterLicenceListViewModel publicRegisterLicenceListViewModel, string submitButtonType)
        {
            SessionHelper.Set("publicRegisterSearchCriteria", publicRegisterLicenceListViewModel.PublicRegisterSearchCriteria);
            SessionHelper.SetString("publicRegisterSearchCriteria_submitButtonType", submitButtonType);

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public async Task <IActionResult> SaveEmailAddress(PrincipalAuthorityEmailAddressViewModel model)
        {
            session.SetSubmittedPage(FormSection.SignUp, 1);

            if (await accountCreationPostDataHandler.ExistsAsync(model.EmailAddress))
            {
                ViewData["doOverride"] = true;
                ModelState.AddModelError("EmailAddress", "A user with this email address already exists in the system.");
            }

            if (!ModelState.IsValid)
            {
                return(View(GetViewPath(FormSection.SignUp, 1), model));
            }

            // Don't overwrite an unconfirmed user if we're currently editing that user
            if (!model.EmailAddress.Equals(session.GetString(CurrentPaEmail),
                                           StringComparison.InvariantCultureIgnoreCase))
            {
                await accountCreationPostDataHandler.DeleteIfUnconfirmedAsync(model.EmailAddress);
            }

            session.SetString(CurrentPaEmail, model.EmailAddress);

            await accountCreationPostDataHandler.UpdateAsync(model.EmailAddress, model);

            return(CheckParentValidityAndRedirect(1));
        }
コード例 #4
0
        public async Task <IActionResult> LoginAsync(string returnUrl, LoginModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //hash password
                    var password = Crypto.HashPassword(model.Password);
                    var user     = await _userService.LoginAsync(model.Email, password);

                    if (user != null && user.Status == (int)UserStatus.Active)
                    {
                        await _userService.UpdateLastLoginDateAsync(user.Email);

                        _sessionHelper.SetString(SessionKey.CurrentUserId, user.Id.ToString());
                        _sessionHelper.Set(SessionKey.CurrentUser, user);
                        _sessionHelper.Set(SessionKey.CurrentRole, await _roleService.GetByIdAsync(user.RoleId));

                        var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
                        identity.AddClaim(new Claim(ClaimTypes.Name, model.Email));

                        var principle  = new ClaimsPrincipal(identity);
                        var properties = new AuthenticationProperties
                        {
                            IsPersistent = model.RememberMe
                        };
                        await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principle, properties);

                        if (!string.IsNullOrEmpty(returnUrl) && returnUrl.ToLowerInvariant().Contains("logout"))
                        {
                            returnUrl = "/admin";
                        }

                        return(LocalRedirect(returnUrl ?? "/admin"));
                    }
                }

                SetTitle("Đăng nhập", "login");
                ViewData["ReturnUrl"] = returnUrl;
                ModelState.AddModelError(string.Empty, "Email hoặc Mật khẩu không chính xác.");
                return(View("Login", model));
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "AccountController > LoginAsync");
                return(NotFound());
            }
        }