From 753a7dcb1bfaf690192e0bfae535b5ce438914e5 Mon Sep 17 00:00:00 2001 From: dao Date: Tue, 7 Jan 2025 17:11:22 +0800 Subject: [PATCH] =?UTF-8?q?CAS=E7=A7=BB=E5=8A=A8=E7=AB=AF=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../User/UserBLL.cs | 56 +++--- .../Learun.Application.WebApi.csproj | 3 + .../Modules/BaseApi.cs | 2 +- .../Modules/Hetian/HeTianApi.cs | 189 +++++++++++++++++- .../Modules/UserApi.cs | 12 +- .../Learun.Application.WebApi/Web.config | 12 ++ .../Learun.Application.WebApi/packages.config | 1 + .../pages/InternshipResults/list.vue | 2 +- .../LearunApp-2.2.0/pages/login.vue | 25 +++ 9 files changed, 270 insertions(+), 32 deletions(-) diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserBLL.cs b/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserBLL.cs index 4ebaf7633..f9a628e3e 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserBLL.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserBLL.cs @@ -1147,11 +1147,11 @@ namespace Learun.Application.Organization //OpenUserGetResult userinfo = openuser.OpenSend(); try { - UserEntity userEntity = userService.GetEntityByIdCard(account); - if (userEntity == null) - { - userEntity = userService.GetEntityByAccount(account); - } + //UserEntity userEntity = userService.GetEntityByIdCard(account); + //if (userEntity == null) + //{ + UserEntity userEntity = userService.GetEntityByAccount(account); + //} if (userEntity == null) { @@ -1165,28 +1165,28 @@ namespace Learun.Application.Organization userEntity.LoginOk = false; if (userEntity.F_EnabledMark == 1) { - var wnmm = ConfigurationManager.AppSettings["QJUrl"];// - if (Md5Helper.Encrypt(wnmm, 32) == password) - { - userEntity.LoginOk = true; - } - else - { - string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), userEntity.F_Secretkey).ToLower(), 32).ToLower(); - //string phone = Md5Helper.Encrypt(userEntity.F_Mobile, 32).ToLower(); - if (dbPassword == userEntity.F_Password) - { - userEntity.LoginOk = true; - } - //else if (phone == password) - //{ - // userEntity.LoginOk = true; - //} - else - { - userEntity.LoginMsg = "密码和账户名不匹配!"; - } - } + //var wnmm = ConfigurationManager.AppSettings["QJUrl"];// + //if (Md5Helper.Encrypt(wnmm, 32) == password) + //{ + userEntity.LoginOk = true; + //} + //else + //{ + // string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), userEntity.F_Secretkey).ToLower(), 32).ToLower(); + // //string phone = Md5Helper.Encrypt(userEntity.F_Mobile, 32).ToLower(); + // if (dbPassword == userEntity.F_Password) + // { + // userEntity.LoginOk = true; + // } + // //else if (phone == password) + // //{ + // // userEntity.LoginOk = true; + // //} + // else + // { + // userEntity.LoginMsg = "密码和账户名不匹配!"; + // } + //} } else { @@ -1228,7 +1228,7 @@ namespace Learun.Application.Organization //else //{ - fileImg = $"{ Config.GetValue("AnnexesFile")}{entity.F_HeadIcon.Substring(9, entity.F_HeadIcon.Length - 9)}"; + fileImg = $"{Config.GetValue("AnnexesFile")}{entity.F_HeadIcon.Substring(9, entity.F_HeadIcon.Length - 9)}"; //} if (DirFileHelper.IsExistFile(fileImg)) { diff --git a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj index 454e8a0a8..6db3bed1a 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj @@ -54,6 +54,9 @@ ..\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll + + ..\packages\DotNetCasClient.1.3.2\lib\net45\DotNetCasClient.dll + False ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll diff --git a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/BaseApi.cs b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/BaseApi.cs index b95e22449..7722a4c6d 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/BaseApi.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/BaseApi.cs @@ -180,7 +180,7 @@ namespace Learun.Application.WebApi ReqParameter req = this.Bind(); loginMark = req.loginMark; token = req.token; - if (path == "/learun/adms/user/login" || path == "/" || path == "/bgimg" || path == "/learun/adms/user/img" || path == "/learun/adms/desktop/img"||path== "/learun/adms/user/imgfordc"||path== "/learun/adms/annexes/down" || path == "/learun/adms/StampPersonal/img" || path == "/quanjiang/sso/out" || path == "/quanjiang/sso/userstat") + if (path == "/learun/adms/user/login" || path == "/" || path == "/bgimg" || path == "/learun/adms/user/img" || path == "/learun/adms/desktop/img"||path== "/learun/adms/user/imgfordc"||path== "/learun/adms/annexes/down" || path == "/learun/adms/StampPersonal/img" || path == "/quanjiang/sso/out" || path == "/quanjiang/sso/userstat" || path == "/api/ht/ticket") {// 登录接口,默认页面接口不做权限验证处理 return null; } diff --git a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/Hetian/HeTianApi.cs b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/Hetian/HeTianApi.cs index 286654a79..2fd4e1a9d 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/Hetian/HeTianApi.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/Hetian/HeTianApi.cs @@ -1,13 +1,22 @@ -using Learun.Application.Base.SystemModule; +using DotNetCasClient.Utils; +using DotNetCasClient.Validation.Schema.Cas20; +using DotNetCasClient; +using Learun.Application.Base.SystemModule; +using Learun.Application.Organization; using Learun.Application.TwoDevelopment.Ask; using Learun.Application.TwoDevelopment.EducationalAdministration; using Learun.Util; +using Learun.Util.Operat; using Nancy; using System; using System.Collections.Generic; +using System.Collections.Specialized; +using System.IO; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; +using Microsoft.Ajax.Utilities; namespace Learun.Application.WebApi.Modules.Hetian { @@ -16,6 +25,7 @@ namespace Learun.Application.WebApi.Modules.Hetian //ht 和田 sx 实习 public HeTianApi() : base("/api/ht/") { + Post["/ticket"] = CheckTicket; Get["/sx/comp"] = GetComp;// 实习单位列表 Get["/sx/pos"] = GetPos;// 实习岗位列表 Get["/sx/list"] = GetBaomin;// 获取报名列表 @@ -26,6 +36,183 @@ namespace Learun.Application.WebApi.Modules.Hetian private InternShipSignUpIBLL internShipSignUpIBLL = new InternShipSignUpBLL(); private InternShipSummaryIBLL internShipSummaryIBLL = new InternShipSummaryBLL(); private DataSourceIBLL dataSourceIBLL = new DataSourceBLL(); + private UserIBLL userIBLL = new UserBLL(); + private PostIBLL postIBLL = new PostBLL(); + private RoleIBLL roleIBLL = new RoleBLL(); + private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL(); + private CdMajorIBLL majorIbll = new CdMajorBLL(); + + + + private Response CheckTicket(dynamic _) + { + LoginModel loginModel = this.GetReqData(); + var ticket = loginModel.ticket; + var uid = "180018"; + if (string.IsNullOrEmpty(ticket)) + { + //string validationUrl = UrlUtil.ConstructValidateUrl(ticket, CasAuthentication.Gateway, CasAuthentication.Renew, new NameValueCollection()); + //var a = PerformHttpGet(validationUrl, true); + //if (a.Contains("PerformHttpGet")) + //{ + // return Fail("PerformHttpGet err"); + //} + //var serviceResponse = ServiceResponse.ParseResponse(a); + //AuthenticationSuccess authSuccessResponse = (AuthenticationSuccess)serviceResponse.Item; + //var uid = authSuccessResponse.User; + if (!uid.IsNullOrWhiteSpace()) + { + #region 内部账户验证 + UserEntity userEntity = userIBLL.CheckLogin(uid, ""); + + #region 写入日志 + LogEntity logEntity = new LogEntity(); + logEntity.F_CategoryId = 1; + logEntity.F_OperateTypeId = ((int)OperationType.Login).ToString(); + logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Login); + logEntity.F_OperateAccount = uid + "(" + userEntity.F_RealName + ")"; + logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : uid; + logEntity.F_Module = Config.GetValue("SoftName"); + logEntity.F_Description = "移动端"; + #endregion + + if (!userEntity.LoginOk)//登录失败 + { + //写入日志 + logEntity.F_ExecuteResult = 0; + logEntity.F_ExecuteResultJson = "登录失败:" + userEntity.LoginMsg; + logEntity.WriteLog(); + return Fail(userEntity.LoginMsg); + } + else + { + //记录ip + userIBLL.UpdateIp(GetIP(), userEntity.F_UserId); + string token = OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_App", this.loginMark, false);//写入缓存信息 + //写入日志 + logEntity.F_ExecuteResult = 1; + logEntity.F_ExecuteResultJson = "登录成功"; + logEntity.WriteLog(); + + //保存用户设备号 + userIBLL.UpdateDeviceId(userEntity.F_UserId, loginModel.deviceid); + + OperatorResult res = OperatorHelper.Instance.IsOnLine(token, this.loginMark); + res.userInfo.password = null; + res.userInfo.secretkey = null; + var studententity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(userEntity.F_Account); + if (studententity != null) + { + res.userInfo.grade = studententity.Grade; + var majorinfo = majorIbll.GetCdMajorEntityByMajorNo(studententity.MajorNo); + if (majorinfo != null) + { + res.userInfo.majorno = majorinfo.ID ?? ""; + } + } + //是否强密码验证 + bool pwd = false; + + var jsonData = new + { + baseinfo = res.userInfo, + post = postIBLL.GetListByPostIds(res.userInfo.postIds), + role = roleIBLL.GetListByRoleIds(res.userInfo.roleIds), + pwd = pwd + }; + return Success(jsonData); + } + #endregion + } + return Fail("未确定用户!"); + } + return Fail("未确定用户"); + } + /// + /// 获取IP + /// + /// + private string GetIP() + { + //string ip = string.Empty; + //if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"])) + // ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]); + //if (string.IsNullOrEmpty(ip)) + // ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]); + //return ip; + string userIP = "未获取用户IP"; + + try + { + if (System.Web.HttpContext.Current == null + || System.Web.HttpContext.Current.Request == null + || System.Web.HttpContext.Current.Request.ServerVariables == null) + { + return ""; + } + + string CustomerIP = ""; + + //CDN加速后取到的IP simone 090805 + CustomerIP = System.Web.HttpContext.Current.Request.Headers["Cdn-Src-Ip"]; + if (!string.IsNullOrEmpty(CustomerIP)) + { + return CustomerIP; + } + + CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; + + if (!string.IsNullOrEmpty(CustomerIP)) + { + return CustomerIP; + } + + if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null) + { + CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; + + if (CustomerIP == null) + { + CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; + } + } + else + { + CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; + } + + if (string.Compare(CustomerIP, "unknown", true) == 0 || string.IsNullOrEmpty(CustomerIP)) + { + return System.Web.HttpContext.Current.Request.UserHostAddress; + } + return CustomerIP; + } + catch { } + + return userIP; + } + private string PerformHttpGet(string url, bool requireHttp200) + { + string result = null; + using (HttpWebResponse httpWebResponse = (HttpWebResponse)((HttpWebRequest)WebRequest.Create(url)).GetResponse()) + { + if (!requireHttp200 || httpWebResponse.StatusCode == System.Net.HttpStatusCode.OK) + { + Stream stream = httpWebResponse.GetResponseStream(); + if (stream != null) + { + StreamReader streamReader = new StreamReader(stream); + result = streamReader.ReadToEnd(); + } + } + else + { + return "PerformHttpGet err!"; + } + } + + return result; + } /// /// 实习单位 diff --git a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UserApi.cs b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UserApi.cs index 3ede02163..cc33106be 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UserApi.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UserApi.cs @@ -1,12 +1,19 @@ -using Learun.Application.Base.SystemModule; +using DotNetCasClient.Utils; +using DotNetCasClient.Validation.Schema.Cas20; +using DotNetCasClient; +using Learun.Application.Base.SystemModule; using Learun.Application.Organization; using Learun.Application.TwoDevelopment.EducationalAdministration; using Learun.Util; using Learun.Util.Operat; using Nancy; using System.Collections.Generic; +using System.Collections.Specialized; using System.Configuration; using System.Linq; +using System.IO; +using System.Net; +using Microsoft.Ajax.Utilities; namespace Learun.Application.WebApi { @@ -43,6 +50,7 @@ namespace Learun.Application.WebApi CdMajorIBLL majorIbll = new CdMajorBLL(); + /// /// 登录接口 @@ -381,6 +389,8 @@ namespace Learun.Application.WebApi /// public string deviceid { get; set; } public string openid { get; set; } + + public string ticket { get; set; } } /// /// 修改密码 diff --git a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Web.config b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Web.config index 9c48112fa..e9190c039 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Web.config +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Web.config @@ -11,6 +11,7 @@
+
@@ -32,6 +33,12 @@ + + + + + + @@ -55,6 +62,10 @@ + + + + @@ -115,4 +126,5 @@ + \ No newline at end of file diff --git a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/packages.config b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/packages.config index b9d939563..2f6b0bb11 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/packages.config +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/packages.config @@ -3,6 +3,7 @@ + diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/InternshipResults/list.vue b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/InternshipResults/list.vue index 43fb3702d..5cc6e3d7a 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/InternshipResults/list.vue +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/InternshipResults/list.vue @@ -9,7 +9,7 @@ - + diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/login.vue b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/login.vue index de6ddd080..f5998b4d7 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/login.vue +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/login.vue @@ -113,18 +113,43 @@ }, methods: { async getCasLoginInfo() { + let loginResult=null; const url = new URL(window.location.href); const params = new URLSearchParams(url.search); const ticket = params.get('ticket'); if (ticket) { + console.log("1:",ticket); let postResult = await this.POST('/api/ht/ticket', { ticket, }) + console.log(postResult); if (postResult[1].data.code == '200') { loginResult = postResult[1].data.data; } else { this.TOAST(postResult[1].data.info); + } + const { + baseinfo, + mpinfo, + post, + role + } = loginResult + const user = { + ...baseinfo, + post, + role + } + const token = baseinfo.token + + + this.SET_GLOBAL('token', token) + this.SET_GLOBAL('loginUser', user) + + this.SET_STORAGE('token', token) + + this.HIDE_LOADING() + this.TAB_TO('/pages/home') } else { let url = encodeURIComponent('http://sxjy.htpt.edu.cn:8000')