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 <AppEnvironment> Value() { if (value == null) { anonClient.Load(); var user = await userContext.User(); var requesterKey = anonClient.RequesterKey; if (string.IsNullOrWhiteSpace(requesterKey)) { requesterKey = Guid.NewGuid().ToString("N"); } var userAgent = httpContextAccessor.HttpContext?.Request.Headers["User-Agent"].ToString() ?? ""; var remoteAddress = httpContextAccessor.HttpContext?.Connection.RemoteIpAddress?.ToString() ?? ""; value = new AppEnvironment ( user.UserName().Value, requesterKey, remoteAddress, userAgent, AppType.Values.WebApp.DisplayText ); } return(value); }
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(); } }