public static AuthenticatedUser FromString(string data) { string[] arr = data.Split('\n'); AuthenticatedUser user = new AuthenticatedUser(); user.ID = Convert.ToInt32(arr[0]); user.Name = arr[1]; user.UpdateRolesFromDB(); return user; }
private static AuthenticatedUser GetAuthenticatedUser() { AuthenticatedUser user = HttpContext.Current.Session["app_user"] as AuthenticatedUser; if (user != null) { return(user); } FormsIdentity ident = HttpContext.Current.User.Identity as FormsIdentity; if (ident != null) { user = AuthenticatedUser.FromString(ident.Ticket.UserData); HttpContext.Current.Session.Add("app_user", user); return(user); } return(null); }
public static object GetInfo(AuthenticatedUser.Info prop) { AuthenticatedUser user = GetAuthenticatedUser(); if (user != null) { switch (prop) { case AuthenticatedUser.Info.ID: return(user.ID); case AuthenticatedUser.Info.Name: return(user.Name); case AuthenticatedUser.Info.Roles: return(user.Roles); } } return(null); }
public static void SetCredentials(AuthenticatedUser user, bool rememberMe) { DateTime expiration = rememberMe ? DateTime.Now.AddMonths(1) : DateTime.Now.AddHours(3); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, user.Name, DateTime.Now, expiration, rememberMe, user.ToString(), FormsAuthentication.FormsCookiePath ); string encTicket = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); if (rememberMe) { cookie.Expires = expiration; } HttpContext.Current.Response.Cookies.Add(cookie); HttpContext.Current.Session.Add("app_user", user); }
public static object GetInfo(AuthenticatedUser.Info prop) { AuthenticatedUser user = GetAuthenticatedUser(); if (user != null) { switch (prop) { case AuthenticatedUser.Info.ID: return user.ID; case AuthenticatedUser.Info.Name: return user.Name; case AuthenticatedUser.Info.Roles: return user.Roles; } } return null; }