public void UpdateUserSettings_InvalidEmailFormat() { var contract = new UpdateUserSettingsContract(userWithEmail) { Email = "mikumiku" }; data.UpdateUserSettings(contract); }
public void UpdateUserSettings_ChangeName_TooSoon() { userWithEmail.CreateDate = DateTime.Now - TimeSpan.FromDays(39); var contract = new UpdateUserSettingsContract(userWithEmail) { Name = "mikumiku" }; data.UpdateUserSettings(contract); }
public void UpdateUserSettings_ChangeName_AlreadyInUse() { userWithEmail.CreateDate = DateTime.Now - TimeSpan.FromDays(720); var contract = new UpdateUserSettingsContract(userWithEmail) { Name = userWithoutEmail.Name }; data.UpdateUserSettings(contract); }
public void UpdateUserSettings_EmailTaken() { permissionContext.LoggedUser = new UserWithPermissionsContract(userWithoutEmail, ContentLanguagePreference.Default); var contract = new UpdateUserSettingsContract(userWithoutEmail) { Email = userWithEmail.Email }; data.UpdateUserSettings(contract); }
public void UpdateUserSettings_Password_InvalidOldPassword() { var contract = new UpdateUserSettingsContract(userWithEmail) { OldPass = "******", NewPass = "******" }; data.UpdateUserSettings(contract); }
public void UpdateUserSettings_ChangeName() { userWithEmail.CreateDate = DateTime.Now - TimeSpan.FromDays(720); var contract = new UpdateUserSettingsContract(userWithEmail) { Name = "mikumiku" }; data.UpdateUserSettings(contract); Assert.AreEqual("mikumiku", userWithEmail.Name, "Name was changed"); Assert.AreEqual(1, userWithEmail.OldUsernames.Count, "Old username was added"); Assert.AreEqual("already_exists", userWithEmail.OldUsernames[0].OldName, "Old name was recorded"); }
public void UpdateUserSettings_Password() { var algo = new HMICSHA1PasswordHashAlgorithm(); var contract = new UpdateUserSettingsContract(userWithEmail) { OldPass = "******", NewPass = "******" }; data.UpdateUserSettings(contract); Assert.AreEqual(algo.HashPassword("3939", userWithEmail.Salt), userWithEmail.Password, "Password was updated"); }
public void UpdateUserSettings_EmailTakenButDisabled() { userWithEmail.Active = false; permissionContext.LoggedUser = new UserWithPermissionsContract(userWithoutEmail, ContentLanguagePreference.Default); var contract = new UpdateUserSettingsContract(userWithoutEmail) { Email = userWithEmail.Email }; data.UpdateUserSettings(contract); var user = GetUserFromRepo(userWithoutEmail.Name); Assert.IsNotNull(user, "User was found in repository"); Assert.AreEqual("*****@*****.**", user.Email, "Email"); }
public UserContract UpdateUserSettings(UpdateUserSettingsContract contract) { ParamIs.NotNull(() => contract); PermissionContext.VerifyPermission(PermissionToken.EditProfile); return(HandleTransaction(session => { var user = session.Load <User>(contract.Id); SysLog(string.Format("Updating settings for {0}", user)); VerifyResourceAccess(user); if (!string.IsNullOrEmpty(contract.NewPass)) { var oldHashed = (!string.IsNullOrEmpty(user.Password) ? LoginManager.GetHashedPass(user.NameLC, contract.OldPass, user.Salt) : string.Empty); if (user.Password != oldHashed) { throw new InvalidPasswordException(); } var newHashed = LoginManager.GetHashedPass(user.NameLC, contract.NewPass, user.Salt); user.Password = newHashed; } user.Options.AboutMe = contract.AboutMe; user.AnonymousActivity = contract.AnonymousActivity; user.Culture = contract.Culture; user.DefaultLanguageSelection = contract.DefaultLanguageSelection; user.EmailOptions = contract.EmailOptions; user.Language = contract.Language; user.Options.Location = contract.Location; user.PreferredVideoService = contract.PreferredVideoService; user.Options.PublicRatings = contract.PublicRatings; user.SetEmail(contract.Email); var webLinkDiff = WebLink.Sync(user.WebLinks, contract.WebLinks, user); SessionHelper.Sync(session, webLinkDiff); session.Update(user); AuditLog(string.Format("updated settings for {0}", EntryLinkFactory.CreateEntryLink(user)), session); return new UserContract(user); })); }
public void UpdateUserSettings_SetEmail() { var contract = new UpdateUserSettingsContract(userWithEmail) { Email = "*****@*****.**" }; userWithEmail.Options.EmailVerified = true; var result = data.UpdateUserSettings(contract); Assert.IsNotNull(result, "Result"); var user = GetUserFromRepo(userWithEmail.Name); Assert.IsNotNull(user, "User was found in repository"); Assert.AreEqual("*****@*****.**", user.Email, "Email"); Assert.IsFalse(user.Options.EmailVerified, "EmailVerified"); // Cancel verification }
/// <summary> /// Updates user's settings (from my settings page). /// </summary> /// <param name="contract">New properties. Cannot be null.</param> /// <returns>Updated user data. Cannot be null.</returns> /// <exception cref="InvalidEmailFormatException">If the email format was invalid.</exception> /// <exception cref="InvalidPasswordException">If password change was attempted and the old password was incorrect.</exception> /// <exception cref="UserEmailAlreadyExistsException">If the email address was already taken by another user.</exception> public UserWithPermissionsContract UpdateUserSettings(UpdateUserSettingsContract contract) { ParamIs.NotNull(() => contract); PermissionContext.VerifyPermission(PermissionToken.EditProfile); return(repository.HandleTransaction(ctx => { var user = ctx.Load(contract.Id); ctx.AuditLogger.SysLog(string.Format("Updating settings for {0}", user)); PermissionContext.VerifyResourceAccess(user); if (!string.IsNullOrEmpty(contract.NewPass)) { var oldHashed = (!string.IsNullOrEmpty(user.Password) ? LoginManager.GetHashedPass(user.NameLC, contract.OldPass, user.Salt) : string.Empty); if (user.Password != oldHashed) { throw new InvalidPasswordException(); } var newHashed = LoginManager.GetHashedPass(user.NameLC, contract.NewPass, user.Salt); user.Password = newHashed; } var email = contract.Email; if (!string.IsNullOrEmpty(email)) { ValidateEmail(email); var existing = ctx.Query().FirstOrDefault(u => u.Active && u.Id != user.Id && u.Email == email); if (existing != null) { throw new UserEmailAlreadyExistsException(); } } user.Options.AboutMe = contract.AboutMe; user.AnonymousActivity = contract.AnonymousActivity; user.Culture = contract.Culture; user.DefaultLanguageSelection = contract.DefaultLanguageSelection; user.EmailOptions = contract.EmailOptions; user.Language = contract.Language; user.Options.Location = contract.Location; user.PreferredVideoService = contract.PreferredVideoService; user.Options.PublicAlbumCollection = contract.PublicAlbumCollection; user.Options.PublicRatings = contract.PublicRatings; user.SetEmail(email); var validWebLinks = contract.WebLinks.Where(w => !string.IsNullOrEmpty(w.Url)); var webLinkDiff = WebLink.Sync(user.WebLinks, validWebLinks, user); ctx.OfType <UserWebLink>().Sync(webLinkDiff); ctx.Update(user); ctx.AuditLogger.AuditLog(string.Format("updated settings for {0}", EntryLinkFactory.CreateEntryLink(user))); return new UserWithPermissionsContract(user, PermissionContext.LanguagePreference); })); }