From 9fda6e11700ca797372a68e0c9b555642f57ca6d Mon Sep 17 00:00:00 2001 From: dyy <807692433@qq.com> Date: Fri, 5 Jul 2024 09:28:34 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91=E5=BF=98?= =?UTF-8?q?=E8=AE=B0=E5=AF=86=E7=A0=81=E3=80=81=E9=A6=96=E6=AC=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E3=80=81=E7=BB=91=E8=A7=A3=E5=BE=AE=E4=BF=A1=E3=80=81?= =?UTF-8?q?=E7=AD=89=E5=8F=91=E9=80=81=E7=9F=AD=E4=BF=A1=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../User/UserBLL.cs | 46 +++- .../User/UserEntity.cs | 5 + .../User/UserIBLL.cs | 11 + .../User/UserService.cs | 52 +++- .../Controllers/LoginController.cs | 230 ++++++++++++++++ .../Learun.Application.Web.csproj | 4 + .../Modules/BaseApi.cs | 2 +- .../Modules/UserApi.cs | 259 +++++++++++++++++- .../Modules/UsernologinApi.cs | 82 ++++-- .../Modules/WeixinApi.cs | 140 ++++++---- .../LearunApp-2.2.0/pages/firstLogin.vue | 7 +- .../LearunApp-2.2.0/pages/wxLogin.vue | 2 +- 12 files changed, 741 insertions(+), 99 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 8c1a24e1e..93b540432 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserBLL.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserBLL.cs @@ -497,7 +497,28 @@ namespace Learun.Application.Organization } } } - + /// + /// 记录已登录标记 + /// + /// + public void UpdateHaveLogMark(string id) + { + try + { + userService.UpdateHaveLogMark(id); + } + catch (Exception ex) + { + if (ex is ExceptionEx) + { + throw; + } + else + { + throw ExceptionEx.ThrowBusinessException(ex); + } + } + } /// /// 获取用户数据 /// @@ -1109,6 +1130,29 @@ namespace Learun.Application.Organization } } } + /// + /// 修改手机号 + /// + /// + /// + public void UpdateMobile(string keyValue, string mobile) + { + try + { + userService.UpdateMobile(keyValue, mobile); + } + catch (Exception ex) + { + if (ex is ExceptionEx) + { + throw; + } + else + { + throw ExceptionEx.ThrowBusinessException(ex); + } + } + } #endregion #region 验证数据 diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserEntity.cs b/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserEntity.cs index db38418f1..129796bf8 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserEntity.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserEntity.cs @@ -240,6 +240,11 @@ namespace Learun.Application.Organization /// [Column("F_MODIFYPWDDATE")] public DateTime? F_ModifyPwdDate { get; set; } + /// + /// 是否已登录标记 + /// + [Column("F_HAVELOGMARK")] + public bool? F_HaveLogMark { get; set; } #endregion #region 扩展操作 diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserIBLL.cs b/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserIBLL.cs index 67bd1a40f..e1a80f3b3 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserIBLL.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserIBLL.cs @@ -155,6 +155,12 @@ namespace Learun.Application.Organization /// 解绑微信 /// void DoUnbundWeiXin(string keyValue); + /// + /// 修改手机号 + /// + /// + /// + void UpdateMobile(string keyValue, string mobile); #endregion #region 验证数据 @@ -202,6 +208,11 @@ namespace Learun.Application.Organization IEnumerable GetAdminList(); void UpdateIp(string ip, string id); + /// + /// 记录已登录标记 + /// + /// + void UpdateHaveLogMark(string id); void GetImgForDC(string userId); UserEntity GetEntityByWeixinOpenIdPC(string openId); diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserService.cs b/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserService.cs index 06c9975d5..560ede52e 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserService.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserService.cs @@ -873,7 +873,35 @@ namespace Learun.Application.Organization } } } - + /// + /// 修改手机号 + /// + /// + /// + public void UpdateMobile(string keyValue, string mobile) + { + try + { + var userEntity = this.BaseRepository().FindEntity(keyValue); + if (userEntity != null) + { + userEntity.F_Mobile = mobile; + userEntity.Modify(keyValue); + this.BaseRepository().Update(userEntity); + } + } + catch (Exception ex) + { + if (ex is ExceptionEx) + { + throw; + } + else + { + throw ExceptionEx.ThrowServiceException(ex); + } + } + } public void UpdateIp(string ip, string id) { try @@ -892,6 +920,28 @@ namespace Learun.Application.Organization } } } + /// + /// 记录已登录标记 + /// + /// + public void UpdateHaveLogMark(string id) + { + try + { + this.BaseRepository().ExecuteBySql("update LR_Base_User set F_HaveLogMark=1 where F_UserId='" + id + "' "); + } + catch (Exception ex) + { + if (ex is ExceptionEx) + { + throw; + } + else + { + throw ExceptionEx.ThrowServiceException(ex); + } + } + } /// /// 获取用户头像,取empinfo照片 diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Controllers/LoginController.cs b/Learun.Framework.Ultimate V7/Learun.Application.Web/Controllers/LoginController.cs index db903e9bb..8aff12e21 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Controllers/LoginController.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Controllers/LoginController.cs @@ -18,6 +18,10 @@ using Quanjiang.DigitalScholl.WebLicense; using Learun.Application.TwoDevelopment.EducationalAdministration; using Newtonsoft.Json; using Learun.Application.OA.Email.EmailSend; +using System.Collections.Generic; +using Quanjiang.DigitalScholl.SendSms; +using Learun.Cache.Factory; +using Learun.Cache.Base; namespace Learun.Application.Web.Controllers { @@ -41,6 +45,8 @@ namespace Learun.Application.Web.Controllers WeChatDevelopIBLL weChatDevelopIbll = new WeChatDevelopBLL(); private Sys_DefaultPwdConfigIBLL Sys_DefaultPwdConfigIbll = new Sys_DefaultPwdConfigBLL(); private EmailSendIBLL emailSendIBLL = new EmailSendBLL(); + private readonly ISms yixintongSms = new YixintongSms(); + private ICache redisCache = CacheFactory.CaChe(); #endregion #region 视图功能 @@ -596,6 +602,8 @@ namespace Learun.Application.Web.Controllers } else { + //记录已登录标记 + userBll.UpdateHaveLogMark(userEntity.F_UserId); //记录ip userBll.UpdateIp(GetIP(), userEntity.F_UserId); OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_PC", null);//写入缓存信息 @@ -992,6 +1000,8 @@ namespace Learun.Application.Web.Controllers logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : userEntity.F_Account; logEntity.F_Module = Config.GetValue("SoftName"); logEntity.F_Description = "PC端微信登录"; + //记录已登录标记 + userBll.UpdateHaveLogMark(userEntity.F_UserId); //记录ip userBll.UpdateIp(GetIP(), userEntity.F_UserId); OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_PC", null);//写入缓存信息 @@ -1021,6 +1031,8 @@ namespace Learun.Application.Web.Controllers logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : userEntity.F_Account; logEntity.F_Module = Config.GetValue("SoftName"); logEntity.F_Description = "PC端微信登录"; + //记录已登录标记 + userBll.UpdateHaveLogMark(userEntity.F_UserId); //记录ip userBll.UpdateIp(GetIP(), userEntity.F_UserId); OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_PC", null);//写入缓存信息 @@ -1119,6 +1131,8 @@ namespace Learun.Application.Web.Controllers } //更新openid userBll.UpdateWeixinOpenIdPC(userEntity.F_UserId, WeixinOpenId); + //记录已登录标记 + userBll.UpdateHaveLogMark(userEntity.F_UserId); //记录ip userBll.UpdateIp(GetIP(), userEntity.F_UserId); OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_PC", null); //写入缓存信息 @@ -1165,6 +1179,8 @@ namespace Learun.Application.Web.Controllers { //更新openid userBll.UpdateWeixinOpenIdPC(userEntity.F_UserId, WeixinOpenId); + //记录已登录标记 + userBll.UpdateHaveLogMark(userEntity.F_UserId); //记录ip userBll.UpdateIp(GetIP(), userEntity.F_UserId); OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_PC", null); //写入缓存信息 @@ -1195,6 +1211,220 @@ namespace Learun.Application.Web.Controllers return Content(response); } + #endregion + + #region 短信发送、校验 + + /// + /// 忘记密码 + /// + /// + public ActionResult ForgotPassword() + { + return View(); + } + /// + /// 首次登录-手机号 + /// + /// + public ActionResult FirstLoginByMobile() + { + return View(); + } + /// + /// 发送短信验证码 + /// + /// 发送短信类型:忘记密码forgetpwd,首次登录firstlogin,绑定微信bindwx,解绑微信unbindwx,修改手机号modifymobile,; + /// 手机号 + /// + [HttpPost] + public ActionResult Sendcode(string codeType, string phone) + { + if (string.IsNullOrEmpty(codeType)) + { + return Fail("未指定短信类型。"); + } + UserEntity userEntity = null; + userEntity = userBll.GetEntityByMobile(phone); + if (userEntity == null) + { + return Fail("用户不存在!"); + } + if (string.IsNullOrEmpty(userEntity.F_Mobile)) + { + return Fail("用户手机号不存在!"); + } + if (codeType == "firstlogin" && userEntity.F_HaveLogMark == true) + { + return Fail("当前用户非首次登录,请使用账号密码进行登录!"); + } + //todo:待取消注释 + //string raRndNum = Learun.Util.CommonHelper.RndNum(6); + string raRndNum = "123456"; + var listStr = new List(); + var str1 = $"欢迎使用智慧校园,您本次登录的验证码是 " + raRndNum + "。"; + listStr.Add(str1); + //todo:待开发短信平台 + //var result = yixintongSms.SendSmsToSingle(userEntity.F_Mobile, SmsType.LoginBind, listStr); + //if (result.Result.code == "0") + if (true) + { + redisCache.Write("sendcodeinpc_" + codeType + "_" + userEntity.F_Mobile, raRndNum, new TimeSpan(0, 5, 0)); + //日志 + LogEntity logEntity = new LogEntity(); + logEntity.F_CategoryId = 3; + logEntity.F_SourceObjectId = codeType; + logEntity.F_OperateTypeId = "sms"; + logEntity.F_OperateType = "sms"; + logEntity.F_OperateAccount = "system"; + logEntity.F_ExecuteResult = 200; + logEntity.F_ExecuteResultJson = "短信发送成功:";// + result.Result.message; + logEntity.F_Description = "短信发送:" + userEntity.F_Mobile + " 验证码:" + raRndNum; + logEntity.WriteLog(); + return Success("短信发送成功:");// + result.Result.message); + } + else + { + LogEntity logEntity = new LogEntity(); + logEntity.F_CategoryId = 4; + logEntity.F_SourceObjectId = codeType; + logEntity.F_OperateTypeId = "sms"; + logEntity.F_OperateType = "sms"; + logEntity.F_OperateAccount = "system"; + logEntity.F_ExecuteResult = 400; + //logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType; + //logEntity.F_Description = "短信发送:" + userEntity.F_Mobile; + //logEntity.WriteLog(); + //return Fail("短信发送失败:" + result.Result.message + result.Result.errorType); + } + } + /// + /// 短信验证码校验 + /// + /// 发送短信类型 + /// 手机号 + /// 验证码 + /// + [HttpPost] + public ActionResult LoginCodeVerify(string codeType, string phone, string verifycode) + { + if (string.IsNullOrEmpty(codeType)) + { + return Fail("未指定短信类型。"); + } + if (string.IsNullOrEmpty(phone)) + { + return Fail("手机号不能为空。"); + } + var code = redisCache.Read("sendcodeinpc_" + codeType + "_" + phone); + if (!string.IsNullOrEmpty(code) && code == verifycode) + { + return Success("验证成功。"); + } + else + { + return Fail("验证失败,验证码错误或已失效。"); + } + + } + /// + /// 忘记密码:修改密码 + /// + /// + /// + /// + [HttpPost] + public ActionResult ForgotPasswordHandle(string phone, string newpassword) + { + UserEntity userEntity = userBll.GetEntityByMobile(phone); + if (userEntity == null) + { + return Fail("用户不存在"); + } + userBll.setPassword(userEntity.F_UserId, newpassword); + + return Success("密码修改成功"); + } + /// + /// 首次登录:手机号登录 + /// + /// 发送短信类型 + /// 手机号 + /// 验证码 + /// + [HttpPost] + public ActionResult LoginByMobile(string codeType, string phone, string verifycode) + { + //短信验证码校验 + if (string.IsNullOrEmpty(codeType)) + { + return Fail("未指定短信类型。"); + } + if (string.IsNullOrEmpty(phone)) + { + return Fail("手机号不能为空。"); + } + var code = redisCache.Read("sendcodeinpc_" + codeType + "_" + phone); + if (!string.IsNullOrEmpty(code) && code == verifycode) + { + //return Success("验证成功。"); + #region 内部账户验证 + UserEntity userEntity = userBll.GetEntityByMobile(phone); + if (userEntity == null) + { + return Fail("用户不存在!"); + } + if (userEntity.F_EnabledMark != 1) + { + return Fail("账户被系统锁定,请联系管理员!"); + } + userEntity.LoginOk = true; + #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 = userEntity.F_Account + "(" + userEntity.F_RealName + ")"; + logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : userEntity.F_Account; + logEntity.F_Module = Config.GetValue("SoftName"); + logEntity.F_Description = "PC端-首次登录"; + #endregion + + if (!userEntity.LoginOk)//登录失败 + { + //写入日志 + logEntity.F_ExecuteResult = 0; + logEntity.F_ExecuteResultJson = "登录失败:" + userEntity.LoginMsg; + logEntity.WriteLog(); + return Fail(userEntity.LoginMsg); + } + else + { + //记录已登录标记 + userBll.UpdateHaveLogMark(userEntity.F_UserId); + //记录ip + userBll.UpdateIp(GetIP(), userEntity.F_UserId); + OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_PC", null);//写入缓存信息 + //写入日志 + logEntity.F_ExecuteResult = 1; + logEntity.F_ExecuteResultJson = "登录成功"; + logEntity.WriteLog(); + //结果 + var succresult = new SuccResult() { + pwd = true + }; + + return Success(succresult); + } + #endregion + } + else + { + return Fail("验证失败,验证码错误或已失效。"); + } + } + + #endregion /// diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj b/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj index 2d2a9fa3e..6eb866aff 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj @@ -7196,6 +7196,10 @@ {1d192591-b85a-41db-ae3a-4bf9765786c1} Learun.Workflow.Engine + + {55f0f08d-2a9f-489a-be1b-2eeae80687e6} + Quanjiang.DigitalScholl.SendSms + {4D841EAD-3FD8-4FAC-BC67-C4CE6C0D1181} Quanjiang.DigitalScholl.WebLicense 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 e1b309863..3cdb3f9c5 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 == "/learun/adms/user/loginbyIdCard" || path == "/" || path == "/bgimg" || path == "/learun/adms/user/img" || path == "/learun/adms/desktop/img"||path== "/learun/adms/user/imgfordc" || path == "/quanjiang/sso/authorize") + if (path == "/learun/adms/user/login"|| path == "/learun/adms/user/loginbyIdCard" || path == "/" || path == "/bgimg" || path == "/learun/adms/user/img" || path == "/learun/adms/desktop/img"||path== "/learun/adms/user/imgfordc" || path == "/quanjiang/sso/authorize" || path == "/learun/adms/user/loginByMobile") {// 登录接口,默认页面接口不做权限验证处理 return null; } 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 b2ebb7033..ff30701b4 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UserApi.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UserApi.cs @@ -6,6 +6,7 @@ using Learun.Cache.Factory; using Learun.Util; using Learun.Util.Operat; using Nancy; +using System; using System.Collections.Generic; using System.Configuration; using System.Linq; @@ -29,10 +30,13 @@ namespace Learun.Application.WebApi { Post["/login"] = Login; Post["/logincodeverify"] = LoginCodeVerify; + Post["/sendcode"] = Sendcode; Post["/modifypw"] = ModifyPassword; Post["/modifypwiden"] = ModifyPasswordiden; Post["/unbundWeiXin"] = DoUnbundWeiXin; Post["/loginbyIdCard"] = LoginByIdCard; + Post["/updateMobile"] = UpdateMobile; + Post["/loginByMobile"] = LoginByMobile; Get["/info"] = Info; Get["/map"] = GetMap; @@ -51,14 +55,22 @@ namespace Learun.Application.WebApi /// - /// 登录二次短信验证 + /// 短信验证码校验 /// /// /// private Response LoginCodeVerify(dynamic _) { MobileVerify mobileVerify = this.GetReqData(); - var code = redisCache.Read("studentuserlogin_" + mobileVerify.mobile); + if (string.IsNullOrEmpty(mobileVerify.codeType)) + { + return Fail("未指定短信类型。"); + } + if (string.IsNullOrEmpty(mobileVerify.mobile)) + { + return Fail("手机号不能为空。"); + } + var code = redisCache.Read("sendcodeinapp_" + mobileVerify.codeType + "_" + mobileVerify.mobile); if (!string.IsNullOrEmpty(code) && code == mobileVerify.verifycode) { return Success("验证成功。"); @@ -69,6 +81,76 @@ namespace Learun.Application.WebApi } } + /// + /// 发送短信验证码 + /// + /// + /// + private Response Sendcode(dynamic _) + { + LoginModel loginModel = this.GetReqData(); + if (string.IsNullOrEmpty(loginModel.codeType)) + { + return Fail("未指定短信类型。"); + } + UserEntity userEntity = null; + userEntity = userIBLL.GetEntityByUserId(userInfo.userId); + if (userEntity == null) + { + return Fail("用户不存在!"); + } + if (loginModel.codeType == "unbindwx") + { + if (string.IsNullOrEmpty(userEntity.F_Mobile)) + { + return Fail("用户手机号不存在!"); + } + loginModel.username = userEntity.F_Mobile; + } + if (string.IsNullOrEmpty(loginModel.username)) + { + return Fail("手机号不能为空。"); + } + //todo:待取消注释 + //string raRndNum = Learun.Util.CommonHelper.RndNum(6); + string raRndNum = "123456"; + var listStr = new List(); + var str1 = $"欢迎使用智慧校园,您本次登录的验证码是 " + raRndNum + "。"; + listStr.Add(str1); + //todo:待开发短信平台 + //var result = yixintongSms.SendSmsToSingle(loginModel.username, SmsType.LoginBind, listStr); + //if (result.Result.code == "0") + if (true) + { + redisCache.Write("sendcodeinapp_" + loginModel.codeType + "_" + loginModel.username, raRndNum, new TimeSpan(0, 5, 0)); + //日志 + LogEntity logEntity = new LogEntity(); + logEntity.F_CategoryId = 3; + logEntity.F_SourceObjectId = loginModel.codeType; + logEntity.F_OperateTypeId = "sms"; + logEntity.F_OperateType = "sms"; + logEntity.F_OperateAccount = "system"; + logEntity.F_ExecuteResult = 200; + logEntity.F_ExecuteResultJson = "短信发送成功:";// + result.Result.message; + logEntity.F_Description = "短信发送:" + loginModel.username + " 验证码:" + raRndNum; + logEntity.WriteLog(); + return Success("短信发送成功:");// + result.Result.message); + } + else + { + LogEntity logEntity = new LogEntity(); + logEntity.F_CategoryId = 4; + logEntity.F_SourceObjectId = loginModel.codeType; + logEntity.F_OperateTypeId = "sms"; + logEntity.F_OperateType = "sms"; + logEntity.F_OperateAccount = "system"; + logEntity.F_ExecuteResult = 400; + //logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType; + //logEntity.F_Description = "短信发送:" + loginModel.username; + //logEntity.WriteLog(); + //return Fail("短信发送失败:" + result.Result.message + result.Result.errorType); + } + } /// /// 登录接口 @@ -103,6 +185,8 @@ namespace Learun.Application.WebApi } else { + //记录已登录标记 + userIBLL.UpdateHaveLogMark(userEntity.F_UserId); //记录ip userIBLL.UpdateIp(GetIP(), userEntity.F_UserId); string token = OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_App", this.loginMark, false);//写入缓存信息 @@ -138,7 +222,7 @@ namespace Learun.Application.WebApi baseinfo = res.userInfo, post = postIBLL.GetListByPostIds(res.userInfo.postIds), role = roleIBLL.GetListByRoleIds(res.userInfo.roleIds), - pwd= pwd + pwd = pwd }; return Success(jsonData); } @@ -180,11 +264,13 @@ namespace Learun.Application.WebApi { //新增新生判断 var stuinfobasic = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(userEntity.F_EnCode); - if (stuinfobasic!=null&&stuinfobasic.Grade!="22") + if (stuinfobasic != null && stuinfobasic.Grade != "22") { userEntity.LoginMsg = "只有新生支持身份证方式登录"; return Fail(userEntity.LoginMsg); } + //记录已登录标记 + userIBLL.UpdateHaveLogMark(userEntity.F_UserId); //记录ip userIBLL.UpdateIp(GetIP(), userEntity.F_UserId); string token = OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_App", this.loginMark, false);//写入缓存信息 @@ -227,6 +313,104 @@ namespace Learun.Application.WebApi #endregion } + /// + /// 登录接口-首次登录-手机号 + /// + /// + /// + private Response LoginByMobile(dynamic _) + { + LoginModel loginModel = this.GetReqData(); + //短信验证码校验 + if (string.IsNullOrEmpty(loginModel.codeType)) + { + return Fail("未指定短信类型。"); + } + if (string.IsNullOrEmpty(loginModel.username)) + { + return Fail("手机号不能为空。"); + } + var code = redisCache.Read("sendcodeinapp_" + loginModel.codeType + "_" + loginModel.username); + if (!string.IsNullOrEmpty(code) && code == loginModel.verifycode) + { + //return Success("验证成功。"); + #region 内部账户验证 + UserEntity userEntity = userIBLL.GetEntityByMobile(loginModel.username); + if (userEntity == null) + { + return Fail("用户不存在!"); + } + if (userEntity.F_EnabledMark != 1) + { + return Fail("账户被系统锁定,请联系管理员!"); + } + userEntity.LoginOk = true; + + #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 = loginModel.username + "(" + userEntity.F_RealName + ")"; + logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : loginModel.username; + 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 + { + //记录已登录标记 + userIBLL.UpdateHaveLogMark(userEntity.F_UserId); + //记录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 ?? ""; + } + } + var jsonData = new + { + baseinfo = res.userInfo, + post = postIBLL.GetListByPostIds(res.userInfo.postIds), + role = roleIBLL.GetListByRoleIds(res.userInfo.roleIds), + pwd = true + }; + return Success(jsonData); + } + #endregion + } + else + { + return Fail("验证失败,验证码错误或已失效。"); + } + + } + /// /// 获取用户信息 /// @@ -300,9 +484,58 @@ namespace Learun.Application.WebApi /// private Response DoUnbundWeiXin(dynamic _) { - userIBLL.DoUnbundWeiXin(userInfo.userId); - return Success("解绑成功"); - + MobileVerify mobileVerify = this.GetReqData(); + if (string.IsNullOrEmpty(mobileVerify.codeType)) + { + return Fail("未指定短信类型。"); + } + if (mobileVerify.codeType == "unbindwx") + { + mobileVerify.mobile = userIBLL.GetEntityByUserId(userInfo.userId)?.F_Mobile; + } + if (string.IsNullOrEmpty(mobileVerify.mobile)) + { + return Fail("手机号不能为空。"); + } + var code = redisCache.Read("sendcodeinapp_" + mobileVerify.codeType + "_" + mobileVerify.mobile); + if (!string.IsNullOrEmpty(code) && code == mobileVerify.verifycode) + { + //return Success("验证成功。"); + userIBLL.DoUnbundWeiXin(userInfo.userId); + return Success("解绑成功"); + } + else + { + return Fail("验证失败,验证码错误或已失效。"); + } + } + /// + /// 修改手机号 + /// + /// + /// + private Response UpdateMobile(dynamic _) + { + MobileVerify mobileVerify = this.GetReqData(); + if (string.IsNullOrEmpty(mobileVerify.codeType)) + { + return Fail("未指定短信类型。"); + } + if (string.IsNullOrEmpty(mobileVerify.mobile)) + { + return Fail("手机号不能为空。"); + } + var code = redisCache.Read("sendcodeinapp_" + mobileVerify.codeType + "_" + mobileVerify.mobile); + if (!string.IsNullOrEmpty(code) && code == mobileVerify.verifycode) + { + //return Success("验证成功。"); + userIBLL.UpdateMobile(userInfo.userId, mobileVerify.mobile); + return Success("修改成功"); + } + else + { + return Fail("验证失败,验证码错误或已失效。"); + } } /// /// 获取所有员工账号列表 @@ -509,6 +742,14 @@ namespace Learun.Application.WebApi /// public string deviceid { get; set; } public string openid { get; set; } + /// + /// 发送短信类型:忘记密码forgetpwd,首次登录firstlogin,绑定微信bindwx,解绑微信unbindwx,修改手机号modifymobile,; + /// + public string codeType { get; set; } + /// + /// 短信验证码 + /// + public string verifycode { get; set; } } /// /// 修改密码 @@ -530,6 +771,10 @@ namespace Learun.Application.WebApi { public string mobile { get; set; } public string verifycode { get; set; } + /// + /// 发送短信类型 + /// + public string codeType { get; set; } } diff --git a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UsernologinApi.cs b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UsernologinApi.cs index 5dce2653b..31e0a68e0 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UsernologinApi.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UsernologinApi.cs @@ -30,6 +30,7 @@ namespace Learun.Application.WebApi public UsernologinApi() : base("/learun/adms/usernologin") { + Post["/logincodeverify"] = LoginCodeVerify; Post["/sendcode"] = Sendcode; Post["/forgetpass"] = forgetpass; @@ -43,19 +44,27 @@ namespace Learun.Application.WebApi private readonly ISms yixintongSms = new YixintongSms(); private ICache redisCache = CacheFactory.CaChe(); private Sys_UpdateRecordIBLL sysUpdateRecordIbll = new Sys_UpdateRecordBLL(); - AnnexesFileIBLL annexesFileIbll=new AnnexesFileBLL(); + AnnexesFileIBLL annexesFileIbll = new AnnexesFileBLL(); /// - /// 登录二次短信验证 + /// 短信验证码校验 /// /// /// private Response LoginCodeVerify(dynamic _) { MobileVerify mobileVerify = this.GetReqData(); - var code = redisCache.Read("studentuserlogin_" + mobileVerify.mobile); + if (string.IsNullOrEmpty(mobileVerify.codeType)) + { + return Fail("未指定短信类型。"); + } + if (string.IsNullOrEmpty(mobileVerify.mobile)) + { + return Fail("手机号不能为空。"); + } + var code = redisCache.Read("sendcodeinapp_" + mobileVerify.codeType + "_" + mobileVerify.mobile); if (!string.IsNullOrEmpty(code) && code == mobileVerify.verifycode) { return Success("验证成功。"); @@ -67,65 +76,80 @@ namespace Learun.Application.WebApi } /// - /// 忘记密码,发送验证码 + /// 发送短信验证码 /// /// /// private Response Sendcode(dynamic _) { LoginModel loginModel = this.GetReqData(); - UserEntity userEntity = userIBLL.GetEntityByMobile(loginModel.username); + if (string.IsNullOrEmpty(loginModel.codeType)) + { + return Fail("未指定短信类型。"); + } + UserEntity userEntity = null; + if (loginModel.codeType == "bindwx") + { + userEntity = userIBLL.GetEntityByAccount(loginModel.username); + } + else + { + userEntity = userIBLL.GetEntityByMobile(loginModel.username); + } if (userEntity == null) { - return Fail("用户不存在"); + return Fail("用户不存在!"); } - #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 = loginModel.username + "(" + userEntity.F_RealName + ")"; - logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : loginModel.username; - logEntity.F_Module = Config.GetValue("SoftName"); - logEntity.F_Description = "移动端"; - #endregion - - string raRndNum = Learun.Util.CommonHelper.RndNum(6); + if (string.IsNullOrEmpty(userEntity.F_Mobile)) + { + return Fail("用户手机号不存在!"); + } + if (loginModel.codeType == "firstlogin" && userEntity.F_HaveLogMark == true) + { + return Fail("当前用户非首次登录,请使用账号密码进行登录!"); + } + //todo:待取消注释 + //string raRndNum = Learun.Util.CommonHelper.RndNum(6); + string raRndNum = "123456"; var listStr = new List(); var str1 = $"欢迎使用智慧校园,您本次登录的验证码是 " + raRndNum + "。"; listStr.Add(str1); - var result = yixintongSms.SendSmsToSingle(userEntity.F_Mobile, SmsType.LoginBind, listStr); - if (result.Result.code == "0") + //todo:待开发短信平台 + //var result = yixintongSms.SendSmsToSingle(userEntity.F_Mobile, SmsType.LoginBind, listStr); + //if (result.Result.code == "0") + if (true) { - redisCache.Write("studentuserlogin_" + userEntity.F_Mobile, raRndNum, new TimeSpan(0, 5, 0)); + redisCache.Write("sendcodeinapp_" + loginModel.codeType + "_" + userEntity.F_Mobile, raRndNum, new TimeSpan(0, 5, 0)); //日志 - logEntity = new LogEntity(); + LogEntity logEntity = new LogEntity(); logEntity.F_CategoryId = 3; + logEntity.F_SourceObjectId = loginModel.codeType; logEntity.F_OperateTypeId = "sms"; logEntity.F_OperateType = "sms"; logEntity.F_OperateAccount = "system"; logEntity.F_ExecuteResult = 200; logEntity.F_ExecuteResultJson = "短信发送成功:";// + result.Result.message; - logEntity.F_Description = "短信发送:" + userEntity.F_Mobile; + logEntity.F_Description = "短信发送:" + userEntity.F_Mobile + " 验证码:" + raRndNum; logEntity.WriteLog(); return Success("短信发送成功:");// + result.Result.message); } else { - logEntity = new LogEntity(); + LogEntity logEntity = new LogEntity(); logEntity.F_CategoryId = 4; + logEntity.F_SourceObjectId = loginModel.codeType; logEntity.F_OperateTypeId = "sms"; logEntity.F_OperateType = "sms"; logEntity.F_OperateAccount = "system"; logEntity.F_ExecuteResult = 400; - logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType; - logEntity.F_Description = "短信发送:" + userEntity.F_Mobile; - logEntity.WriteLog(); - return Fail("短信发送失败:" + result.Result.message + result.Result.errorType); + //logEntity.F_ExecuteResultJson = "短信发送失败:" + result.Result.message + result.Result.errorType; + //logEntity.F_Description = "短信发送:" + userEntity.F_Mobile; + //logEntity.WriteLog(); + //return Fail("短信发送失败:" + result.Result.message + result.Result.errorType); } } /// - /// 忘记密码修改密码 + /// 忘记密码:修改密码 /// /// /// diff --git a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/WeixinApi.cs b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/WeixinApi.cs index 2d3415a96..2d85ee51e 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/WeixinApi.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/WeixinApi.cs @@ -18,6 +18,8 @@ using Learun.Util.Operat; using Nancy.ModelBinding; using Nancy.Responses; using Newtonsoft.Json; +using Learun.Cache.Factory; +using Learun.Cache.Base; namespace Learun.Application.WebApi.Modules { @@ -30,6 +32,7 @@ namespace Learun.Application.WebApi.Modules private WeChatConfigIBLL weChatConfigIbll = new WeChatConfigBLL(); LR_Base_LogoIBLL baseLogoIbll = new LR_Base_LogoBLL(); CdMajorIBLL majorIbll = new CdMajorBLL(); + private ICache redisCache = CacheFactory.CaChe(); public WeixinApi() : base("/weixinapi") { @@ -183,71 +186,96 @@ namespace Learun.Application.WebApi.Modules { LoginModel loginModel = this.GetReqData(); - #region 内部账户验证 - UserEntity userEntity = userIbll.CheckLogin(loginModel.username, loginModel.password); - - #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 = loginModel.username + "(" + userEntity.F_RealName + ")"; - logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : loginModel.username; - logEntity.F_Module = Config.GetValue("SoftName"); - logEntity.F_Description = "移动端"; - #endregion - - if (!userEntity.LoginOk)//登录失败 + //短信验证码校验 + if (string.IsNullOrEmpty(loginModel.codeType)) { - //写入日志 - logEntity.F_ExecuteResult = 0; - logEntity.F_ExecuteResultJson = "登录失败:" + userEntity.LoginMsg; - logEntity.WriteLog(); - return Fail(userEntity.LoginMsg); + return Fail("未指定短信类型。"); } - else + var mobiletemp = string.Empty; + if (loginModel.codeType == "bindwx") { - ReqParameter req = this.Bind(); - string token = OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_App", req.loginMark, false);//写入缓存信息 - //写入日志 - logEntity.F_ExecuteResult = 1; - logEntity.F_ExecuteResultJson = "登录成功"; - logEntity.WriteLog(); - OperatorResult res = OperatorHelper.Instance.IsOnLine(token, req.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 ?? ""; - } + mobiletemp = userIbll.GetEntityByAccount(loginModel.username)?.F_Mobile; + } + if (string.IsNullOrEmpty(mobiletemp)) + { + return Fail("手机号不能为空。"); + } + var code = redisCache.Read("sendcodeinapp_" + loginModel.codeType + "_" + mobiletemp); + if (!string.IsNullOrEmpty(code) && code == loginModel.verifycode) + { + //return Success("验证成功。"); + #region 内部账户验证 + UserEntity userEntity = userIbll.CheckLogin(loginModel.username, loginModel.password); - } - //是否强密码验证 - bool pwd = false; - if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["verifypwd"]) && ConfigurationManager.AppSettings["verifypwd"] == "true" && loginModel.up == false) + #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 = loginModel.username + "(" + userEntity.F_RealName + ")"; + logEntity.F_OperateUserId = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : loginModel.username; + logEntity.F_Module = Config.GetValue("SoftName"); + logEntity.F_Description = "移动端"; + #endregion + + if (!userEntity.LoginOk)//登录失败 { - pwd = true; + //写入日志 + logEntity.F_ExecuteResult = 0; + logEntity.F_ExecuteResultJson = "登录失败:" + userEntity.LoginMsg; + logEntity.WriteLog(); + return Fail(userEntity.LoginMsg); } else { - //保存用户设备号 - userIbll.UpdateWeixinOpenId(userEntity.F_UserId, loginModel.openid); + //记录已登录标记 + userIbll.UpdateHaveLogMark(userEntity.F_UserId); + ReqParameter req = this.Bind(); + string token = OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_App", req.loginMark, false);//写入缓存信息 + //写入日志 + logEntity.F_ExecuteResult = 1; + logEntity.F_ExecuteResultJson = "登录成功"; + logEntity.WriteLog(); + OperatorResult res = OperatorHelper.Instance.IsOnLine(token, req.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; + if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["verifypwd"]) && ConfigurationManager.AppSettings["verifypwd"] == "true" && loginModel.up == false) + { + pwd = true; + } + else + { + //保存用户设备号 + userIbll.UpdateWeixinOpenId(userEntity.F_UserId, loginModel.openid); + } + var jsonData = new + { + baseinfo = res.userInfo, + post = postIBLL.GetListByPostIds(res.userInfo.postIds), + role = roleIBLL.GetListByRoleIds(res.userInfo.roleIds), + pwd = pwd + }; + return Success(jsonData); } - var jsonData = new - { - baseinfo = res.userInfo, - post = postIBLL.GetListByPostIds(res.userInfo.postIds), - role = roleIBLL.GetListByRoleIds(res.userInfo.roleIds), - pwd = pwd - }; - return Success(jsonData); + #endregion + } + else + { + return Fail("验证失败,验证码错误或已失效。"); } - #endregion } private Response LoginByIdCard(dynamic _) @@ -278,6 +306,8 @@ namespace Learun.Application.WebApi.Modules } else { + //记录已登录标记 + userIbll.UpdateHaveLogMark(userEntity.F_UserId); ReqParameter req = this.Bind(); string token = OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "Learun_ADMS_6.1_App", req.loginMark, false);//写入缓存信息 //写入日志 diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/firstLogin.vue b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/firstLogin.vue index 562326ec8..05d7c4c2a 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/firstLogin.vue +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/firstLogin.vue @@ -3,9 +3,9 @@ - 数字化智慧校园 + 首次登录 - {{ APP_VERSION }} + @@ -28,7 +28,6 @@ 登 录 - 常规登录 @@ -121,7 +120,7 @@ export default{ if (success.pwd === true) { this.SET_STORAGE('pwd', true); - this.TOAST("绑定失败!您的密码不满足强度要求,请您先修改密码后再执行系统其他操作"); + this.TOAST("您的密码不满足强度要求,请您先修改密码后再执行系统其他操作"); } setTimeout(()=>{ location.href = "http://" + window.location.host + "/#/pages/my/newpassword"; diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/wxLogin.vue b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/wxLogin.vue index 8d53300e5..4df76bbcd 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/wxLogin.vue +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/wxLogin.vue @@ -44,7 +44,7 @@ 确 认 - 常规登陆 + 常规登录