uff, lot of work
This commit is contained in:
39
OwnChar.Server/Extensions/GeneralExtensions.cs
Normal file
39
OwnChar.Server/Extensions/GeneralExtensions.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using OwnChar.Api.Packets;
|
||||
using OwnChar.Data;
|
||||
using OwnChar.Data.Model.Base;
|
||||
using OwnChar.Server.Api;
|
||||
using OwnChar.Server.Data.Model;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace OwnChar.Server.Extensions;
|
||||
|
||||
public static class GeneralExtensions
|
||||
{
|
||||
public static bool CheckLogin(this IServer server, OwnCharRequest request, UserType userType)
|
||||
{
|
||||
if (server.Data is null
|
||||
|| string.IsNullOrWhiteSpace(request.Username)
|
||||
|| string.IsNullOrWhiteSpace(request.AuthSecret)
|
||||
|| !server.IsLoggedIn(request.AuthSecret)
|
||||
|| server.GetUser(request.AuthSecret) is not UserAccountBase usr
|
||||
|| usr.Type < userType)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CheckLogin(this IServer server, OwnCharRequest request, UserType userType, [NotNullWhen(true)] out UserAccountDb? user)
|
||||
{
|
||||
if (server.Data is null
|
||||
|| string.IsNullOrWhiteSpace(request.Username)
|
||||
|| string.IsNullOrWhiteSpace(request.AuthSecret)
|
||||
|| !server.IsLoggedIn(request.AuthSecret)
|
||||
|| server.GetUser(request.AuthSecret) is not UserAccountDb usr
|
||||
|| usr.Type < userType)
|
||||
{
|
||||
user = null;
|
||||
return false;
|
||||
}
|
||||
user = usr;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
48
OwnChar.Server/Extensions/ModelExtensions.cs
Normal file
48
OwnChar.Server/Extensions/ModelExtensions.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using OwnChar.Data.Model.Client;
|
||||
using OwnChar.Server.Data.Model;
|
||||
|
||||
namespace OwnChar.Server.Extensions;
|
||||
|
||||
public static class ModelExtensions
|
||||
{
|
||||
public static Group ToClient(this GroupDb @this)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Id = @this.Id,
|
||||
Name = @this.Name,
|
||||
Fandom = @this.Fandom,
|
||||
IsInternal = @this.IsInternal,
|
||||
};
|
||||
}
|
||||
|
||||
public static UserAccount ToClient(this UserAccountDb @this)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Id = @this.Id,
|
||||
Email = @this.Email,
|
||||
Type = @this.Type,
|
||||
Username = @this.Username,
|
||||
};
|
||||
}
|
||||
|
||||
public static UserProfile ToClient(this UserProfileDb @this)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Id = @this.Id,
|
||||
Name = @this.Name,
|
||||
};
|
||||
}
|
||||
|
||||
public static MemberEntry ToClient(this MemberEntryDb @this)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Id = @this.Id,
|
||||
UserProfileId = @this.User!.Id,
|
||||
Level = @this.Level,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user