public void Write(string identifier, UserCredential credential)
 {
     if (!_storage.ContainsKey(identifier))
     {
         _storage.Add(identifier, credential);
     }
     else
     {
         _storage[identifier] = credential;
     }
 }
예제 #2
0
 public void Write(string identifier, UserCredential credential)
 {
     if (!SessionContainsKey(identifier))
     {
         Session.Add(identifier, credential);
     }
     else
     {
         Session[identifier] = credential;
     }
 }
예제 #3
0
 public void Write(string identifier, UserCredential credential)
 {
     HttpCookie http_cookie = Request.Cookies[identifier];
     if (http_cookie != null && !http_cookie.Equals(null))
     {
         Response.Cookies.Add(new HttpCookie(identifier, Encrypt(Serialize(credential), credential.Login))
                                  {
                                      Expires = DateTime.Now.AddDays(14)
                                  });
     }
     else
     {
         Response.Cookies.Set(new HttpCookie(identifier, Encrypt(Serialize(credential), credential.Login))
                                  {
                                      Expires = DateTime.Now.AddDays(14)
                                  });
     }
 }
예제 #4
0
 /// <summary>
 /// Стартовать сессию.
 /// </summary>
 public virtual void SessionStartup()
 {
     if (!IsRemember())
     {
         UserCredential = DefaultUserCredential;
     }
     else
     {
         RestoreRememberSession();
     }
     Logger.Info(String.Format("Сессия для пользователя {0} запущена.", UserCredential.Login));
 }
예제 #5
0
        /// <summary>
        /// Вход пользователя.
        /// </summary>
        /// <param name="login">Логин.</param>
        /// <param name="password">Пароль.</param>
        /// <param name="rememberMe">Запоминить?</param>
        /// <returns>Результат авторизации.</returns>
        public virtual bool Login(string login, string password, bool rememberMe = false)
        {
            Logger.Info(String.Format("Попытка авторизации пользователя: Логин - {0}, Пароль - {1}, Запоминать? - {2}.",
                                      login, password, rememberMe));

            User user = Get<IUserRepository>().GetByLoginAndPassword(login, password);

            if (user != null)
            {
                var credential = new UserCredential
                                     {
                                         Login = user.Login,
                                         Role = user.Role.Name,
                                         IsAuthorization = true,
                                         IsRemember = rememberMe,
                                         IsQuickUser = false
                                     };
                ActualDataAccessor.Write(DefaultUserCredentialName, credential);
                if (rememberMe)
                {
                    RememberMe();
                }
            }

            Logger.Info(String.Format("Результат авторизации пользователя {0} - {1} .", login,
                                      UserCredential.IsAuthorization));
            return user != null;
        }
예제 #6
0
 protected string Serialize(UserCredential credential)
 {
     var memory_stream = new MemoryStream();
     var xml_serializer = new XmlSerializer(credential.GetType());
     xml_serializer.Serialize(memory_stream, credential);
     return Encoding.UTF8.GetString(memory_stream.ToArray());
 }