public void AssertNotReserved(ValidUsername username) { username.AssertNotNull("username"); if (this.IsReserved(username)) { throw new RecoverableException("The username '" + username.Value + "' is already taken."); } }
public bool IsReserved(ValidUsername username) { username.AssertNotNull("username"); return(this.reservedUsernames.Contains(username.Value)); }
public async Task <UpdateAccountSettingsResult> ExecuteAsync( UserId userId, ValidUsername newUsername, ValidEmail newEmail, ValidPassword newPassword, FileId newProfileImageFileId, string newSecurityStamp) { userId.AssertNotNull("userId"); newUsername.AssertNotNull("newUsername"); newEmail.AssertNotNull("newEmail"); string passwordHash = null; if (newPassword != null) { passwordHash = this.userManager.PasswordHasher.HashPassword(newPassword.Value); } var query = new StringBuilder(); query.AppendLine(@"DECLARE @emailConfirmed bit"); query.Append(@" UPDATE dbo.AspNetUsers SET Email = @Email, UserName = @Username, ProfileImageFileId = @ProfileImageFileId, SecurityStamp = @SecurityStamp, @emailConfirmed = ( CASE WHEN ((EmailConfirmed = 0) OR (Email != @Email)) THEN 0 ELSE 1 END ), EmailConfirmed = @emailConfirmed"); if (passwordHash != null) { query.Append(@", PasswordHash=@PasswordHash"); } query.AppendLine().Append(@"WHERE Id=@UserId").AppendLine(); query.Append(@"select @emailConfirmed"); bool emailConfirmed; using (var transaction = TransactionScopeBuilder.CreateAsync()) { using (var connection = this.connectionFactory.CreateConnection()) { emailConfirmed = await connection.ExecuteScalarAsync <bool>( query.ToString(), new { UserId = userId.Value, Username = newUsername.Value, Email = newEmail.Value, PasswordHash = passwordHash, SecurityStamp = newSecurityStamp, ProfileImageFileId = newProfileImageFileId == null ? (Guid?)null : newProfileImageFileId.Value }); } await this.requestSnapshot.ExecuteAsync(userId, SnapshotType.Subscriber); transaction.Complete(); } return(new UpdateAccountSettingsResult(emailConfirmed)); }