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:
2025-12-28 13:54:01 -05:00
parent b9b14a3d5a
commit db1d8704a1
38 changed files with 1334 additions and 103 deletions
+36
View File
@@ -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;
}
}
}
}
+8 -2
View File
@@ -31,8 +31,13 @@ namespace SharpbinV3.Server.Controllers
string content = await new StreamReader(Request.Body).ReadToEndAsync();
var httpUser = HttpContext.User;
foreach (var key in httpUser.Claims)
{
Console.WriteLine($"Claim: {key.Type} = {key.Value}");
}
var userUUID = httpUser?.FindFirst("UUID")?.Value;
User? user = userUUID is not null ? await _userService.GetByUUID(Guid.Parse(userUUID)) : null;
Console.WriteLine($"Creating paste for user: {(user != null ? user.Username : "Anonymous")}");
Paste paste = await _pasteService.Create(user, content, title, syntax, visibility, expiresAt);
return Ok(new
{
@@ -62,12 +67,13 @@ namespace SharpbinV3.Server.Controllers
paste.Syntax,
paste.Visibility,
paste.ExpiresAt,
Author = paste.User != null && paste.User.Visiblity == 0 ? new
Author = paste.User != null && paste.User.Visibility == 0 ? new
{
paste.User.UID,
paste.User.UUID,
paste.User.Username,
paste.User.Visiblity
paste.User.DisplayName,
paste.User.Visibility
} : null
});
}
+35 -10
View File
@@ -10,15 +10,7 @@ namespace SharpbinV3.Server.Controllers
{
private readonly IUserService _userService = userService;
[HttpGet("{uid}")]
public async Task<IActionResult> GetByUid(int uid)
{
var user = await _userService.GetByUID(uid);
if (user == null) return NotFound();
return Ok(new { user.UID, user.Username, user.UUID, user.DisplayName });
}
[HttpGet("username/{username}")]
[HttpGet("{username}")]
public async Task<IActionResult> GetByUsername(string username)
{
var user = await _userService.GetByUsername(username);
@@ -26,12 +18,45 @@ namespace SharpbinV3.Server.Controllers
return Ok(new { user.UID, user.Username, user.UUID, user.DisplayName });
}
[HttpGet("uuid/{uuid}")]
[Authorize]
public async Task<IActionResult> GetByUUID(Guid uuid)
{
var user = await _userService.GetByUUID(uuid);
if (user == null) return NotFound();
return Ok(new { user.UID, user.Username, user.UUID, user.DisplayName });
}
[HttpGet("me")]
[Authorize]
public async Task<IActionResult> GetMe()
{
var httpUser = HttpContext.User;
var userUUID = httpUser?.FindFirst("UUID")?.Value;
if (userUUID is null)
return Unauthorized(new { message = "Invalid token." });
var user = await _userService.GetByUUID(Guid.Parse(userUUID), true);
if (user == null)
return NotFound();
var pastes = user.Pastes?.Select(p => new {
p.UUID,
p.Title,
p.Syntax,
p.Size,
p.TrueSize,
p.Views,
p.Visibility,
p.EditedAt,
p.ExpiresAt
});
return Ok(new {
user.UID,
user.Username,
user.UUID,
user.DisplayName,
user.Email,
user.LastLogin,
user.Roles,
user.Visibility,
Pastes = pastes
});
}
}
}
-1
View File
@@ -6,7 +6,6 @@ namespace SharpbinV3.Server.DTOs
{
[StringLength(50, MinimumLength = 3)]
public string? Username { get; set; }
[EmailAddress]
public string? Email { get; set; }
[StringLength(128, MinimumLength = 6)]
public string? Password { get; set; }
-1
View File
@@ -12,7 +12,6 @@ namespace SharpbinV3.Server.DTOs
[StringLength(128, MinimumLength = 6)]
public required string Password { get; set; }
[EmailAddress]
public string? Email { get; set; }
public string? DisplayName { get; set; }
+2 -2
View File
@@ -24,8 +24,8 @@ namespace SharpbinV3.Server.Data.Entities
public long? EditedAt { get; set; }
public required byte[] Content { get; set; }
public int Size { get; set; } // stored size (may be compressed)
public int TrueSize { get; set; } // uncompressed size
public long Size { get; set; } // stored size (may be compressed)
public long TrueSize { get; set; } // uncompressed size
public bool IsCompressed { get; set; } = false;
public int Views { get; set; }
+1 -2
View File
@@ -3,7 +3,6 @@ using System.ComponentModel.DataAnnotations;
namespace SharpbinV3.Server.Data.Entities
{
[Index(nameof(UID), IsUnique = true)]
[Index(nameof(UUID), IsUnique = true)]
public sealed class User
{
@@ -16,7 +15,7 @@ namespace SharpbinV3.Server.Data.Entities
public string? DisplayName { get; set; }
public long? LastLogin { get; set; }
public int[] Roles { get; set; } = [0]; // 0 = regular user, 1 = moderator, 255 = admin
public int Visiblity { get; set; } = 0; // 0 = public, 1 = unlisted, 2 = private
public int Visibility { get; set; } = 0; // 0 = public, 1 = unlisted, 2 = private
public List<Paste> Pastes { get; set; } = [];
}
}
@@ -0,0 +1,195 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharpbinV3.Server.Data;
#nullable disable
namespace SharpbinV3.Server.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20251228173503_UserGrammarFix")]
partial class UserGrammarFix
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.0");
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Paste", b =>
{
b.Property<int>("PID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<Guid>("AuthorUUID")
.HasColumnType("TEXT");
b.Property<byte[]>("Content")
.IsRequired()
.HasColumnType("BLOB");
b.Property<long?>("EditedAt")
.HasColumnType("INTEGER");
b.Property<long>("ExpiresAt")
.HasColumnType("INTEGER");
b.Property<string>("ID")
.HasColumnType("TEXT");
b.Property<bool>("IsCompressed")
.HasColumnType("INTEGER");
b.Property<int>("Size")
.HasColumnType("INTEGER");
b.Property<string>("Syntax")
.HasColumnType("TEXT");
b.Property<string>("Title")
.HasColumnType("TEXT");
b.Property<int>("TrueSize")
.HasColumnType("INTEGER");
b.Property<Guid>("UUID")
.HasColumnType("TEXT");
b.Property<int?>("UserUID")
.HasColumnType("INTEGER");
b.Property<int>("Views")
.HasColumnType("INTEGER");
b.Property<int>("Visibility")
.HasColumnType("INTEGER");
b.HasKey("PID");
b.HasIndex("AuthorUUID");
b.HasIndex("ExpiresAt");
b.HasIndex("ID")
.IsUnique();
b.HasIndex("PID")
.IsUnique();
b.HasIndex("UUID")
.IsUnique();
b.HasIndex("UserUID");
b.HasIndex("Views");
b.HasIndex("Visibility");
b.ToTable("Pastes");
});
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.RefreshToken", b =>
{
b.Property<Guid>("UserUUID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<long>("CreatedAt")
.HasColumnType("INTEGER");
b.Property<long>("ExpiresAt")
.HasColumnType("INTEGER");
b.Property<string>("JwtId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("Used")
.HasColumnType("INTEGER");
b.Property<int?>("UserUID")
.HasColumnType("INTEGER");
b.HasKey("UserUUID");
b.HasIndex("UserUID");
b.ToTable("RefreshTokens");
});
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.User", b =>
{
b.Property<int>("UID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("DisplayName")
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasColumnType("TEXT");
b.Property<long?>("LastLogin")
.HasColumnType("INTEGER");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("TEXT");
b.PrimitiveCollection<string>("Roles")
.IsRequired()
.HasColumnType("TEXT");
b.Property<Guid>("UUID")
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Visibility")
.HasColumnType("INTEGER");
b.HasKey("UID");
b.HasIndex("UUID")
.IsUnique();
b.ToTable("Users");
});
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Paste", b =>
{
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
.WithMany("Pastes")
.HasForeignKey("UserUID");
b.Navigation("User");
});
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.RefreshToken", b =>
{
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
.WithMany()
.HasForeignKey("UserUID");
b.Navigation("User");
});
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.User", b =>
{
b.Navigation("Pastes");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SharpbinV3.Server.Migrations
{
/// <inheritdoc />
public partial class UserGrammarFix : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_Users_UID",
table: "Users");
migrationBuilder.RenameColumn(
name: "Visiblity",
table: "Users",
newName: "Visibility");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "Visibility",
table: "Users",
newName: "Visiblity");
migrationBuilder.CreateIndex(
name: "IX_Users_UID",
table: "Users",
column: "UID",
unique: true);
}
}
}
@@ -0,0 +1,195 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharpbinV3.Server.Data;
#nullable disable
namespace SharpbinV3.Server.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20251228175338_LongFileSizes")]
partial class LongFileSizes
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.0");
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Paste", b =>
{
b.Property<int>("PID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<Guid>("AuthorUUID")
.HasColumnType("TEXT");
b.Property<byte[]>("Content")
.IsRequired()
.HasColumnType("BLOB");
b.Property<long?>("EditedAt")
.HasColumnType("INTEGER");
b.Property<long>("ExpiresAt")
.HasColumnType("INTEGER");
b.Property<string>("ID")
.HasColumnType("TEXT");
b.Property<bool>("IsCompressed")
.HasColumnType("INTEGER");
b.Property<long>("Size")
.HasColumnType("INTEGER");
b.Property<string>("Syntax")
.HasColumnType("TEXT");
b.Property<string>("Title")
.HasColumnType("TEXT");
b.Property<long>("TrueSize")
.HasColumnType("INTEGER");
b.Property<Guid>("UUID")
.HasColumnType("TEXT");
b.Property<int?>("UserUID")
.HasColumnType("INTEGER");
b.Property<int>("Views")
.HasColumnType("INTEGER");
b.Property<int>("Visibility")
.HasColumnType("INTEGER");
b.HasKey("PID");
b.HasIndex("AuthorUUID");
b.HasIndex("ExpiresAt");
b.HasIndex("ID")
.IsUnique();
b.HasIndex("PID")
.IsUnique();
b.HasIndex("UUID")
.IsUnique();
b.HasIndex("UserUID");
b.HasIndex("Views");
b.HasIndex("Visibility");
b.ToTable("Pastes");
});
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.RefreshToken", b =>
{
b.Property<Guid>("UserUUID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<long>("CreatedAt")
.HasColumnType("INTEGER");
b.Property<long>("ExpiresAt")
.HasColumnType("INTEGER");
b.Property<string>("JwtId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("Used")
.HasColumnType("INTEGER");
b.Property<int?>("UserUID")
.HasColumnType("INTEGER");
b.HasKey("UserUUID");
b.HasIndex("UserUID");
b.ToTable("RefreshTokens");
});
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.User", b =>
{
b.Property<int>("UID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("DisplayName")
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasColumnType("TEXT");
b.Property<long?>("LastLogin")
.HasColumnType("INTEGER");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("TEXT");
b.PrimitiveCollection<string>("Roles")
.IsRequired()
.HasColumnType("TEXT");
b.Property<Guid>("UUID")
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Visibility")
.HasColumnType("INTEGER");
b.HasKey("UID");
b.HasIndex("UUID")
.IsUnique();
b.ToTable("Users");
});
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Paste", b =>
{
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
.WithMany("Pastes")
.HasForeignKey("UserUID");
b.Navigation("User");
});
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.RefreshToken", b =>
{
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
.WithMany()
.HasForeignKey("UserUID");
b.Navigation("User");
});
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.User", b =>
{
b.Navigation("Pastes");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SharpbinV3.Server.Migrations
{
/// <inheritdoc />
public partial class LongFileSizes : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}
@@ -17,7 +17,7 @@ namespace SharpbinV3.Server.Migrations
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.0");
modelBuilder.Entity("SharpbinV3.Data.Entities.Paste", b =>
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Paste", b =>
{
b.Property<int>("PID")
.ValueGeneratedOnAdd()
@@ -42,7 +42,7 @@ namespace SharpbinV3.Server.Migrations
b.Property<bool>("IsCompressed")
.HasColumnType("INTEGER");
b.Property<int>("Size")
b.Property<long>("Size")
.HasColumnType("INTEGER");
b.Property<string>("Syntax")
@@ -51,7 +51,7 @@ namespace SharpbinV3.Server.Migrations
b.Property<string>("Title")
.HasColumnType("TEXT");
b.Property<int>("TrueSize")
b.Property<long>("TrueSize")
.HasColumnType("INTEGER");
b.Property<Guid>("UUID")
@@ -90,7 +90,7 @@ namespace SharpbinV3.Server.Migrations
b.ToTable("Pastes");
});
modelBuilder.Entity("SharpbinV3.Data.Entities.RefreshToken", b =>
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.RefreshToken", b =>
{
b.Property<Guid>("UserUUID")
.ValueGeneratedOnAdd()
@@ -123,7 +123,7 @@ namespace SharpbinV3.Server.Migrations
b.ToTable("RefreshTokens");
});
modelBuilder.Entity("SharpbinV3.Data.Entities.User", b =>
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.User", b =>
{
b.Property<int>("UID")
.ValueGeneratedOnAdd()
@@ -153,39 +153,36 @@ namespace SharpbinV3.Server.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Visiblity")
b.Property<int>("Visibility")
.HasColumnType("INTEGER");
b.HasKey("UID");
b.HasIndex("UID")
.IsUnique();
b.HasIndex("UUID")
.IsUnique();
b.ToTable("Users");
});
modelBuilder.Entity("SharpbinV3.Data.Entities.Paste", b =>
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Paste", b =>
{
b.HasOne("SharpbinV3.Data.Entities.User", "User")
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
.WithMany("Pastes")
.HasForeignKey("UserUID");
b.Navigation("User");
});
modelBuilder.Entity("SharpbinV3.Data.Entities.RefreshToken", b =>
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.RefreshToken", b =>
{
b.HasOne("SharpbinV3.Data.Entities.User", "User")
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
.WithMany()
.HasForeignKey("UserUID");
b.Navigation("User");
});
modelBuilder.Entity("SharpbinV3.Data.Entities.User", b =>
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.User", b =>
{
b.Navigation("Pastes");
});
+4 -3
View File
@@ -38,16 +38,17 @@ namespace SharpbinV3.Server
})
.AddJwtBearer(jwt =>
{
var key = Encoding.ASCII.GetBytes(builder.Configuration.GetSection("JwtConfig:Secret").Value ?? string.Empty);
var jwtSettings = builder.Configuration.GetSection("JwtSettings");
var key = Encoding.ASCII.GetBytes(jwtSettings["Secret"] ?? string.Empty);
jwt.SaveToken = true;
jwt.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = true,
ValidIssuer = builder.Configuration["JwtConfig:Issuer"],
ValidIssuer = jwtSettings["Issuer"],
ValidateAudience = true,
ValidAudience = builder.Configuration["JwtConfig:Audience"],
ValidAudience = jwtSettings["Audience"],
RequireExpirationTime = true,
ValidateLifetime = true
};
+4 -4
View File
@@ -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 -4
View File
@@ -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);
}
}
+5
View File
@@ -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;
}
+30 -4
View File
@@ -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);
}
}
}
+3 -3
View File
@@ -2,8 +2,8 @@
{
public class JWTSettings
{
public string SecretKey { get; set; } = Utilities.GenerateRandomString(64);
public string Issuer { get; set; } = "SharpbinV3";
public string Audience { get; set; } = "SharpbinV3.Client";
public string Secret { get; set; } = Utilities.GenerateRandomString(64);
public string Issuer { get; set; } = "SharpbinApi";
public string Audience { get; set; } = "SharpbinClient";
}
}
+5
View File
@@ -4,5 +4,10 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"JwtSettings": {
"Secret": "ad277c181e51d2131017abc53a5805ccb85410ab902d2e1e09266304e4e86d6c38f2b2543b708d678dfdbfb76016dcf568925ddb25dc91638a69e479e31a23c9",
"Issuer": "SharpbinApi",
"Audience": "SharpbinClient"
}
}