diff --git a/.gitignore b/.gitignore index bb08bcee..d0391f6a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,11 @@ riderModule.iml lighthouse.config.json gitBranch.txt gitVersion.txt +ProjectLighthouse/.vscode/tasks.json +ProjectLighthouse/.vscode/launch.json +logs/Startup.log +logs/LoggerInfo.log +logs/all.log +.vscode/tasks.json +.vscode/launch.json +.editorconfig diff --git a/ProjectLighthouse/Database.cs b/ProjectLighthouse/Database.cs index 3a5366cc..6e84e6ef 100644 --- a/ProjectLighthouse/Database.cs +++ b/ProjectLighthouse/Database.cs @@ -6,6 +6,7 @@ using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Levels; +using LBPUnion.ProjectLighthouse.Types.Reviews; using LBPUnion.ProjectLighthouse.Types.Profiles; using LBPUnion.ProjectLighthouse.Types.Settings; using Microsoft.AspNetCore.Http; @@ -31,6 +32,8 @@ namespace LBPUnion.ProjectLighthouse public DbSet VisitedLevels { get; set; } public DbSet RatedLevels { get; set; } public DbSet AuthenticationAttempts { get; set; } + public DbSet Reviews { get; set; } + public DbSet RatedReviews { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseMySql(ServerSettings.Instance.DbConnectionString, MySqlServerVersion.LatestSupportedServerVersion); @@ -60,7 +63,7 @@ namespace LBPUnion.ProjectLighthouse return user; } - #nullable enable +#nullable enable public async Task AuthenticateUser(LoginData loginData, string userLocation, string titleId = "") { // TODO: don't use psn name to authenticate @@ -252,6 +255,6 @@ namespace LBPUnion.ProjectLighthouse public async Task PhotoFromSubject(PhotoSubject subject) => await this.Photos.FirstOrDefaultAsync(p => p.PhotoSubjectIds.Contains(subject.PhotoSubjectId.ToString())); - #nullable disable +#nullable disable } } \ No newline at end of file diff --git a/ProjectLighthouse/Maintenance/Commands/CreateUserCommand.cs b/ProjectLighthouse/Maintenance/Commands/CreateUserCommand.cs index b3db6c4a..ca0379fb 100644 --- a/ProjectLighthouse/Maintenance/Commands/CreateUserCommand.cs +++ b/ProjectLighthouse/Maintenance/Commands/CreateUserCommand.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics; +#nullable enable using System.Threading.Tasks; using JetBrains.Annotations; using Kettu; @@ -21,7 +20,7 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands string password = args[1]; password = HashHelper.Sha256Hash(password); - + User? user = await this._database.Users.FirstOrDefaultAsync(u => u.Username == onlineId); if (user == null) { diff --git a/ProjectLighthouse/Maintenance/Commands/WipeTokensForUserCommand.cs b/ProjectLighthouse/Maintenance/Commands/WipeTokensForUserCommand.cs index 4e42461a..3da9514c 100644 --- a/ProjectLighthouse/Maintenance/Commands/WipeTokensForUserCommand.cs +++ b/ProjectLighthouse/Maintenance/Commands/WipeTokensForUserCommand.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Linq; using System.Threading.Tasks; diff --git a/ProjectLighthouse/Migrations/20211211043517_CacheReviewStats.cs b/ProjectLighthouse/Migrations/20211211043517_CacheReviewStats.cs deleted file mode 100644 index 43ff8248..00000000 --- a/ProjectLighthouse/Migrations/20211211043517_CacheReviewStats.cs +++ /dev/null @@ -1,66 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ProjectLighthouse.Migrations -{ - public partial class CacheReviewStats : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "DeletedBy", - table: "Reviews", - type: "int", - nullable: false, - oldClrType: typeof(string), - oldType: "longtext") - .OldAnnotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.AddColumn( - name: "Thumb", - table: "Reviews", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "ThumbsDown", - table: "Reviews", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "ThumbsUp", - table: "Reviews", - type: "int", - nullable: false, - defaultValue: 0); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "Thumb", - table: "Reviews"); - - migrationBuilder.DropColumn( - name: "ThumbsDown", - table: "Reviews"); - - migrationBuilder.DropColumn( - name: "ThumbsUp", - table: "Reviews"); - - migrationBuilder.AlterColumn( - name: "DeletedBy", - table: "Reviews", - type: "longtext", - nullable: false, - oldClrType: typeof(int), - oldType: "int") - .Annotation("MySql:CharSet", "utf8mb4"); - } - } -} diff --git a/ProjectLighthouse/Migrations/20211211043517_CacheReviewStats.Designer.cs b/ProjectLighthouse/Migrations/20211211045823_AddLevelReviews.Designer.cs similarity index 98% rename from ProjectLighthouse/Migrations/20211211043517_CacheReviewStats.Designer.cs rename to ProjectLighthouse/Migrations/20211211045823_AddLevelReviews.Designer.cs index ca4261c1..98610a6c 100644 --- a/ProjectLighthouse/Migrations/20211211043517_CacheReviewStats.Designer.cs +++ b/ProjectLighthouse/Migrations/20211211045823_AddLevelReviews.Designer.cs @@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ProjectLighthouse.Migrations { [DbContext(typeof(Database))] - [Migration("20211211043517_CacheReviewStats")] - partial class CacheReviewStats + [Migration("20211211045823_AddLevelReviews")] + partial class AddLevelReviews { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -407,7 +407,7 @@ namespace ProjectLighthouse.Migrations b.ToTable("Comments"); }); - modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.LastMatch", b => + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.LastContact", b => { b.Property("UserId") .ValueGeneratedOnAdd() @@ -421,7 +421,7 @@ namespace ProjectLighthouse.Migrations b.HasKey("UserId"); - b.ToTable("LastMatches"); + b.ToTable("LastContacts"); }); modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.Location", b => @@ -546,6 +546,9 @@ namespace ProjectLighthouse.Migrations b.Property("Biography") .HasColumnType("longtext"); + b.Property("BooHash") + .HasColumnType("longtext"); + b.Property("Game") .HasColumnType("int"); @@ -558,6 +561,9 @@ namespace ProjectLighthouse.Migrations b.Property("LocationId") .HasColumnType("int"); + b.Property("MehHash") + .HasColumnType("longtext"); + b.Property("Password") .HasColumnType("longtext"); @@ -573,6 +579,9 @@ namespace ProjectLighthouse.Migrations b.Property("Username") .HasColumnType("longtext"); + b.Property("YayHash") + .HasColumnType("longtext"); + b.HasKey("UserId"); b.HasIndex("LocationId"); diff --git a/ProjectLighthouse/Migrations/20211211045823_AddLevelReviews.cs b/ProjectLighthouse/Migrations/20211211045823_AddLevelReviews.cs new file mode 100644 index 00000000..ccdf6c2c --- /dev/null +++ b/ProjectLighthouse/Migrations/20211211045823_AddLevelReviews.cs @@ -0,0 +1,107 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ProjectLighthouse.Migrations +{ + public partial class AddLevelReviews : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Reviews", + columns: table => new + { + ReviewId = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + ReviewerId = table.Column(type: "int", nullable: false), + SlotId = table.Column(type: "int", nullable: false), + Timestamp = table.Column(type: "bigint", nullable: false), + LabelCollection = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Deleted = table.Column(type: "tinyint(1)", nullable: false), + DeletedBy = table.Column(type: "int", nullable: false), + Text = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Thumb = table.Column(type: "int", nullable: false), + ThumbsUp = table.Column(type: "int", nullable: false), + ThumbsDown = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Reviews", x => x.ReviewId); + table.ForeignKey( + name: "FK_Reviews_Slots_SlotId", + column: x => x.SlotId, + principalTable: "Slots", + principalColumn: "SlotId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Reviews_Users_ReviewerId", + column: x => x.ReviewerId, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "RatedReviews", + columns: table => new + { + RatedReviewId = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + UserId = table.Column(type: "int", nullable: false), + ReviewId = table.Column(type: "int", nullable: false), + Thumb = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RatedReviews", x => x.RatedReviewId); + table.ForeignKey( + name: "FK_RatedReviews_Reviews_ReviewId", + column: x => x.ReviewId, + principalTable: "Reviews", + principalColumn: "ReviewId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_RatedReviews_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_RatedReviews_ReviewId", + table: "RatedReviews", + column: "ReviewId"); + + migrationBuilder.CreateIndex( + name: "IX_RatedReviews_UserId", + table: "RatedReviews", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Reviews_ReviewerId", + table: "Reviews", + column: "ReviewerId"); + + migrationBuilder.CreateIndex( + name: "IX_Reviews_SlotId", + table: "Reviews", + column: "SlotId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "RatedReviews"); + + migrationBuilder.DropTable( + name: "Reviews"); + } + } +} diff --git a/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs b/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs index 70f91a28..4afc7b51 100644 --- a/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs +++ b/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs @@ -770,6 +770,44 @@ namespace ProjectLighthouse.Migrations b.Navigation("Target"); }); + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Reviews.RatedReview", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.Reviews.Review", "Review") + .WithMany() + .HasForeignKey("ReviewId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Review"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Reviews.Review", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "Reviewer") + .WithMany() + .HasForeignKey("ReviewerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LBPUnion.ProjectLighthouse.Types.Levels.Slot", "Slot") + .WithMany() + .HasForeignKey("SlotId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Reviewer"); + + b.Navigation("Slot"); + }); + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Score", b => { b.HasOne("LBPUnion.ProjectLighthouse.Types.Levels.Slot", "Slot") diff --git a/ProjectLighthouse/Pages/ExternalAuth/AuthenticationPage.cshtml.cs b/ProjectLighthouse/Pages/ExternalAuth/AuthenticationPage.cshtml.cs index f64d3102..c4bd98e3 100644 --- a/ProjectLighthouse/Pages/ExternalAuth/AuthenticationPage.cshtml.cs +++ b/ProjectLighthouse/Pages/ExternalAuth/AuthenticationPage.cshtml.cs @@ -12,7 +12,7 @@ namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth public class AuthenticationPage : BaseLayout { public AuthenticationPage(Database database) : base(database) - {} + { } public List AuthenticationAttempts; diff --git a/ProjectLighthouse/Types/Settings/ServerStatics.cs b/ProjectLighthouse/Types/Settings/ServerStatics.cs index 1bb8227c..d5f94c12 100644 --- a/ProjectLighthouse/Types/Settings/ServerStatics.cs +++ b/ProjectLighthouse/Types/Settings/ServerStatics.cs @@ -10,13 +10,15 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings { public const string ServerName = "ProjectLighthouse"; - public static bool DbConnected { - get { + public static bool DbConnected + { + get + { try { return new Database().Database.CanConnect(); } - catch(Exception e) + catch (Exception e) { Logger.Log(e.ToString(), LoggerLevelDatabase.Instance); return false;