From e82b3c3ccf944764496668fbb8c1c265e17c3b30 Mon Sep 17 00:00:00 2001 From: iyak Date: Mon, 14 Apr 2025 04:24:33 +0000 Subject: [PATCH] =?UTF-8?q?=EB=A9=94=EB=89=B4=20=EC=A0=91=EC=86=8D?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=20=EB=A1=9C=EC=A7=81=20=EA=B0=9C=EC=84=A0=20?= =?UTF-8?q?=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9CTask=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Base/Filter/AuthFilter.cs | 44 ++++++++++++++++++----------- Dao/CommonDao.cs | 58 ++++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 48 deletions(-) diff --git a/Base/Filter/AuthFilter.cs b/Base/Filter/AuthFilter.cs index 2a654ed..290fa59 100644 --- a/Base/Filter/AuthFilter.cs +++ b/Base/Filter/AuthFilter.cs @@ -13,33 +13,46 @@ namespace NP.Base.Auth { public EMRole[] Roles { get; set; } BaseController _base; + public bool IsFront { get; set; } public override void OnActionExecuting(ActionExecutingContext context) { Controller currentControll = context.Controller as Controller; _base = currentControll as BaseController; - //if (_base.SUserInfo.UserNo > 0 && Array.Exists(Roles, el => el == GetEMRole(_base.SUserInfo.UserType))) + if (!IsFront) { - var cm = _base.GetMENUS.Where(w => w.usertype == _base.SUserInfo.UserType && w.menuurl.Equals(context.HttpContext.Request.Url.AbsolutePath)).OrderByDescending(od => od.menulevel).FirstOrDefault(); - if (cm != null - || (_base.SUserInfo.UserNo > 0 && (context.HttpContext.Request.Url.AbsolutePath.Equals("/Home/Index/") - || context.HttpContext.Request.Url.AbsolutePath.Equals("/Home/Index") - || context.HttpContext.Request.Url.AbsolutePath.Equals("/Home/") - || context.HttpContext.Request.Url.AbsolutePath.Equals("/Home") - || context.HttpContext.Request.Url.AbsolutePath.Equals("/")))) + var cm = _base.GetMENUS + .Where(w => w.usertype == _base.SUserInfo.UserType && w.menuurl.Equals(context.HttpContext.Request.Url.AbsolutePath)) + .OrderByDescending(od => od.menulevel) + .FirstOrDefault(); + + var absolutePath = context.HttpContext.Request.Url.AbsolutePath.ToLower(); + + if (cm != null || (_base.SUserInfo.UserNo > 0 && (absolutePath == "/" || absolutePath.StartsWith("/home")))) { _base.ViewBag.Title = (cm ?? new Model.Menu()).menuname ?? "Home"; _base.ViewBag.CMenu = cm; _base.ViewBag.CMenuNo = (cm ?? new Model.Menu()).menuno; _base.ViewBag.CHidden = (cm ?? new Model.Menu()).ishid; + var pmenu = (_base.GetMENUS.Where(w => w.menuno == (cm ?? new Model.Menu()).pmenuno).FirstOrDefault() ?? new Model.Menu()); _base.ViewBag.pmenuno = pmenu.ishid == 1 ? pmenu.pmenuno : pmenu.menuno; _base.ViewBag.pmenunos = (cm ?? new Model.Menu()).menurout; - //접속로그 - var rtn = System.Threading.Tasks.Task.Run(async() => Console.WriteLine(await _base.Dao.Log( - new NP.Model.PageLog() { uno = _base.SUserInfo.UserNo, uip = _base.GetUserIP(), logsite = 0, menuno = _base.ViewBag.CMenuNo < 1 ? (int?)null : _base.ViewBag.CMenuNo, loginfo = _base.ViewBag.Title }))); + + // 접속로그 (2025-04-14 HS: 불필요한 2중 Task제거 후 await 구문으로 변경) + var rtn = System.Threading.Tasks.Task.Run(async () => await _base.Dao.Log( + new Model.PageLog() + { + uno = _base.SUserInfo.UserNo, + uip = _base.GetUserIP(), + logsite = 0, + menuno = _base.ViewBag.CMenuNo < 1 ? (int?)null : _base.ViewBag.CMenuNo, + loginfo = _base.ViewBag.Title + }) + ); + base.OnActionExecuting(context); } else @@ -65,13 +78,12 @@ namespace NP.Base.Auth { switch (userType) { - case 99: - return EMRole.Admin; - case 1: - return EMRole.Student; + case 99: return EMRole.Admin; + case 1: return EMRole.Student; } + return EMRole.Anonymous; } } -} +} \ No newline at end of file diff --git a/Dao/CommonDao.cs b/Dao/CommonDao.cs index 8415930..d370566 100644 --- a/Dao/CommonDao.cs +++ b/Dao/CommonDao.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using NP.Model; using System.Collections; using NP.Dao.MyBatis; +using MySql.Data.MySqlClient; namespace NP.Dao { public partial class CommonDao : BaseDao @@ -267,51 +268,44 @@ namespace NP.Dao } return 0; } + + /// + /// 접속로그 등록 + /// + /// + /// public async Task Log(PageLog log) { int rtn = 0; - using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(NP.Frame.DaoFactory.Instance.DataSource.ConnectionString)) + + using (var conn = new MySqlConnection(Frame.DaoFactory.Instance.DataSource.ConnectionString)) { try { - //int count = 0; - MySql.Data.MySqlClient.MySqlCommand command = new MySql.Data.MySqlClient.MySqlCommand("insert into pagelog(logsite,userno,menuno,pno,loginfo,cdt,cno,udt,uno,uip)values(" + log.logsite + "," + log.uno + "," + (log.menuno == null ? "null" : log.menuno.ToString()) + "," + (log.pno == null ? "null" : log.pno.ToString()) + ",'" + (log.loginfo ?? "") + "',now()," + log.uno + ",now()," + log.uno + ",'" + log.uip + "')", conn); - command.CommandType = System.Data.CommandType.Text; - conn.Open(); - //conn.OpenAsync(); - //command.ExecuteNonQuery(); - rtn = (int) await command.ExecuteNonQueryAsync(); - //IAsyncResult result = command.BeginExecuteNonQuery(new AsyncCallback(logcompleted), command); - //IAsyncResult result = command.BeginExecuteNonQuery(); - //while (!result.IsCompleted) - //{ - // Console.WriteLine("Waiting ({0})", count++); - // // Wait for 1/10 second, so the counter - // // does not consume all available resources - // // on the main thread. - // System.Threading.Thread.Sleep(100); - //} - //Console.WriteLine("Command complete. Affected {0} rows.", - // command.EndExecuteNonQuery(result)); - //command.EndExecuteNonQuery(result); - } - catch (MySql.Data.MySqlClient.MySqlException ex) - { - //Console.WriteLine("Error ({0}): {1}", ex.Number, ex.Message); - } - catch (InvalidOperationException ex) - { - //Console.WriteLine("Error: {0}", ex.Message); + await conn.OpenAsync(); + using (var command = new MySqlCommand("insert into pagelog(logsite, userno, menuno, pno, loginfo, cdt, cno, udt, uno, uip) values (@logsite, @uno, @menuno, @pno, @loginfo, now(), @uno, now(), @uno, @uip)", conn)) + { + command.Parameters.AddWithValue("@logsite", log.logsite); + command.Parameters.AddWithValue("@uno", log.uno); + command.Parameters.AddWithValue("@menuno", log.menuno ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@pno", log.pno ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@loginfo", log.loginfo ?? ""); + command.Parameters.AddWithValue("@uip", log.uip); + + rtn = await command.ExecuteNonQueryAsync(); + } } catch (Exception ex) { - // You might want to pass these errors - // back out to the caller. - //Console.WriteLine("Error: {0}", ex.Message); + Console.WriteLine(ex.Message); } } + return rtn; } + + + public int SavePay(Pay p, bool inlect, bool inlectsedate = false) { Trans();