public void Test_UserCreate_ValueToModel() { var value = new UserCreate { CountryId = 1, TimeZoneId = 2, Name = "test", EmailAddress = "*****@*****.**", Password = "******", Dst = UserPreferenceDaylightSavingTime.On, StartOfWeek = UserPreferenceStartOfWeek.Monday, TimeFormat = UserPreferenceTimeFormat.Extended }; var user = new User(); value.ValueToModel(user); Assert.AreEqual("test", user.Name, "Name"); Assert.AreEqual("*****@*****.**", user.EmailAddress, "EmailAddress"); Assert.AreEqual("testing", user.Password, "Password"); Assert.AreEqual(UserPreferenceDaylightSavingTime.On, value.Preference.Dst, "Dst"); Assert.AreEqual(UserPreferenceStartOfWeek.Monday, value.Preference.StartOfWeek, "StartOfWeek"); Assert.AreEqual(UserPreferenceTimeFormat.Extended, value.Preference.TimeFormat, "TimeFormat"); }
public void Test_UserAdminCreate_ValueToModel() { var value = new UserAdminCreate { CountryId = 1, TimeZoneId = 2, Name = "test", Title = "test2", EmailAddress = "*****@*****.**", Password = "******", Signature = "test5", IsProtected = true, Status = UserStatus.Activated, Dst = UserPreferenceDaylightSavingTime.On, StartOfWeek = UserPreferenceStartOfWeek.Monday, TimeFormat = UserPreferenceTimeFormat.Extended }; var user = new User(); value.ValueToModel(user); Assert.AreEqual("test", user.Name, "Name"); Assert.AreEqual("test2", user.Title, "Title"); Assert.AreEqual("*****@*****.**", user.EmailAddress, "EmailAddress"); Assert.AreEqual("testing", user.Password, "Password"); Assert.AreEqual("test5", user.Signature, "Signature"); Assert.IsTrue(user.IsProtected, "IsProtected"); Assert.AreEqual(UserStatus.Activated, user.Status, "Status"); Assert.AreEqual(UserPreferenceDaylightSavingTime.On, value.Preference.Dst, "Dst"); Assert.AreEqual(UserPreferenceStartOfWeek.Monday, value.Preference.StartOfWeek, "StartOfWeek"); Assert.AreEqual(UserPreferenceTimeFormat.Extended, value.Preference.TimeFormat, "TimeFormat"); }
public void Test_UserAvatarServiceTest_Assign() { var user = new User(); this.UserAvatarService.AssignToUser(user, new UserAvatar { Id = 1, FileName = "test" }); Assert.AreEqual(1, user.Avatar.Id, "Id"); Assert.AreEqual("test", user.Avatar.FileName, "FileName"); }
public void Test_UserAuthenticationReset_Initialize() { var value = new UserAuthenticationReset(); var user = new User { Id = 1 }; value.Initialize(user); Assert.IsNotNull(user, "User"); Assert.AreEqual(1, value.Id, "Id"); }
/// <summary> /// Copies the specified user to the specified document. /// </summary> /// <param name="user">The user.</param> /// <param name="document">The document.</param> private static void UserToDocument(User user, Document document) { document.Add(new Field("id", user.Id.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); document.Add(new Field("name", user.Name, Field.Store.YES, Field.Index.TOKENIZED)); document.Add(new Field("email", user.EmailAddress, Field.Store.YES, Field.Index.TOKENIZED)); document.Add(new Field("reputation", user.Reputation.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); document.Add(new Field("status", user.Status.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); document.Add(new Field("created", user.Created.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.UN_TOKENIZED)); document.Add(new Field("last_visit", user.LastVisit.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.UN_TOKENIZED)); document.Add(new Field("last_logon", user.LastLogOn.ToString("yyyyMMddHHmm", CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.UN_TOKENIZED)); }
public void Test_UserExtension_AvatarImage_Null() { var user = new User { Name = "Test" }; var result = user.AvatarImage(null, this.Context); Assert.AreEqual("<img alt=\"Test\" src=\"/images/avatars/avatar.jpg\" />", result.ToString()); }
public void Test_FormsAuthenticationService_Authenticate() { var user = new User { Password = "******".HashToSha1("123").Hex(), Salt = "123" }; var result = this.AuthenticationService.Authenticate(user, "Test"); Assert.IsTrue(result, "Result"); }
public void Test_User_UpdateReputation() { var user = new User(); user.UpdateReputation(); Assert.AreEqual(1, user.Reputation, "Add"); user.UpdateReputation(1, false); Assert.AreEqual(0, user.Reputation, "Subtract"); }
public void Test_UserExtension_AvatarImage() { var user = new User { Name = "Test", Avatar = new UserAvatar { FileDiskName = "test.jpg", FilePath = "images/avatars" } }; var result = user.AvatarImage(null, this.Context); Assert.AreEqual("<img alt=\"Test\" src=\"/images/avatars/test.jpg\" />", result.ToString()); }
public void Test_FormsAuthenticationService_Reset() { var password = "******".HashToSha1("123").Hex(); var salt = "123"; var user = new User { Password = password, Salt = salt }; this.AuthenticationService.Reset(user); Assert.AreNotEqual(password, user.Password, "Password"); Assert.AreNotEqual(salt, user.Salt, "Salt"); Assert.AreEqual(4, user.Salt.Length, "Salt.Length"); }
public void Test_UserUpdate_ValueToModel() { var value = new UserUpdate { Name = "test", Title = "test2", EmailAddress = "*****@*****.**", Signature = "test3" }; var user = new User(); value.ValueToModel(user); Assert.AreEqual("test", user.Name, "Name"); Assert.AreEqual("test2", user.Title, "Title"); Assert.AreEqual("*****@*****.**", user.EmailAddress, "EmailAddress"); Assert.AreEqual("test3", user.Signature, "Signature"); }
/// <summary> /// Initializes the specified user. /// </summary> /// <param name="user">The user.</param> /// <param name="roles">The roles.</param> /// <param name="privileges">The privileges.</param> public void Initialize(User user, IEnumerable<UserRole> roles, IEnumerable<UserRoleRelation> privileges) { this.UserId = user.Id; this.User = user; this.Names = Enum.GetNames(typeof(Privileges)); this.Values = new List<UserRoleRelationUpdate>(); var dictionary = privileges.ToDictionary(x => x.Role.Title); var values = Enum.GetValues(typeof(Privileges)) as int[]; if (values == null) { return; } foreach (var role in roles) { var relation = new UserRoleRelationUpdate { RoleId = role.Id, Selected = dictionary.ContainsKey(role.Title), Role = role, Privileges = new List<UserRoleRelationUpdateValue>() }; foreach (var privilege in values) { relation.Privileges.Add( new UserRoleRelationUpdateValue { Privilege = privilege, Selected = dictionary.Has(role.Title, privilege) } ); } this.Values.Add(relation); } }
public void UpdatePrivileges(User user, IList<UserRoleRelationUpdate> values) { }
public void Test_FormsAuthenticationService_Update() { var salt = "123"; var user = new User { Password = "******", Salt = salt }; this.AuthenticationService.Update(user, "Other"); var password = "******".HashToSha1(user.Salt).Hex(); Assert.AreEqual(password, user.Password, "Password"); Assert.AreNotEqual(salt, user.Salt, "Salt"); Assert.AreEqual(4, user.Salt.Length, "Salt.Length"); }
public void Test_UserAvatarServiceTest_RemoveFromUserOnMatch() { var user = new User(); var avatar = new UserAvatar { Id = 1, FileName = "test" }; user.Avatar = avatar; var matched = this.UserAvatarService.RemoveFromUserOnMatch(user, avatar); Assert.IsTrue(matched, "Matched"); Assert.IsNull(user.Avatar, "Avatar"); }
public void Update(User entity) { }
public void Test_UserAdminUpdate_ValueToModel() { var value = new UserAdminUpdate { Name = "test", Title = "test2", EmailAddress = "*****@*****.**", Signature = "test3", IsProtected = true, Status = UserStatus.Activated }; var user = new User(); value.ValueToModel(user); Assert.AreEqual("test", user.Name, "Name"); Assert.AreEqual("test2", user.Title, "Title"); Assert.AreEqual("*****@*****.**", user.EmailAddress, "EmailAddress"); Assert.AreEqual("test3", user.Signature, "Signature"); Assert.IsTrue(user.IsProtected, "IsProtected"); Assert.AreEqual(UserStatus.Activated, user.Status, "Status"); }
public bool RemoveFromUserOnMatch(User user, UserAvatar avatar) { return true; }
/// <summary> /// Authenticates the specified user. /// </summary> /// <param name="user">The user.</param> /// <param name="password">The password.</param> /// <returns></returns> public bool Authenticate(User user, string password) { if (user == null) { throw new ArgumentNullException("user"); } if (user.Password.Equals(password.HashToSha1(user.Salt).Hex())) { return true; } #region Legacy Code for Compatibility Reasons if (user.Password.Equals(password.HashToMd5().Hex().HashToMd5(user.Salt).Hex())) { var salt = this.GeneratePassword(Setting.UserPasswordSaltLength.Value); user.Password = password.HashToSha1(salt).Hex(); user.Salt = salt; this.UserRepository.Update(user); return true; } #endregion return false; }
public void Insert(User entity) { entity.Preference = new UserPreference { Country = new Country(), TimeZone = new TimeZone() }; }
public void Reset(User user) { }
public void LogOn(User user) { }
public bool Authenticate(User user, string password) { return true; }
public void Delete(User entity) { }
public void AssignToUser(User user, UserAvatar avatar) { }
/// <summary> /// Logs the specified user on. /// </summary> /// <param name="user">The user.</param> public void LogOn(User user) { if (user == null) { throw new ArgumentNullException("user"); } var context = HttpContext.Current; if (context == null) { return; } user.LastLogOn = DateTime.Now; this.UserRepository.Update(user); // get auth cookie var auth = FormsAuthentication.GetAuthCookie(user.EmailAddress, true); // decrypt auth cookie value var current = FormsAuthentication.Decrypt(auth.Value); // create new auth ticket var ticket = new FormsAuthenticationTicket( current.Version, current.Name, current.IssueDate, current.Expiration, current.IsPersistent, string.Empty); // encrypt new auth ticket auth.Value = FormsAuthentication.Encrypt(ticket); // add auth cookie context.Response.Cookies.Add(auth); }
/// <summary> /// Resets the password for the specified user. /// </summary> /// <param name="user">The user.</param> public void Reset(User user) { if (user == null) { throw new ArgumentNullException("user"); } // reset password var password = this.GeneratePassword(); var salt = this.GeneratePassword(Setting.UserPasswordSaltLength.Value); user.Password = password.HashToSha1(salt).Hex(); user.Salt = salt; user.Updated = DateTime.Now; // update user this.UserRepository.Update(user); // send email to user this.EmailService.Send(new UserResetPasswordEmail { Recipient = user.EmailAddress, Name = user.Name, EmailAddress = user.EmailAddress, Password = password }); }
/// <summary> /// Updates the password for the specified user. /// </summary> /// <param name="user">The user.</param> /// <param name="password">The password.</param> public void Update(User user, string password) { if (user == null) { throw new ArgumentNullException("user"); } // update password var salt = this.GeneratePassword(Setting.UserPasswordSaltLength.Value); user.Password = password.HashToSha1(salt).Hex(); user.Salt = salt; user.Updated = DateTime.Now; // update user this.UserRepository.Update(user); }
public void Update(User user, string password) { }
public void Insert(User user, UserPreference preference) { user.Preference = new UserPreference { Country = new Country(), TimeZone = new TimeZone() }; }