public Task<UserViewModel> GetUser() { return Task.Factory.StartNew(() => { if (IsAuthenticated()) { var user = _userService.GetUser(); var model = new UserViewModel {Name = user.Name, IsAuthenticated = true}; return model; } return null; }); }
public override void OnAuthorization(AuthorizationContext filterContext) { var controller = filterContext.Controller as BaseController; if (controller != null) { var userViewModel = new UserViewModel(); if (filterContext.HttpContext.Request.Cookies[UserCookieName] != null) { string cookie = filterContext.HttpContext.Request.Cookies[UserCookieName].Value; byte[] cipherText = Convert.FromBase64String(cookie); var user = UserService.GetRegisteredUser(); if (user != null) { string name = cipherText.Decrypt(user.Salt, ConfigurationManager.AppSetting("keyphrase")); userViewModel.Name = name; userViewModel.Email = user.Email; // userViewModel.Name = user.Name; // userViewModel.IsLoggedIn = true; } } filterContext.HttpContext.User = Thread.CurrentPrincipal = new GenericPrincipal(userViewModel, null); } }
private void CreateIdentity(string name) { var identity = new UserViewModel { Name = name }; HttpContext.Current.User = new GenericPrincipal(identity, null); }
private UserViewModel UpdateCookies(User user) { var userViewModel = new UserViewModel { Email = user.Email, Name = user.Name, IsAuthenticated = true }; if (_filterContext.HttpContext.Request.Cookies[GetCookieUserFilterAttribute.UserCookieName] == null) { byte[] cipherText = user.Name.Encrypt(user.Salt, ConfigurationManager.AppSetting("keyphrase")); string base64CipherText = Convert.ToBase64String(cipherText); var cookie = new HttpCookie(GetCookieUserFilterAttribute.UserCookieName, base64CipherText) {Secure = RequireSsl}; _filterContext.HttpContext.Response.Cookies.Add(cookie); } return userViewModel; }