finish migration to Pilz.NET
This commit is contained in:
@@ -3,31 +3,40 @@ using OwnChar.Data;
|
||||
using OwnChar.Data.Model.Base;
|
||||
using OwnChar.Server.Api;
|
||||
using OwnChar.Server.Data.Model;
|
||||
using Pilz.Net.Api;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace OwnChar.Server.Extensions;
|
||||
|
||||
public static class GeneralExtensions
|
||||
{
|
||||
public static bool CheckLogin(this IServer server, OwnCharRequest request, UserType userType)
|
||||
public static bool CheckLogin(this IOwnCharServer server, ApiRequestInfo 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
|
||||
|| !request.IsAuthenticated
|
||||
|| request.AuthKey.Split(":") is not string[] authKey
|
||||
|| authKey.ElementAtOrDefault(0) is not string username
|
||||
|| authKey.ElementAtOrDefault(1) is not string secret
|
||||
|| string.IsNullOrWhiteSpace(username)
|
||||
|| string.IsNullOrWhiteSpace(secret)
|
||||
|| !server.IsLoggedIn(secret)
|
||||
|| server.GetUser(secret) 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)
|
||||
public static bool CheckLogin(this IOwnCharServer server, ApiRequestInfo 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
|
||||
|| !request.IsAuthenticated
|
||||
|| request.AuthKey.Split(":") is not string[] authKey
|
||||
|| authKey.ElementAtOrDefault(0) is not string username
|
||||
|| authKey.ElementAtOrDefault(1) is not string secret
|
||||
|| string.IsNullOrWhiteSpace(username)
|
||||
|| string.IsNullOrWhiteSpace(secret)
|
||||
|| !server.IsLoggedIn(secret)
|
||||
|| server.GetUser(secret) is not UserAccountDb usr
|
||||
|| usr.Type < userType)
|
||||
{
|
||||
user = null;
|
||||
|
||||
Reference in New Issue
Block a user