Merge branch 'DiscordBot' of https://github.com/Moonlight-Panel/Moonlight into DiscordBot

This commit is contained in:
Spielepapagei 2023-03-24 17:54:43 +01:00
commit 7f4f507870
13 changed files with 1125 additions and 28 deletions

View file

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

View file

@ -30,8 +30,6 @@ public class User
// Discord
public long DiscordId { get; set; } = -1;
public string DiscordUsername { get; set; } = "";
public string DiscordDiscriminator { get; set; } = "";
// Date stuff
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")
.HasColumnType("datetime(6)");
b.Property<string>("DiscordDiscriminator")
.IsRequired()
.HasColumnType("longtext");
b.Property<long>("DiscordId")
.HasColumnType("bigint");
b.Property<string>("DiscordUsername")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("longtext");

View file

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

View file

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

View file

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

View file

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

View file

@ -134,18 +134,6 @@
</label>
<input @bind="User.DiscordId" type="number" class="form-control">
</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>

View file

@ -186,7 +186,7 @@ else
<TL>Discord</TL>
</label>
<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 class="separator my-4"></div>