Ejemplo n.º 1
0
        public static User GetAuthenticated(bool IncludeNavigationProperties = false)
        {
            var db = new ProjectDbContext();

            var userCookie  = HttpContext.Current.Request.Cookies["LoggedUser"];
            var userSession = (UserToLoginViewModel)HttpContext.Current.Session["LoggedUser"];
            var user        = new User();
            UserToLoginViewModel userToLogin = null;

            if (userSession != null)
            {
                userToLogin = userSession;
            }
            else if (userCookie != null)
            {
                userToLogin = JsonConvert.DeserializeObject <UserToLoginViewModel>(userCookie.Value);
            }

            Mapper.Map(userToLogin, user);
            var authUser = user.Authenticate(true) == ActionStatus.Success
                ? userToLogin
                : null;

            return(authUser == null
                ? null
                : (IncludeNavigationProperties
                    ? db.Users.Include(u => u.Avatar).Include(u => u.ActivationRequests).Include(u => u.RemindPasswordRequests).Include(u => u.AddedToFriends).Single(u => u.Id == authUser.Id)
                    : db.Users.Single(u => u.Id == authUser.Id)));
        }
Ejemplo n.º 2
0
        public static UserToLoginViewModel GetAuthenticated()
        {
            var userCookie  = HttpContext.Current.Request.Cookies["LoggedUser"];
            var userSession = (UserToLoginViewModel)HttpContext.Current.Session["LoggedUser"];
            var user        = new User();
            UserToLoginViewModel userToLogin = null;

            if (userSession != null)
            {
                userToLogin = userSession;
            }
            else if (userCookie != null)
            {
                userToLogin = JsonConvert.DeserializeObject <UserToLoginViewModel>(userCookie.Value);
            }

            Mapper.Map(userToLogin, user);
            return(user.Authenticate(true) == ActionStatus.Success
                ? userToLogin
                : null);
        }