mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-31 00:50:45 +01:00
Better make sure users with no password can be created
This commit is contained in:
@@ -618,5 +618,11 @@ namespace Tgstation.Server.Api.Models
|
||||
/// </summary>
|
||||
[Description("The " + Routes.UserGroup + " endpoint cannot edit group members. Please update each member user individually.")]
|
||||
UserGroupControllerCantEditMembers,
|
||||
|
||||
/// <summary>
|
||||
/// Tried to remove the last <see cref="OAuthConnection"/> for a passwordless <see cref="User"/>.
|
||||
/// </summary>
|
||||
[Description("This user is passwordless and removing their oAuthConnections would leave them with no authentication method!")]
|
||||
CannotRemoveLastAuthenticationOption,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
if (model.OAuthConnections?.Any(x => x == null) == true)
|
||||
return BadRequest(new ErrorMessage(ErrorCode.ModelValidationFailure));
|
||||
|
||||
if (!(model.Password == null ^ model.SystemIdentifier == null))
|
||||
if ((model.Password != null && model.SystemIdentifier != null)
|
||||
|| (model.Password == null && model.SystemIdentifier == null && model.OAuthConnections?.Any() != true))
|
||||
return BadRequest(new ErrorMessage(ErrorCode.UserMismatchPasswordSid));
|
||||
|
||||
if (model.Group != null && model.PermissionSet != null)
|
||||
@@ -155,7 +156,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
{
|
||||
return RequiresPosixSystemIdentity();
|
||||
}
|
||||
else if (!(model.Password?.Length == 0 && model.OAuthConnections.Count != 0))
|
||||
else if (!(model.Password?.Length == 0 && model.OAuthConnections?.Any() == true))
|
||||
{
|
||||
var result = TrySetPassword(dbUser, model.Password, true);
|
||||
if (result != null)
|
||||
@@ -261,6 +262,9 @@ namespace Tgstation.Server.Host.Controllers
|
||||
if (originalUser.CanonicalName == Models.User.CanonicalizeName(Api.Models.User.AdminName))
|
||||
return BadRequest(new ErrorMessage(ErrorCode.AdminUserCannotOAuth));
|
||||
|
||||
if (model.OAuthConnections.Count == 0 && originalUser.PasswordHash == null && originalUser.SystemIdentifier == null)
|
||||
return BadRequest(new ErrorMessage(ErrorCode.CannotRemoveLastAuthenticationOption));
|
||||
|
||||
originalUser.OAuthConnections.Clear();
|
||||
foreach (var updatedConnection in model.OAuthConnections)
|
||||
originalUser.OAuthConnections.Add(new Models.OAuthConnection
|
||||
|
||||
Reference in New Issue
Block a user