mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
fix: handle username conflict during user creation
This commit is contained in:
@@ -61,7 +61,19 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
if (!string.IsNullOrEmpty(request.DisplayName) && request.DisplayName.Length > 26)
|
if (!string.IsNullOrEmpty(request.DisplayName) && request.DisplayName.Length > 26)
|
||||||
return BadRequest(new { success = false, message = "Display name should not exceed 26 characters." });
|
return BadRequest(new { success = false, message = "Display name should not exceed 26 characters." });
|
||||||
|
|
||||||
var user = await _authService.CreateUser(request.Username, request.Password, request.Email, request.DisplayName);
|
User user;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
user = await _authService.CreateUser(request.Username, request.Password, request.Email, request.DisplayName);
|
||||||
|
}
|
||||||
|
catch (DbUpdateException)
|
||||||
|
{
|
||||||
|
if (await _userService.GetByUsername(request.Username) != null)
|
||||||
|
return Conflict(new { success = false, message = "Username already exists." });
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(user.Email))
|
if (!string.IsNullOrWhiteSpace(user.Email))
|
||||||
await _authService.SendEmailVerification(user);
|
await _authService.SendEmailVerification(user);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user