private async Task UpdateEmailAsync(
            UpdateCurrentUserAccountCommand command,
            int userId,
            User user,
            IExecutionContext executionContext
            )
        {
            var userArea = _userAreaRepository.GetByCode(user.UserAreaCode);
            var newEmail = command.Email?.Trim();

            if (userArea.UseEmailAsUsername && user.Username != newEmail)
            {
                var uniqueQuery = new IsUsernameUniqueQuery()
                {
                    Username     = newEmail,
                    UserId       = userId,
                    UserAreaCode = CofoundryAdminUserArea.AreaCode
                };

                if (!await _queryExecutor.ExecuteAsync(uniqueQuery, executionContext))
                {
                    throw new PropertyValidationException("This email is already registered", "Email");
                }

                user.Username = newEmail;
            }

            user.Email = newEmail;
        }
コード例 #2
0
        private async Task ValidateIsUniqueAsync(
            UpdateUserCommand command,
            IUserAreaDefinition userArea,
            IExecutionContext executionContext
            )
        {
            var query = new IsUsernameUniqueQuery()
            {
                UserId       = command.UserId,
                UserAreaCode = userArea.UserAreaCode
            };

            if (userArea.UseEmailAsUsername)
            {
                query.Username = command.Email?.Trim();
            }
            else
            {
                query.Username = command.Username.Trim();
            }

            var isUnique = await _queryExecutor.ExecuteAsync(query, executionContext);

            if (!isUnique)
            {
                if (userArea.UseEmailAsUsername)
                {
                    throw ValidationErrorException.CreateWithProperties("This email is already registered", "Email");
                }
                else
                {
                    throw ValidationErrorException.CreateWithProperties("This username is already registered", "Username");
                }
            }
        }
コード例 #3
0
        private async Task ValidateIsUnique(UpdateUserCommand command, IUserAreaDefinition userArea)
        {
            var query = new IsUsernameUniqueQuery()
            {
                UserId       = command.UserId,
                UserAreaCode = userArea.UserAreaCode
            };

            if (userArea.UseEmailAsUsername)
            {
                query.Username = command.Email;
            }
            else
            {
                query.Username = command.Username.Trim();
            }

            var isUnique = await _queryExecutor.ExecuteAsync(query);

            if (!isUnique)
            {
                if (userArea.UseEmailAsUsername)
                {
                    throw new PropertyValidationException("This email is already registered", "Email");
                }
                else
                {
                    throw new PropertyValidationException("This username is already registered", "Username");
                }
            }
        }
コード例 #4
0
        private IsUsernameUniqueQuery GetUniqueQuery(AddUserCommand command, IUserAreaDefinition userArea)
        {
            var query = new IsUsernameUniqueQuery();

            if (userArea.UseEmailAsUsername)
            {
                query.Username = command.Email;
            }
            else
            {
                query.Username = command.Username.Trim();
            }
            query.UserAreaCode = command.UserAreaCode;

            return(query);
        }
コード例 #5
0
 public Task <bool> IsUsernameUniqueAsync(IsUsernameUniqueQuery query)
 {
     return(ExtendableContentRepository.ExecuteQueryAsync(query));
 }
コード例 #6
0
 /// <summary>
 /// Determines if a username is unique within a specific UserArea.
 /// Usernames only have to be unique per UserArea.
 /// </summary>
 /// <param name="query">The parameters run the query with.</param>
 /// <param name="executionContext">Optional execution context to use when executing the query. Useful if you need to temporarily elevate your permission level.</param>
 /// <returns>True if the username is unique; otherwise false.</returns>
 public Task <bool> IsUsernameUniqueAsync(IsUsernameUniqueQuery query, IExecutionContext executionContext = null)
 {
     return(_queryExecutor.ExecuteAsync(query, executionContext));
 }
コード例 #7
0
 /// <summary>
 /// Determines if a username is unique within a specific UserArea.
 /// Usernames only have to be unique per UserArea.
 /// </summary>
 /// <param name="query">The parameters run the query with.</param>
 /// <param name="executionContext">Optional execution context to use when executing the query. Useful if you need to temporarily elevate your permission level.</param>
 /// <returns>True if the username is unique; otherwise false.</returns>
 public bool IsUsernameUnique(IsUsernameUniqueQuery query, IExecutionContext executionContext = null)
 {
     return(_queryExecutor.Execute(query, executionContext));
 }
コード例 #8
0
 public IContentRepositoryQueryContext <bool> IsUsernameUnique(IsUsernameUniqueQuery query)
 {
     return(ContentRepositoryQueryContextFactory.Create(query, ExtendableContentRepository));
 }