mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: password resets
fix: frontend docker file chore: format via csharpier again
This commit is contained in:
@@ -35,20 +35,33 @@ namespace SharpbinV3.Server.Services
|
||||
|
||||
public Task<User?> GetByEmail(string email, bool withPastes = false)
|
||||
{
|
||||
var normalizedEmail = NormalizeEmail(email);
|
||||
if (normalizedEmail == null)
|
||||
return Task.FromResult<User?>(null);
|
||||
|
||||
IQueryable<User> query = _db.Users;
|
||||
if (withPastes)
|
||||
query = query.Include(u => u.Pastes);
|
||||
return query.FirstOrDefaultAsync(u => u.Email == email);
|
||||
return query.FirstOrDefaultAsync(u => u.Email == normalizedEmail);
|
||||
}
|
||||
|
||||
public async Task<User> Update(User user)
|
||||
{
|
||||
user.Username = NormalizeUsername(user.Username);
|
||||
user.Email = NormalizeEmail(user.Email);
|
||||
_db.Users.Update(user);
|
||||
await _db.SaveChangesAsync();
|
||||
return user;
|
||||
}
|
||||
|
||||
public static string NormalizeUsername(string username) => username.ToLowerInvariant();
|
||||
|
||||
public static string? NormalizeEmail(string? email)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(email))
|
||||
return null;
|
||||
|
||||
return email.Trim().ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user