添加before&after

This commit is contained in:
milimoe 2023-10-17 20:31:32 +08:00
parent 6876430f7a
commit 0b272dd6b8
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E

View File

@ -1,5 +1,4 @@
using System.Data; using System.Data;
using System.Data.Common;
using Milimoe.FunGame.Core.Api.Transmittal; using Milimoe.FunGame.Core.Api.Transmittal;
using Milimoe.FunGame.Core.Library.SQLScript.Entity; using Milimoe.FunGame.Core.Library.SQLScript.Entity;
@ -14,8 +13,13 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
this.SQLHelper = SQLHelper; this.SQLHelper = SQLHelper;
} }
public abstract bool BeforeAuthenticator();
public abstract bool AfterAuthenticator();
public bool Authenticate(string script) public bool Authenticate(string script)
{ {
if (!BeforeAuthenticator()) return false;
SQLHelper.ExecuteDataSet(script); SQLHelper.ExecuteDataSet(script);
if (SQLHelper.Success) if (SQLHelper.Success)
{ {
@ -23,6 +27,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;
return true; return true;
} }
} }
@ -31,6 +36,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;
SQLHelper.ExecuteDataSet(script); SQLHelper.ExecuteDataSet(script);
if (SQLHelper.Success) if (SQLHelper.Success)
{ {
@ -40,24 +46,26 @@ 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;
return true; return true;
} }
} }
return false; return false;
} }
public bool Authenticate(string script, string username, string password) public bool Authenticate(string username, string password)
{ {
SQLHelper.ExecuteDataSet(script); if (!BeforeAuthenticator()) return false;
SQLHelper.ExecuteDataSet(UserQuery.Select_Users_LoginQuery(username, password));
if (SQLHelper.Success) if (SQLHelper.Success)
{ {
DataSet ds = SQLHelper.DataSet; DataSet ds = SQLHelper.DataSet;
if (ds.Tables.Count > 0 && if (ds.Tables.Count > 0 &&
ds.Tables[0].Columns.Contains(UserQuery.Column_Username) && ds.Tables[0].Columns.Contains(UserQuery.Column_Username) &&
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)
ds.Tables[0].AsEnumerable().Where(row => (string)row[UserQuery.Column_Username] == username && (string)row[UserQuery.Column_Password] == password).Any())
{ {
if (!AfterAuthenticator()) return false;
return true; return true;
} }
} }