public ActionResult Licence(int id)
        {
            session.SetCurrentUserIsAdmin(true);
            session.SetCurrentLicenceId(id);
            var model = licenceBuilder.Build <AdminLicenceViewModel>(id);

            return(View("Application", model));
        }
Example #2
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, isPersistent : true, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    var user = await _userManager.FindByEmailAsync(model.Email);

                    _logger.TimedLog(LogLevel.Information, $"User {user.Email} logged in.");

                    var isAdmin = await _userManager.IsInRoleAsync(user, "Administrator");

                    if (isAdmin)
                    {
                        _logger.TimedLog(LogLevel.Information, $"User {user.Email} accessed role 'Administrator'");

                        return(RedirectToAction("Index", "Admin"));
                    }

                    _logger.TimedLog(LogLevel.Information, $"User {user.Email} accessed role 'Labour Provider'");

                    var licence = licenceApplicationViewModelBuilder.BuildLicencesForUser(user.Id).FirstOrDefault();

                    if (licence != null)
                    {
                        session.SetCurrentLicenceId(licence.Id);

                        return(RedirectToAction("Portal", "Licence", null));
                    }

                    return(RedirectToAction("TaskList", "Licence"));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToAction(nameof(LoginWith2fa), new { returnUrl }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToAction(nameof(Lockout)));
                }
                else
                {
                    ViewData["doOverride"] = true;
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(View(model));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult Introduction(LicenceApplicationViewModel model)
        {
            model.NewLicenceStatus = LicenceStatusEnum.NewApplication;

            var licenceId = licenceApplicationPostDataHandler.Insert(model);

            session.SetCurrentLicenceId(licenceId);

            return(RedirectToAction($"Part/1"));
        }