Esempio n. 1
0
        UserSessionStorage CreateStorage()
        {
            if (user.IsGuest)
            {
                var storage = new UserSessionStorage();

                return(storage);
            }
            var data = UsersAccessor.Get(user.UserId);

            if (data != null)
            {
                try
                {
                    var storage = new UserSessionStorage();
                    storage.SessionId      = data.UserId;
                    storage.Username       = data.Username;
                    storage.Mobile         = data.Mobile;
                    storage.Email          = data.Email;
                    storage.Title          = data.Title;
                    storage.Name           = data.Name;
                    storage.Password       = data.Password;
                    storage.PermissionCode = data.PermissionCode;
                    return(storage);
                }
                catch
                {
                    user.Logout();
                }
            }
            user.Logout();
            return(new UserSessionStorage());
        }
Esempio n. 2
0
 internal void Refresh()
 {
     if (context.Session.Get(Keys.UserSession) != null)
     {
         context.Session.Remove(Keys.UserSession);
     }
     storage = null;
 }
Esempio n. 3
0
 void EnsureStorage()
 {
     if (storage == null)
     {
         if (user.IsGuest)
         {
             storage = CreateStorage();
         }
         else
         {
             var data = context.Session.GetString(Keys.UserSession);
             if (!string.IsNullOrEmpty(data))
             {
                 storage = JsonConvert.DeserializeObject <UserSessionStorage>(data);
             }
             if (storage == null || string.IsNullOrEmpty(storage.Username))
             {
                 storage = CreateStorage();
                 data    = JsonConvert.SerializeObject(storage);
                 context.Session.SetString(Keys.UserSession, data);
             }
         }
     }
 }