mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
fix!: normalize and make usernames unique
This commit is contained in:
@@ -15,6 +15,7 @@ namespace SharpbinV3.Server.Data.Entities
|
|||||||
|
|
||||||
[Index(nameof(UID))]
|
[Index(nameof(UID))]
|
||||||
[Index(nameof(UUID), IsUnique = true)]
|
[Index(nameof(UUID), IsUnique = true)]
|
||||||
|
[Index(nameof(Username), IsUnique = true)]
|
||||||
public sealed class User
|
public sealed class User
|
||||||
{
|
{
|
||||||
public long? UID { get; set; }
|
public long? UID { get; set; }
|
||||||
|
|||||||
@@ -0,0 +1,626 @@
|
|||||||
|
// <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("20260614000001_NormalizeUsernames")]
|
||||||
|
partial class NormalizeUsernames
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder.HasAnnotation("ProductVersion", "10.0.3");
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("UUID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<long>("CreatedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("KeyHash")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<long?>("LastUsedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserUUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("UUID");
|
||||||
|
|
||||||
|
b.HasIndex("UserUUID");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Comment", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<byte[]>("Content")
|
||||||
|
.HasMaxLength(5000)
|
||||||
|
.HasColumnType("BLOB");
|
||||||
|
|
||||||
|
b.Property<long>("CreatedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<bool>("IsCompressed")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("OriginalSize")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long?>("ParentCommentID")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("PastePID")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("StoredSize")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long?>("UpdatedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserUUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ParentCommentID");
|
||||||
|
|
||||||
|
b.HasIndex("PastePID");
|
||||||
|
|
||||||
|
b.HasIndex("UserUUID");
|
||||||
|
|
||||||
|
b.ToTable("Comments");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.CommentInteraction", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("CommentID")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("CreatedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Type")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserUUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CommentID", "Type");
|
||||||
|
|
||||||
|
b.HasIndex("CommentID", "UserUUID")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("CommentInteractions");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.EmailVerificationToken", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("UUID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<long>("CreatedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("ExpiresAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("TokenHash")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Type")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<bool>("Used")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserUUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("UUID");
|
||||||
|
|
||||||
|
b.HasIndex("UserUUID");
|
||||||
|
|
||||||
|
b.ToTable("EmailVerificationTokens");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Paste", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("PID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<Guid?>("AuthorUUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<byte[]>("Content")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("BLOB");
|
||||||
|
|
||||||
|
b.Property<long>("CreatedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
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>("OriginalSize")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("StoredSize")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Syntax")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<Guid>("UUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
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("StoredSize");
|
||||||
|
|
||||||
|
b.HasIndex("Syntax");
|
||||||
|
|
||||||
|
b.HasIndex("UUID");
|
||||||
|
|
||||||
|
b.HasIndex("Views");
|
||||||
|
|
||||||
|
b.ToTable("Pastes");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.PasteInteraction", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("CreatedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("PasteID")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Type")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserUUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PasteID", "Type");
|
||||||
|
|
||||||
|
b.HasIndex("PasteID", "UserUUID")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("PasteInteractions");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.PasteView", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("PastePID")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("ViewedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("ViewerHash")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PastePID", "ViewerHash")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("PasteViews");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.RefreshToken", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("CreatedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("ExpiresAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("JwtId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("ReplacedByToken")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("Revoked")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<byte[]>("RowVersion")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("BLOB");
|
||||||
|
|
||||||
|
b.Property<string>("TokenHash")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("Used")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserUUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("TokenHash")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("UserUUID");
|
||||||
|
|
||||||
|
b.ToTable("RefreshTokens");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Report", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("ReportID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long?>("CommentID")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("CreatedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasMaxLength(1000)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<long?>("PastePID")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<Guid>("ReporterUUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("TargetType")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Type")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long?>("UpdatedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<Guid?>("UserUUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("ReportID");
|
||||||
|
|
||||||
|
b.HasIndex("CommentID");
|
||||||
|
|
||||||
|
b.HasIndex("PastePID");
|
||||||
|
|
||||||
|
b.HasIndex("ReportID")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("ReporterUUID");
|
||||||
|
|
||||||
|
b.HasIndex("TargetType");
|
||||||
|
|
||||||
|
b.HasIndex("UserUUID");
|
||||||
|
|
||||||
|
b.ToTable("Reports");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("UUID")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<long>("CreatedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("DisplayName")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("EmailVerified")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<bool>("IsBanned")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long?>("LastLogin")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("PasswordHash")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Roles")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long?>("UID")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Visibility")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("UUID");
|
||||||
|
|
||||||
|
b.HasIndex("UID");
|
||||||
|
|
||||||
|
b.HasIndex("UUID")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("Username")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.UserTotp", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("UserUUID")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<long>("CreatedAt")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<byte[]>("EncryptedSecret")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("BLOB");
|
||||||
|
|
||||||
|
b.HasKey("UserUUID");
|
||||||
|
|
||||||
|
b.ToTable("UserTotps");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
|
||||||
|
.WithMany("ApiKeys")
|
||||||
|
.HasForeignKey("UserUUID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Comment", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.Comment", "ParentComment")
|
||||||
|
.WithMany("Replies")
|
||||||
|
.HasForeignKey("ParentCommentID")
|
||||||
|
.OnDelete(DeleteBehavior.Restrict);
|
||||||
|
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.Paste", "Paste")
|
||||||
|
.WithMany("Comments")
|
||||||
|
.HasForeignKey("PastePID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
|
||||||
|
.WithMany("Comments")
|
||||||
|
.HasForeignKey("UserUUID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("ParentComment");
|
||||||
|
|
||||||
|
b.Navigation("Paste");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.CommentInteraction", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.Comment", "Comment")
|
||||||
|
.WithMany("Interactions")
|
||||||
|
.HasForeignKey("CommentID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Comment");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.EmailVerificationToken", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
|
||||||
|
.WithMany("EmailVerificationTokens")
|
||||||
|
.HasForeignKey("UserUUID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Paste", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
|
||||||
|
.WithMany("Pastes")
|
||||||
|
.HasForeignKey("AuthorUUID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.PasteInteraction", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.Paste", "Paste")
|
||||||
|
.WithMany("Interactions")
|
||||||
|
.HasForeignKey("PasteID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Paste");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.PasteView", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.Paste", "Paste")
|
||||||
|
.WithMany("PasteViews")
|
||||||
|
.HasForeignKey("PastePID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Paste");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.RefreshToken", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
|
||||||
|
.WithMany("RefreshTokens")
|
||||||
|
.HasForeignKey("UserUUID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Report", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.Comment", null)
|
||||||
|
.WithMany("Reports")
|
||||||
|
.HasForeignKey("CommentID")
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.Paste", "Paste")
|
||||||
|
.WithMany("Reports")
|
||||||
|
.HasForeignKey("PastePID")
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
|
||||||
|
.WithMany("Reports")
|
||||||
|
.HasForeignKey("UserUUID")
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
|
b.Navigation("Paste");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.UserTotp", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SharpbinV3.Server.Data.Entities.User", "User")
|
||||||
|
.WithOne("Totp")
|
||||||
|
.HasForeignKey("SharpbinV3.Server.Data.Entities.UserTotp", "UserUUID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Comment", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Interactions");
|
||||||
|
|
||||||
|
b.Navigation("Replies");
|
||||||
|
|
||||||
|
b.Navigation("Reports");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.Paste", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Comments");
|
||||||
|
|
||||||
|
b.Navigation("Interactions");
|
||||||
|
|
||||||
|
b.Navigation("PasteViews");
|
||||||
|
|
||||||
|
b.Navigation("Reports");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SharpbinV3.Server.Data.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("ApiKeys");
|
||||||
|
|
||||||
|
b.Navigation("Comments");
|
||||||
|
|
||||||
|
b.Navigation("EmailVerificationTokens");
|
||||||
|
|
||||||
|
b.Navigation("Pastes");
|
||||||
|
|
||||||
|
b.Navigation("RefreshTokens");
|
||||||
|
|
||||||
|
b.Navigation("Reports");
|
||||||
|
|
||||||
|
b.Navigation("Totp");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SharpbinV3.Server.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class NormalizeUsernames : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.Sql(@"UPDATE Users SET Username = lower(Username);");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Users_Username",
|
||||||
|
table: "Users",
|
||||||
|
column: "Username",
|
||||||
|
unique: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Users_Username",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -423,6 +423,9 @@ namespace SharpbinV3.Server.Migrations
|
|||||||
b.HasIndex("UUID")
|
b.HasIndex("UUID")
|
||||||
.IsUnique();
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("Username")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace SharpbinV3.Server.Services
|
|||||||
{
|
{
|
||||||
var user = new User
|
var user = new User
|
||||||
{
|
{
|
||||||
Username = username,
|
Username = UserService.NormalizeUsername(username),
|
||||||
PasswordHash = Bcrypt.HashPassword(password),
|
PasswordHash = Bcrypt.HashPassword(password),
|
||||||
Email = email,
|
Email = email,
|
||||||
DisplayName = displayName,
|
DisplayName = displayName,
|
||||||
@@ -181,7 +181,7 @@ namespace SharpbinV3.Server.Services
|
|||||||
public async Task<User> UpdateUser(User user)
|
public async Task<User> UpdateUser(User user)
|
||||||
{
|
{
|
||||||
var existingUser = await _db.Users.FirstOrDefaultAsync(u => u.UUID == user.UUID) ?? throw new Exception("User not found");
|
var existingUser = await _db.Users.FirstOrDefaultAsync(u => u.UUID == user.UUID) ?? throw new Exception("User not found");
|
||||||
existingUser.Username = user.Username;
|
existingUser.Username = UserService.NormalizeUsername(user.Username);
|
||||||
existingUser.Email = user.Email;
|
existingUser.Email = user.Email;
|
||||||
existingUser.DisplayName = user.DisplayName;
|
existingUser.DisplayName = user.DisplayName;
|
||||||
existingUser.Roles = user.Roles;
|
existingUser.Roles = user.Roles;
|
||||||
|
|||||||
@@ -26,10 +26,11 @@ namespace SharpbinV3.Server.Services
|
|||||||
|
|
||||||
public Task<User?> GetByUsername(string username, bool withPastes = false)
|
public Task<User?> GetByUsername(string username, bool withPastes = false)
|
||||||
{
|
{
|
||||||
|
var normalizedUsername = NormalizeUsername(username);
|
||||||
IQueryable<User> query = _db.Users;
|
IQueryable<User> query = _db.Users;
|
||||||
if (withPastes)
|
if (withPastes)
|
||||||
query = query.Include(u => u.Pastes);
|
query = query.Include(u => u.Pastes);
|
||||||
return query.FirstOrDefaultAsync(u => u.Username == username);
|
return query.FirstOrDefaultAsync(u => u.Username == normalizedUsername);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<User?> GetByEmail(string email, bool withPastes = false)
|
public Task<User?> GetByEmail(string email, bool withPastes = false)
|
||||||
@@ -42,9 +43,12 @@ namespace SharpbinV3.Server.Services
|
|||||||
|
|
||||||
public async Task<User> Update(User user)
|
public async Task<User> Update(User user)
|
||||||
{
|
{
|
||||||
|
user.Username = NormalizeUsername(user.Username);
|
||||||
_db.Users.Update(user);
|
_db.Users.Update(user);
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string NormalizeUsername(string username) => username.ToLowerInvariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user