添加AuthenticationType和传入参数

This commit is contained in:
milimoe 2023-10-17 21:44:34 +08:00
parent 0014ad4b33
commit c4ed012141
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
2 changed files with 17 additions and 8 deletions

View File

@ -1,5 +1,6 @@
using System.Data; using System.Data;
using Milimoe.FunGame.Core.Api.Transmittal; using Milimoe.FunGame.Core.Api.Transmittal;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Library.SQLScript.Entity; using Milimoe.FunGame.Core.Library.SQLScript.Entity;
namespace Milimoe.FunGame.Core.Library.Common.Architecture namespace Milimoe.FunGame.Core.Library.Common.Architecture
@ -13,13 +14,13 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
this.SQLHelper = SQLHelper; this.SQLHelper = SQLHelper;
} }
public abstract bool BeforeAuthenticator(); public abstract bool BeforeAuthenticator(AuthenticationType type, params object[] args);
public abstract bool AfterAuthenticator(); public abstract bool AfterAuthenticator(AuthenticationType type, params object[] args);
public bool Authenticate(string script) public bool Authenticate(string script)
{ {
if (!BeforeAuthenticator()) return false; if (!BeforeAuthenticator(AuthenticationType.ScriptOnly, script)) return false;
SQLHelper.ExecuteDataSet(script); SQLHelper.ExecuteDataSet(script);
if (SQLHelper.Success) if (SQLHelper.Success)
{ {
@ -27,7 +28,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
if (ds.Tables.Count > 0 && if (ds.Tables.Count > 0 &&
ds.Tables[0].Rows.Count > 0) ds.Tables[0].Rows.Count > 0)
{ {
if (!AfterAuthenticator()) return false; if (!AfterAuthenticator(AuthenticationType.ScriptOnly, script)) return false;
return true; return true;
} }
} }
@ -36,7 +37,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
public bool Authenticate<T>(string script, string column, T keyword) public bool Authenticate<T>(string script, string column, T keyword)
{ {
if (!BeforeAuthenticator()) return false; if (!BeforeAuthenticator(AuthenticationType.Column, script, column)) return false;
SQLHelper.ExecuteDataSet(script); SQLHelper.ExecuteDataSet(script);
if (SQLHelper.Success) if (SQLHelper.Success)
{ {
@ -46,7 +47,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows.Count > 0 &&
ds.Tables[0].AsEnumerable().Where(row => row.Field<T>(column)!.Equals(keyword)).Any()) ds.Tables[0].AsEnumerable().Where(row => row.Field<T>(column)!.Equals(keyword)).Any())
{ {
if (!AfterAuthenticator()) return false; if (!AfterAuthenticator(AuthenticationType.Column, script, column)) return false;
return true; return true;
} }
} }
@ -55,7 +56,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
public bool Authenticate(string username, string password) public bool Authenticate(string username, string password)
{ {
if (!BeforeAuthenticator()) return false; if (!BeforeAuthenticator(AuthenticationType.Username, username, password)) return false;
SQLHelper.ExecuteDataSet(UserQuery.Select_Users_LoginQuery(username, password)); SQLHelper.ExecuteDataSet(UserQuery.Select_Users_LoginQuery(username, password));
if (SQLHelper.Success) if (SQLHelper.Success)
{ {
@ -65,7 +66,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
ds.Tables[0].Columns.Contains(UserQuery.Column_Password) && ds.Tables[0].Columns.Contains(UserQuery.Column_Password) &&
ds.Tables[0].Rows.Count > 0) ds.Tables[0].Rows.Count > 0)
{ {
if (!AfterAuthenticator()) return false; if (!AfterAuthenticator(AuthenticationType.Username, username, password)) return false;
return true; return true;
} }
} }

View File

@ -293,4 +293,12 @@ namespace Milimoe.FunGame.Core.Library.Constant
DuplicateEmail, DuplicateEmail,
InputVerifyCode InputVerifyCode
} }
public enum AuthenticationType
{
None,
ScriptOnly,
Column,
Username
}
} }