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:
@@ -35,7 +35,7 @@ namespace SharpbinV3.Server.Services
|
||||
public async Task<JWTResult> GenerateJWTToken(User user)
|
||||
{
|
||||
var jwtHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes(_jwtSettings.SecretKey);
|
||||
var key = Encoding.ASCII.GetBytes(_jwtSettings.Secret);
|
||||
|
||||
var descriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
@@ -93,7 +93,7 @@ namespace SharpbinV3.Server.Services
|
||||
public async Task<bool> ValidateJWTToken(string token)
|
||||
{
|
||||
var jwtHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes(_jwtSettings.SecretKey);
|
||||
var key = Encoding.ASCII.GetBytes(_jwtSettings.Secret);
|
||||
try
|
||||
{
|
||||
jwtHandler.ValidateToken(token, new TokenValidationParameters
|
||||
@@ -115,7 +115,7 @@ namespace SharpbinV3.Server.Services
|
||||
public async Task<JWTResult> RefreshJWTToken(string token, string refreshToken)
|
||||
{
|
||||
var jwtHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes(_jwtSettings.SecretKey);
|
||||
var key = Encoding.ASCII.GetBytes(_jwtSettings.Secret);
|
||||
try
|
||||
{
|
||||
var principal = jwtHandler.ValidateToken(token, new TokenValidationParameters
|
||||
@@ -162,7 +162,7 @@ namespace SharpbinV3.Server.Services
|
||||
existingUser.DisplayName = user.DisplayName;
|
||||
existingUser.Roles = user.Roles;
|
||||
existingUser.LastLogin = user.LastLogin;
|
||||
existingUser.Visiblity = user.Visiblity;
|
||||
existingUser.Visibility = user.Visibility;
|
||||
_db.Users.Update(existingUser);
|
||||
await _db.SaveChangesAsync();
|
||||
return user;
|
||||
|
||||
@@ -4,9 +4,9 @@ namespace SharpbinV3.Server.Services
|
||||
{
|
||||
public interface IUserService
|
||||
{
|
||||
Task<User?> GetByUID(int uid);
|
||||
Task<User?> GetByUsername(string username);
|
||||
Task<User?> GetByUUID(Guid uuid);
|
||||
Task<User?> GetByEmail(string email);
|
||||
Task<User?> GetByUID(int uid, bool withPastes = false);
|
||||
Task<User?> GetByUsername(string username, bool withPastes = false);
|
||||
Task<User?> GetByUUID(Guid uuid, bool withPastes = false);
|
||||
Task<User?> GetByEmail(string email, bool withPastes = false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@ namespace SharpbinV3.Server.Services
|
||||
ExpiresAt = expiresAt,
|
||||
};
|
||||
_db.Pastes.Add(paste);
|
||||
if (author != null)
|
||||
{
|
||||
author.Pastes.Add(paste);
|
||||
_db.Users.Update(author);
|
||||
}
|
||||
await _db.SaveChangesAsync();
|
||||
return paste;
|
||||
}
|
||||
|
||||
@@ -8,10 +8,36 @@ namespace SharpbinV3.Server.Services
|
||||
public sealed class UserService(AppDbContext db) : IUserService
|
||||
{
|
||||
private readonly AppDbContext _db = db;
|
||||
public Task<User?> GetByUID(int uid, bool withPastes = false)
|
||||
{
|
||||
IQueryable<User> query = _db.Users;
|
||||
if (withPastes)
|
||||
query = query.Include(u => u.Pastes);
|
||||
return query.FirstOrDefaultAsync(u => u.UID == uid);
|
||||
}
|
||||
|
||||
public Task<User?> GetByUID(int uid) => _db.Users.FirstOrDefaultAsync(u => u.UID == uid);
|
||||
public Task<User?> GetByUUID(Guid uuid) => _db.Users.FirstOrDefaultAsync(u => u.UUID == uuid);
|
||||
public Task<User?> GetByUsername(string username) => _db.Users.FirstOrDefaultAsync(u => u.Username == username);
|
||||
public Task<User?> GetByEmail(string email) => _db.Users.FirstOrDefaultAsync(u => u.Email == email);
|
||||
public Task<User?> GetByUUID(Guid uuid, bool withPastes = false)
|
||||
{
|
||||
IQueryable<User> query = _db.Users;
|
||||
if (withPastes)
|
||||
query = query.Include(u => u.Pastes);
|
||||
return query.FirstOrDefaultAsync(u => u.UUID == uuid);
|
||||
}
|
||||
|
||||
public Task<User?> GetByUsername(string username, bool withPastes = false)
|
||||
{
|
||||
IQueryable<User> query = _db.Users;
|
||||
if (withPastes)
|
||||
query = query.Include(u => u.Pastes);
|
||||
return query.FirstOrDefaultAsync(u => u.Username == username);
|
||||
}
|
||||
|
||||
public Task<User?> GetByEmail(string email, bool withPastes = false)
|
||||
{
|
||||
IQueryable<User> query = _db.Users;
|
||||
if (withPastes)
|
||||
query = query.Include(u => u.Pastes);
|
||||
return query.FirstOrDefaultAsync(u => u.Email == email);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user