Add Authenticator

This commit is contained in:
milimoe 2023-10-16 20:56:01 +08:00
parent b923308be2
commit c3c153635f
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
3 changed files with 34 additions and 2 deletions

View File

@ -14,10 +14,10 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
public abstract string Script { get; set; } public abstract string Script { get; set; }
public abstract CommandType CommandType { get; set; } public abstract CommandType CommandType { get; set; }
public abstract SQLResult Result { get; } public abstract SQLResult Result { get; }
public abstract bool Success { get; }
public abstract SQLServerInfo ServerInfo { get; } public abstract SQLServerInfo ServerInfo { get; }
public abstract int UpdateRows { get; } public abstract int UpdateRows { get; }
public abstract DataSet DataSet { get; } public abstract DataSet DataSet { get; }
public bool Success => Result == SQLResult.Success;
/// <summary> /// <summary>
/// 执行一个命令 /// 执行一个命令

View File

@ -10,10 +10,10 @@ namespace Milimoe.FunGame.Core.Interface.Base
public string Script { get; set; } public string Script { get; set; }
public CommandType CommandType { get; set; } public CommandType CommandType { get; set; }
public SQLResult Result { get; } public SQLResult Result { get; }
public bool Success { get; }
public SQLServerInfo ServerInfo { get; } public SQLServerInfo ServerInfo { get; }
public int UpdateRows { get; } public int UpdateRows { get; }
public DataSet DataSet { get; } public DataSet DataSet { get; }
public bool Success { get; }
public int Execute(); public int Execute();
public DataSet ExecuteDataSet(); public DataSet ExecuteDataSet();

View File

@ -0,0 +1,32 @@
using System.Data;
using Milimoe.FunGame.Core.Api.Transmittal;
namespace Milimoe.FunGame.Core.Library.Common.Architecture
{
public abstract class Authenticator
{
private readonly SQLHelper SQLHelper;
public Authenticator(SQLHelper SQLHelper)
{
this.SQLHelper = SQLHelper;
}
public bool Authenticate<T>(string script, string column, T keyword)
{
SQLHelper.ExecuteDataSet(script);
if (SQLHelper.Success)
{
DataSet ds = SQLHelper.DataSet;
if (ds.Tables.Count > 0 &&
ds.Tables[0].Columns.Contains(column) &&
ds.Tables[0].Rows.Count > 0 &&
ds.Tables[0].AsEnumerable().Where(row => row.Field<T>(column)!.Equals(keyword)).Any())
{
return true;
}
}
return false;
}
}
}