mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: login & registration; enhanced paste view; custom dropdown + search; navbar; global user access via store; auto token refresh; paste creation as user; /api/user/me, returns info on yourself including pastes;
fix: auth check refactor: remove user UID api endpoint
This commit is contained in:
@@ -22,6 +22,16 @@ namespace SharpbinV3.Server.Controllers
|
||||
var existingUser = await _userService.GetByUsername(request.Username);
|
||||
if (existingUser != null)
|
||||
return Conflict(new { message = "Username already exists." });
|
||||
if (!string.IsNullOrEmpty(request.Email))
|
||||
{
|
||||
var existingEmailUser = await _userService.GetByEmail(request.Email);
|
||||
if (existingEmailUser != null)
|
||||
return Conflict(new { message = "Email already in use." });
|
||||
if (!IsValidEmail(request.Email))
|
||||
return BadRequest(new { message = "Invalid email." });
|
||||
}
|
||||
if (!IsValidPassword(request.Password))
|
||||
return BadRequest(new { message = "Password should have at least 8 characters, including uppercase, lowercase, and digits." });
|
||||
|
||||
var user = await _authService.CreateUser(request.Username, request.Password, request.Email, request.DisplayName);
|
||||
return Ok(new
|
||||
@@ -75,5 +85,31 @@ namespace SharpbinV3.Server.Controllers
|
||||
return BadRequest(new { message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static bool IsValidPassword(string password)
|
||||
{
|
||||
if (password.Length < 6)
|
||||
return false;
|
||||
if (!password.Any(char.IsUpper))
|
||||
return false;
|
||||
if (!password.Any(char.IsLower))
|
||||
return false;
|
||||
if (!password.Any(char.IsDigit))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
private static bool IsValidEmail(string email)
|
||||
{
|
||||
try
|
||||
{
|
||||
var addr = new System.Net.Mail.MailAddress(email);
|
||||
return addr.Address == email;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user