Implemented GetUsersInRoleAsync and reintroduced email check

This commit is contained in:
Bjarke Berg
2020-05-05 11:33:19 +02:00
parent c58f480d24
commit e8fc2a766b
2 changed files with 28 additions and 12 deletions

View File

@@ -56,6 +56,11 @@ namespace Umbraco.Web.Install.InstallSteps
{
throw new InvalidOperationException("Could not find the super user!");
}
admin.Email = user.Email.Trim();
admin.Name = user.Name.Trim();
admin.Username = user.Email.Trim();
_userService.Save(admin);
var userManager = _httpContextAccessor.GetRequiredHttpContext().GetOwinContext().GetBackOfficeUserManager();
var membershipUser = await userManager.FindByIdAsync(Constants.Security.SuperUserId.ToString());
@@ -74,11 +79,7 @@ namespace Umbraco.Web.Install.InstallSteps
if (!resetResult.Succeeded)
throw new InvalidOperationException("Could not reset password: " + string.Join(", ", resetResult.Errors.ToErrorMessage()));
admin.Email = user.Email.Trim();
admin.Name = user.Name.Trim();
admin.Username = user.Email.Trim();
_userService.Save(admin);
if (user.SubscribeToNewsLetter)
{

View File

@@ -66,7 +66,7 @@ namespace Umbraco.Web.Security
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
if (user == null) throw new ArgumentNullException(nameof(user));
return Task.FromResult(user.Id.ToString());
}
@@ -152,7 +152,7 @@ namespace Umbraco.Web.Security
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
if (user == null) throw new ArgumentNullException(nameof(user));
var found = _userService.GetUserById(user.Id);
if (found != null)
{
@@ -184,7 +184,7 @@ namespace Umbraco.Web.Security
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
if (user == null) throw new ArgumentNullException(nameof(user));
var found = _userService.GetUserById(user.Id);
if (found != null)
{
@@ -293,7 +293,7 @@ namespace Umbraco.Web.Security
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
if (user == null) throw new ArgumentNullException(nameof(user));
// if (email.IsNullOrWhiteSpace()) throw new ArgumentNullException("email");
if (email.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(email));
user.Email = email;
@@ -540,9 +540,24 @@ namespace Umbraco.Web.Security
return Task.FromResult(user.Roles.Select(x => x.RoleId).InvariantContains(normalizedRoleName));
}
public Task<IList<BackOfficeIdentityUser>> GetUsersInRoleAsync(string normalizedRoleName, CancellationToken cancellationToken)
/// <summary>
/// Lists all users of a given role.
/// </summary>
/// <remarks>
/// Identity Role names are equal to Umbraco UserGroup alias.
/// </remarks>
public Task<IList<BackOfficeIdentityUser>> GetUsersInRoleAsync(string normalizedRoleName, CancellationToken cancellationToken = default(CancellationToken))
{
throw new NotImplementedException();
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
if (normalizedRoleName == null) throw new ArgumentNullException(nameof(normalizedRoleName));
var userGroup = _userService.GetUserGroupByAlias(normalizedRoleName);
var users = _userService.GetAllInGroup(userGroup.Id);
IList<BackOfficeIdentityUser> backOfficeIdentityUsers = users.Select(x => _mapper.Map<BackOfficeIdentityUser>(x)).ToList();
return Task.FromResult(backOfficeIdentityUsers);
}
/// <summary>
@@ -875,7 +890,7 @@ namespace Umbraco.Web.Security
return anythingChanged;
}
private void ThrowIfDisposed()
{
if (_disposed) throw new ObjectDisposedException(GetType().Name);
@@ -891,7 +906,7 @@ namespace Umbraco.Web.Security
return Task.FromResult(false);
}
private static int UserIdToInt(string userId)
{
var attempt = userId.TryConvertTo<int>();