public void Write(string identifier, UserCredential credential) { if (!_storage.ContainsKey(identifier)) { _storage.Add(identifier, credential); } else { _storage[identifier] = credential; } }
public void Write(string identifier, UserCredential credential) { if (!SessionContainsKey(identifier)) { Session.Add(identifier, credential); } else { Session[identifier] = credential; } }
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) }); } }
/// <summary> /// Стартовать сессию. /// </summary> public virtual void SessionStartup() { if (!IsRemember()) { UserCredential = DefaultUserCredential; } else { RestoreRememberSession(); } Logger.Info(String.Format("Сессия для пользователя {0} запущена.", UserCredential.Login)); }
/// <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; }
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()); }