private bool IsCookiePlaced() { var userCookie = CookieService.GetCookie(Constantes.UserCookieName); if (userCookie != null) { if (int.TryParse(userCookie.Value, out int userId)) { var user = userService.GetUser(userId); int offset = Int16.Parse(CookieService.GetCookieStringValue(Constantes.UserTimeOffset)); userService.SetPrincipal(user, offset); return(true); } } return(false); }
public void SetPrincipal(User user, int userTimeOffset) { var webIdentity = new WebIdentity { Name = user.Name, IsAuthenticated = true }; var webPrincipal = new WebPrincipal { Identity = webIdentity }; Thread.CurrentPrincipal = webPrincipal; if (HttpContext.Current != null) { HttpContext.Current.User = webPrincipal; } //add time zone info and id to user cookies CookieService.AddCookie(Constantes.UserCookieName, user.UserId); CookieService.AddCookie(Constantes.UserTimeOffset, userTimeOffset); }