/// <summary> /// Logs the user out and redirects them to a URL /// </summary> /// <param name="context">Current context</param> /// <param name="redirectUrl">URL to redirect to</param> /// <returns>Nancy response</returns> public static Response LogOutAndRedirectResponse(NancyContext context, string redirectUrl) { var response = context.GetRedirect(redirectUrl); var authenticationCookie = BuildLogoutCookie(currentConfiguration); response.AddCookie(authenticationCookie); return response; }
private Response SetCurrentUserToViewBag(NancyContext ctx) { var author = _viewProjectionFactory.Get<string, Author>(ctx.CurrentUser.UserName); if (author == null) return ctx.GetRedirect("/mz-login?returnUrl=" + Request.Url.Path).WithCookie(FormsAuthentication.CreateLogoutCookie()); ViewBag.CurrentUser = author; return null; }
private Response SetContextUserFromAuthenticationCookie(NancyContext ctx) { var username = FormsAuthentication.GetAuthUsernameFromCookie(ctx); if (username.IsNullOrWhitespace()) return ctx.GetRedirect("/mz-login?returnUrl=" + Request.Url.Path).WithCookie(FormsAuthentication.CreateLogoutCookie()); ctx.CurrentUser = new BlogUserIdentity(username, new string[] {"admin" }); return null; }
/// <summary> /// Creates a response that sets the authentication cookie and redirects /// the user back to where they came from. /// </summary> /// <param name="context">Current context</param> /// <param name="userIdentifier">User identifier guid</param> /// <param name="cookieExpiry">Optional expiry date for the cookie (for 'Remember me')</param> /// <param name="fallbackRedirectUrl">Url to redirect to if none in the querystring</param> /// <returns>Nancy response with redirect.</returns> public static Response UserLoggedInRedirectResponse(NancyContext context, Guid userIdentifier, DateTime? cookieExpiry = null, string fallbackRedirectUrl = "/") { var redirectUrl = fallbackRedirectUrl; var response = context.GetRedirect(redirectUrl); var authenticationCookie = BuildCookie(userIdentifier, cookieExpiry, currentConfiguration); response.AddCookie(authenticationCookie); return response; }