public async Task <IActionResult> AuthorizationCode(AuthorizationCodeViewModel viewmodel) { if (!AuthUser.Identity.IsAuthenticated) { // not logged in, redirect to login page return(RedirectToRoute(new { area = string.Empty, controller = "SignIn", ReturnUrl = "/MissionControl" })); } if (ModelState.IsValid) { string sanitized = _codeSanitizer.Sanitize(viewmodel.AuthorizationCode, 255); try { string role = await _userService.ActivateAuthorizationCode(sanitized); if (!string.IsNullOrEmpty(role)) { var auth = await _authenticationService .RevalidateUserAsync(GetId(ClaimType.UserId)); auth.AuthenticationMessage = $"Code applied, you are now a member of the role: <strong>{role}</strong>."; await LoginUserAsync(auth); return(RedirectToRoute(new { area = "MissionControl", controller = "Home", action = "Index" })); } else { ShowAlertDanger("Invalid code. This request was logged."); } } catch (GraException gex) { ShowAlertDanger("Unable to activate code: ", gex); } } var site = await GetCurrentSiteAsync(); string siteLogoUrl = site.SiteLogoUrl ?? Url.Content(Defaults.SiteLogoPath); return(View(new AuthorizationCodeViewModel { SiteLogoUrl = siteLogoUrl })); }
public async Task <IActionResult> AuthorizationCode(AuthorizationCodeViewModel viewmodel) { if (!AuthUser.Identity.IsAuthenticated) { return(RedirectToSignIn()); } if (ModelState.IsValid) { string sanitized = _codeSanitizer.Sanitize(viewmodel.AuthorizationCode, 255); try { string role = await _userService.ActivateAuthorizationCode(sanitized); if (!string.IsNullOrEmpty(role)) { var auth = await _authenticationService .RevalidateUserAsync(GetId(ClaimType.UserId)); // TODO globalize auth.Message = $"Code applied, you are a member of the role: {role}."; await LoginUserAsync(auth); return(RedirectToRoute(new { area = "MissionControl", controller = "Home", action = "Index" })); } else { ShowAlertDanger("Invalid code. This request was logged."); } } catch (GraException gex) { ShowAlertDanger("Unable to activate code: ", gex); } } return(View()); }
public async Task <IActionResult> AuthorizationCode(AuthorizationCodeViewModel model) { var site = await GetCurrentSiteAsync(); if (!TempData.ContainsKey(AuthCodeAttempts) || (int)TempData.Peek(AuthCodeAttempts) < 5) { var sanitized = model.AuthorizationCode.Trim().ToLowerInvariant(); if (await _authorizationCodeService.ValidateAuthorizationCode(sanitized)) { TempData.Remove(AuthCodeAttempts); TempData[EnteredAuthCode] = model.AuthorizationCode; ShowAlertInfo("Authorization code accepted."); if (site.SinglePageSignUp) { return(RedirectToAction(nameof(Index))); } else { return(RedirectToAction(nameof(Step1))); } } if (TempData.ContainsKey(AuthCodeAttempts)) { TempData[AuthCodeAttempts] = (int)TempData[AuthCodeAttempts] + 1; } else { TempData[AuthCodeAttempts] = 1; } } if (TempData.ContainsKey(AuthCodeAttempts) && (int)TempData.Peek(AuthCodeAttempts) >= 5) { ShowAlertDanger("Too many failed authorization attempts."); return(RedirectToAction(nameof(HomeController.Index), HomeController.Name)); } ShowAlertDanger("Invalid authorization code."); return(View()); }
public async Task <IActionResult> AuthorizationCode(AuthorizationCodeViewModel viewmodel) { if (!AuthUser.Identity.IsAuthenticated) { // not logged in, redirect to login page return(RedirectToSignIn()); } if (ModelState.IsValid) { string sanitized = viewmodel.AuthorizationCode.Trim().ToLowerInvariant(); try { string role = await _userService.ActivateAuthorizationCode(sanitized); if (!string.IsNullOrEmpty(role)) { var auth = await _authenticationService .RevalidateUserAsync(GetId(ClaimType.UserId)); // TODO globalize auth.Message = $"Code applied, you are a member of the role: {role}."; await LoginUserAsync(auth); return(RedirectToAction(nameof(Index))); } else { ShowAlertDanger("Invalid code. This request was logged."); } } catch (GraException gex) { ShowAlertDanger("Unable to activate code: ", gex); } } return(View()); }
public async Task <IActionResult> AuthorizationCode(AuthorizationCodeViewModel viewmodel) { if (!AuthUser.Identity.IsAuthenticated) { // not logged in, redirect to login page return(RedirectToRoute(new { area = string.Empty, controller = "SignIn", ReturnUrl = "/MissionControl" })); } string role = await _userService.ActivateAuthorizationCode(viewmodel.AuthorizationCode); if (!string.IsNullOrEmpty(role)) { var auth = await _authenticationService .RevalidateUserAsync(GetId(ClaimType.UserId)); auth.AuthenticationMessage = $"Code applied, you are now a member of the role: <strong>{role}</strong>."; await LoginUserAsync(auth); return(RedirectToRoute(new { area = "MissionControl", controller = "Home", action = "Index" })); } else { ShowAlertDanger("Invalid code. This request was logged."); return(View("AuthorizationCode")); } }