コード例 #1
0
 public void IssueAuthCookie(UserState userState)
 {
     var ticket = new FormsAuthenticationTicket(1, userState.UserId.ToString(CultureInfo.InvariantCulture), DateTime.Now, DateTime.Now.AddDays(100), true, userState.ToString());
     SetTicket(ticket);
     var identity = new MvcIdentity(userState.UserId);
     var principal = new MvcPrincipal(identity, userState);
     m_ContextProvider.User = principal;
 }
コード例 #2
0
        private static UserState ParseUserState(string contents)
        {
            var idents = contents.Split(new[]
                                        {
                                            '|'
                                        }, StringSplitOptions.RemoveEmptyEntries);

            DateTime dt;
            if (!DateTime.TryParse(idents[4], out dt))
                dt = DateTime.Now.AddDays(-1);

            bool isAdmin;
            bool isModerator;

            if (!bool.TryParse(idents[2], out isModerator))
                isModerator = false;

            if (!bool.TryParse(idents[3], out isAdmin))
                isAdmin = false;

            var p = new UserState
                    {
                        Email = idents[0],
                        UserId = int.Parse(idents[1]),
                        IsModerator = isModerator,
                        IsAdmin = isAdmin,
                        LastCheck = dt
                    };

            return p;
        }
コード例 #3
0
 private UserState RefreshUserState(UserState userState)
 {
     if (DateTime.Now.Subtract(userState.LastCheck).Minutes < 5)
         return userState;
     var user = m_UserManager.GetUser(userState.UserId);
     return CreateUserState(user);
 }
コード例 #4
0
 public MvcPrincipal(IIdentity identity, UserState userState)
     : base(identity, userState.Roles)
 {
     UserState = userState;
     UserId = userState.UserId;
 }