public async Task <WebRedirectResult> Execute(LoginModel model) { await auth.Authenticate(model.Credentials.UserName, model.Credentials.Password); anonClient.Load(); anonClient.Persist("", DateTimeOffset.MinValue, anonClient.RequesterKey); var startUrl = model.StartUrl; if (string.IsNullOrWhiteSpace(startUrl)) { startUrl = "~/User"; } else { startUrl = HttpUtility.UrlDecode(startUrl); } if (!string.IsNullOrWhiteSpace(model.ReturnUrl)) { if (startUrl.Contains("?")) { startUrl += "&"; } else { startUrl += "?"; } startUrl += $"returnUrl={model.ReturnUrl}"; } return(new WebRedirectResult(startUrl)); }
public async Task InvokeAsync(HttpContext context, CurrentSession currentSession, TempLogSession sessionLog, IAnonClient anonClient, IClock clock, IHostEnvironment hostEnv) { anonClient.Load(); if (isAnonSessionExpired(anonClient, clock)) { expireAnonSession(anonClient); } if (context.User.Identity?.IsAuthenticated == true) { currentSession.SessionKey = new XtiClaims(context).SessionKey(); } else { currentSession.SessionKey = anonClient.SessionKey; } var session = await sessionLog.StartSession(); if (anonClient.SessionKey != session.SessionKey) { anonClient.Persist(session.SessionKey, clock.Now().AddHours(4), session.RequesterKey); } await sessionLog.StartRequest($"{context.Request.PathBase}{context.Request.Path}"); try { await _next(context); } catch (Exception ex) { await handleError(context, sessionLog, hostEnv, ex); } finally { await sessionLog.EndRequest(); } }
private static void expireAnonSession(IAnonClient anonClient) { anonClient.Persist("", DateTimeOffset.MinValue, anonClient.RequesterKey); }