Moved implementation of check for existance of username on creating user from user service to repository.
This commit is contained in:
@@ -20,8 +20,24 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// </summary>
|
||||
/// <param name="username"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("This method will be removed in future versions. Please use ExistsByUserName instead.")]
|
||||
bool Exists(string username);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a user with the username exists
|
||||
/// </summary>
|
||||
/// <param name="username"></param>
|
||||
/// <returns></returns>
|
||||
bool ExistsByUserName(string username);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a user with the login exists
|
||||
/// </summary>
|
||||
/// <param name="username"></param>
|
||||
/// <returns></returns>
|
||||
bool ExistsByLogin(string login);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IUser"/> objects associated with a given group
|
||||
/// </summary>
|
||||
|
||||
@@ -626,6 +626,11 @@ ORDER BY colName";
|
||||
}
|
||||
|
||||
public bool Exists(string username)
|
||||
{
|
||||
return ExistsByUserName(username);
|
||||
}
|
||||
|
||||
public bool ExistsByUserName(string username)
|
||||
{
|
||||
var sql = SqlContext.Sql()
|
||||
.SelectCount()
|
||||
@@ -635,6 +640,16 @@ ORDER BY colName";
|
||||
return Database.ExecuteScalar<int>(sql) > 0;
|
||||
}
|
||||
|
||||
public bool ExistsByLogin(string login)
|
||||
{
|
||||
var sql = SqlContext.Sql()
|
||||
.SelectCount()
|
||||
.From<UserDto>()
|
||||
.Where<UserDto>(x => x.Login == login);
|
||||
|
||||
return Database.ExecuteScalar<int>(sql) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IUser"/> objects associated with a given group
|
||||
/// </summary>
|
||||
|
||||
@@ -109,9 +109,9 @@ namespace Umbraco.Core.Services.Implement
|
||||
User user;
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var loginExists = scope.Database.ExecuteScalar<int>("SELECT COUNT(id) FROM umbracoUser WHERE userLogin = @Login", new { Login = username }) != 0;
|
||||
var loginExists = _userRepository.ExistsByLogin(username);
|
||||
if (loginExists)
|
||||
throw new ArgumentException("Login already exists"); // causes rollback // causes rollback
|
||||
throw new ArgumentException("Login already exists"); // causes rollback
|
||||
|
||||
user = new User(_globalSettings)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user