Example #1
0
 public Task<UserViewModel> GetUser()
 {
     return Task.Factory.StartNew(() =>
             {
                 try
                 {
                     IsAuthenticated();
                     var user = _userService.GetUser();
                     var model = new UserViewModel {Name = user.Name, IsAuthenticated = true};
                     return model;
                 }
                 catch (NotLoggedInException)
                 {
                     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);
            }
        }
Example #3
0
 public void GivenAUserViewModel_ItIsNotInANyRole()
 {
     var model = new UserViewModel();
     model.IsInRole(It.IsAny<string>()).Should().BeFalse();
 }