public async Task <IActionResult> Login() { try { logger.ScopeTrace(() => "Start login."); var sequenceData = await sequenceLogic.GetSequenceDataAsync <LoginUpSequenceData>(remove : false); loginPageLogic.CheckUpParty(sequenceData); var loginUpParty = await tenantRepository.GetAsync <LoginUpParty>(sequenceData.UpPartyId); securityHeaderLogic.AddImgSrc(loginUpParty.IconUrl); securityHeaderLogic.AddImgSrcFromCss(loginUpParty.Css); (var session, var user) = await sessionLogic.GetAndUpdateSessionCheckUserAsync(loginUpParty, GetDownPartyLink(loginUpParty, sequenceData)); var validSession = session != null && ValidSessionUpAgainstSequence(sequenceData, session, loginPageLogic.GetRequereMfa(user, loginUpParty, sequenceData)); if (validSession && sequenceData.LoginAction != LoginAction.RequireLogin) { return(await loginPageLogic.LoginResponseUpdateSessionAsync(loginUpParty, sequenceData.DownPartyLink, session)); } if (sequenceData.LoginAction == LoginAction.ReadSession) { return(await loginUpLogic.LoginResponseErrorAsync(sequenceData, LoginSequenceError.LoginRequired)); } else { logger.ScopeTrace(() => "Show login dialog."); return(View(nameof(Login), new LoginViewModel { SequenceString = SequenceString, Title = loginUpParty.Title, IconUrl = loginUpParty.IconUrl, Css = loginUpParty.Css, EnableCancelLogin = loginUpParty.EnableCancelLogin, EnableResetPassword = !loginUpParty.DisableResetPassword, EnableCreateUser = !validSession && loginUpParty.EnableCreateUser, Email = sequenceData.Email.IsNullOrWhiteSpace() ? string.Empty : sequenceData.Email, })); } } catch (Exception ex) { throw new EndpointException($"Login failed, Name '{RouteBinding.UpParty.Name}'.", ex) { RouteBinding = RouteBinding }; } }
public async Task <IActionResult> RegTwoFactor() { try { logger.ScopeTrace(() => "Start two factor registration."); var sequenceData = await sequenceLogic.GetSequenceDataAsync <LoginUpSequenceData>(remove : false); loginPageLogic.CheckUpParty(sequenceData); if (sequenceData.TwoFactorAppState != TwoFactorAppSequenceStates.DoRegistration) { throw new InvalidOperationException($"Invalid {nameof(TwoFactorAppSequenceStates)} is '{sequenceData.TwoFactorAppState}'. Required to be '{TwoFactorAppSequenceStates.DoRegistration}'."); } if (!sequenceData.EmailVerified) { await accountActionLogic.SendConfirmationEmailAsync(sequenceData.Email); return(GetEmailNotConfirmedView()); } var loginUpParty = await tenantRepository.GetAsync <LoginUpParty>(sequenceData.UpPartyId); securityHeaderLogic.AddImgSrc(loginUpParty.IconUrl); securityHeaderLogic.AddImgSrcFromCss(loginUpParty.Css); var twoFactorSetupInfo = await accountTwoFactorLogic.GenerateSetupCodeAsync(loginUpParty.TwoFactorAppName, sequenceData.Email); sequenceData.TwoFactorAppNewSecret = twoFactorSetupInfo.Secret; await sequenceLogic.SaveSequenceDataAsync(sequenceData); return(View(new RegisterTwoFactorViewModel { Title = loginUpParty.Title, IconUrl = loginUpParty.IconUrl, Css = loginUpParty.Css, QrCodeSetupImageUrl = twoFactorSetupInfo.QrCodeSetupImageUrl, ManualSetupKey = twoFactorSetupInfo.ManualSetupKey })); } catch (Exception ex) { throw new EndpointException($"Start two factor registration failed, Name '{RouteBinding.UpParty.Name}'.", ex) { RouteBinding = RouteBinding }; } }