Removed discord id and discriminator. Fixed oauth2. Added data pending state

This commit is contained in:
Marcel Baumgartner 2023-03-24 17:50:29 +01:00
parent 49bf26350e
commit 922be4443d
13 changed files with 1125 additions and 28 deletions

View file

@ -1,11 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="EfCoreCommonOptions"> <component name="EfCoreCommonOptions">
<option name="migrationsToStartupProjects">
<map>
<entry key="16141d00-a997-4ba6-b0dc-af6f4712613a" value="16141d00-a997-4ba6-b0dc-af6f4712613a" />
</map>
</option>
<option name="solutionLevelOptions"> <option name="solutionLevelOptions">
<map> <map>
<entry key="migrationsProject" value="16141d00-a997-4ba6-b0dc-af6f4712613a" /> <entry key="migrationsProject" value="16141d00-a997-4ba6-b0dc-af6f4712613a" />
<entry key="startupProject" value="16141d00-a997-4ba6-b0dc-af6f4712613a" /> <entry key="startupProject" value="16141d00-a997-4ba6-b0dc-af6f4712613a" />
</map> </map>
</option> </option>
<option name="startupToMigrationsProjects">
<map>
<entry key="16141d00-a997-4ba6-b0dc-af6f4712613a" value="16141d00-a997-4ba6-b0dc-af6f4712613a" />
</map>
</option>
</component> </component>
</project> </project>

View file

@ -30,8 +30,6 @@ public class User
// Discord // Discord
public long DiscordId { get; set; } = -1; public long DiscordId { get; set; } = -1;
public string DiscordUsername { get; set; } = "";
public string DiscordDiscriminator { get; set; } = "";
// Date stuff // Date stuff
public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

View file

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Moonlight.App.Database.Migrations
{
/// <inheritdoc />
public partial class RemovedDiscordUsernameAndDiscriminator : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "DiscordDiscriminator",
table: "Users");
migrationBuilder.DropColumn(
name: "DiscordUsername",
table: "Users");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "DiscordDiscriminator",
table: "Users",
type: "longtext",
nullable: false)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "DiscordUsername",
table: "Users",
type: "longtext",
nullable: false)
.Annotation("MySql:CharSet", "utf8mb4");
}
}
}

View file

@ -723,17 +723,9 @@ namespace Moonlight.App.Database.Migrations
b.Property<DateTime>("CreatedAt") b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)"); .HasColumnType("datetime(6)");
b.Property<string>("DiscordDiscriminator")
.IsRequired()
.HasColumnType("longtext");
b.Property<long>("DiscordId") b.Property<long>("DiscordId")
.HasColumnType("bigint"); .HasColumnType("bigint");
b.Property<string>("DiscordUsername")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Email") b.Property<string>("Email")
.IsRequired() .IsRequired()
.HasColumnType("longtext"); .HasColumnType("longtext");

View file

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Moonlight.App.Exceptions; using Moonlight.App.Exceptions;
using Moonlight.App.Helpers; using Moonlight.App.Helpers;
using Moonlight.App.Models.Misc;
using Moonlight.App.Repositories; using Moonlight.App.Repositories;
using Moonlight.App.Services; using Moonlight.App.Services;
using Moonlight.App.Services.OAuth2; using Moonlight.App.Services.OAuth2;
@ -104,6 +105,14 @@ public class OAuth2Controller : Controller
userData.FirstName, userData.FirstName,
userData.LastName userData.LastName
); );
var newUser = UserRepository
.Get()
.First(x => x.Email == userData.Email);
newUser.Status = UserStatus.DataPending;
UserRepository.Update(newUser);
} }
else else
{ {

View file

@ -8,5 +8,6 @@ public enum UserStatus
VerifyFailed, VerifyFailed,
Warned, Warned,
Banned, Banned,
Disabled Disabled,
DataPending
} }

View file

@ -3,6 +3,7 @@ using Logging.Net;
using Moonlight.App.Database.Entities; using Moonlight.App.Database.Entities;
using Moonlight.App.Exceptions; using Moonlight.App.Exceptions;
using Moonlight.App.Models.Google.Requests; using Moonlight.App.Models.Google.Requests;
using Moonlight.App.Models.Misc;
using RestSharp; using RestSharp;
namespace Moonlight.App.Services.OAuth2; namespace Moonlight.App.Services.OAuth2;
@ -112,8 +113,10 @@ public class DiscordOAuth2Service
return new User() return new User()
{ {
Email = getData.GetValue<string>("email"), Email = getData.GetValue<string>("email"),
FirstName = getData.GetValue<string>("username"), FirstName = "User",
LastName = getData.GetValue<string>("discriminator") LastName = "User",
DiscordId = getData.GetValue<long>("id"),
Status = UserStatus.DataPending
}; };
} }

View file

@ -69,9 +69,7 @@ public class UserService
State = "", State = "",
Status = UserStatus.Unverified, Status = UserStatus.Unverified,
CreatedAt = DateTime.UtcNow, CreatedAt = DateTime.UtcNow,
DiscordDiscriminator = "",
DiscordId = -1, DiscordId = -1,
DiscordUsername = "",
TotpEnabled = false, TotpEnabled = false,
TotpSecret = "", TotpSecret = "",
UpdatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow,

View file

@ -134,18 +134,6 @@
</label> </label>
<input @bind="User.DiscordId" type="number" class="form-control"> <input @bind="User.DiscordId" type="number" class="form-control">
</div> </div>
<div class="mb-10">
<label class="form-label">
<TL>Discord username</TL>
</label>
<input @bind="User.DiscordUsername" type="text" class="form-control">
</div>
<div class="mb-10">
<label class="form-label">
<TL>Discord discriminator</TL>
</label>
<input @bind="User.DiscordDiscriminator" type="text" class="form-control">
</div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -186,7 +186,7 @@ else
<TL>Discord</TL> <TL>Discord</TL>
</label> </label>
<div class="col-lg-8"> <div class="col-lg-8">
<span class="fw-bold fs-6 text-gray-800">@(User.DiscordUsername)#@(User.DiscordDiscriminator)</span> <span class="fw-bold fs-6 text-gray-800">@* TODO: Implement discord fetching here *@</span>
</div> </div>
</div> </div>
<div class="separator my-4"></div> <div class="separator my-4"></div>