From 8461615f4d30eabc27f676f09c8d3b604870624c Mon Sep 17 00:00:00 2001 From: dyy <807692433@qq.com> Date: Tue, 30 Jul 2024 16:56:39 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91=E5=BF=98?= =?UTF-8?q?=E8=AE=B0=E5=AF=86=E7=A0=81=E3=80=81=E4=BF=AE=E6=94=B9=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7=E5=8A=9F=E8=83=BD=E5=A2=9E=E5=8A=A0=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../User/UserBLL.cs | 44 +++++ .../User/UserEntity.cs | 5 + .../User/UserIBLL.cs | 8 + .../User/UserService.cs | 55 ++++++ .../Controllers/LoginController.cs | 119 ++++++++++++ .../Learun.Application.Web.csproj | 6 + .../Views/Login/Default.cshtml | 2 + .../Views/Login/ForgotPassword.cshtml | 149 +++++++++++++++ .../Views/Login/ForgotPassword.js | 179 ++++++++++++++++++ .../Learun.Application.WebApi.csproj | 5 + .../Modules/UserApi.cs | 149 +++++++++++++++ .../Modules/UsernologinApi.cs | 168 ++++++++++++++++ .../Learun.Util/Common/CommonHelper.cs | 15 ++ .../LearunApp-2.2.0/pages.json | 14 ++ .../LearunApp-2.2.0/pages/forgotPassword.vue | 150 +++++++++++++++ .../LearunApp-2.2.0/pages/login.vue | 15 +- .../LearunApp-2.2.0/pages/my.vue | 4 + .../LearunApp-2.2.0/pages/my/changePhone.vue | 121 ++++++++++++ 18 files changed, 1207 insertions(+), 1 deletion(-) create mode 100644 Learun.Framework.Ultimate V7/Learun.Application.Web/Views/Login/ForgotPassword.cshtml create mode 100644 Learun.Framework.Ultimate V7/Learun.Application.Web/Views/Login/ForgotPassword.js create mode 100644 Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/UsernologinApi.cs create mode 100644 Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/forgotPassword.vue create mode 100644 Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/my/changePhone.vue 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 919e1c0b1..cfaaacd13 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserBLL.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserBLL.cs @@ -382,6 +382,27 @@ namespace Learun.Application.Organization } } } + + public UserEntity GetEntityByMobile(string mobile) + { + try + { + UserEntity userEntity; + userEntity = userService.GetEntityByMobile(mobile); + return userEntity; + } + catch (Exception ex) + { + if (ex is ExceptionEx) + { + throw; + } + else + { + throw ExceptionEx.ThrowBusinessException(ex); + } + } + } /// /// 获取实体,通过用户账号 /// @@ -1060,6 +1081,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 cabee8b6f..5fe15ea00 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserIBLL.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserIBLL.cs @@ -69,6 +69,8 @@ namespace Learun.Application.Organization /// /// void GetExportListOfStudent(); + + UserEntity GetEntityByMobile(string mobile); /// /// 获取实体,通过用户账号 /// @@ -153,6 +155,12 @@ namespace Learun.Application.Organization /// 解绑微信 /// void DoUnbundWeiXin(string keyValue); + /// + /// 修改手机号 + /// + /// + /// + void UpdateMobile(string keyValue, string mobile); #endregion #region 验证数据 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 711475e03..04e71cf29 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserService.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.Organization/User/UserService.cs @@ -26,6 +26,32 @@ namespace Learun.Application.Organization #endregion #region 获取数据 + public UserEntity GetEntityByMobile(string mobile) + { + try + { + var strSql = new StringBuilder(); + strSql.Append("SELECT "); + strSql.Append(fieldSql); + strSql.Append(" FROM LR_Base_User t "); + strSql.Append(" WHERE t.F_Mobile = @account AND t.F_DeleteMark = 0 "); + return this.BaseRepository().FindEntity(strSql.ToString(), new + { + account = mobile + }); + } + catch (Exception ex) + { + if (ex is ExceptionEx) + { + throw; + } + else + { + throw ExceptionEx.ThrowServiceException(ex); + } + } + } /// /// 获取实体,通过用户账号 /// @@ -833,6 +859,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) { 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 fa3d32db7..3a7776e23 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Controllers/LoginController.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Controllers/LoginController.cs @@ -17,6 +17,10 @@ using System.Web; using Quanjiang.DigitalScholl.WebLicense; using Learun.Application.TwoDevelopment.EducationalAdministration; using Newtonsoft.Json; +using Quanjiang.DigitalScholl.SendSms; +using Learun.Cache.Factory; +using Learun.Cache.Base; +using System.Collections.Generic; namespace Learun.Application.Web.Controllers { @@ -38,6 +42,8 @@ namespace Learun.Application.Web.Controllers private LoginModelIBLL loginModelIbll = new LoginModelBLL(); private AnnexesFileIBLL annexesFileIbll = new AnnexesFileBLL(); WeChatDevelopIBLL weChatDevelopIbll = new WeChatDevelopBLL(); + private readonly ISms aliyunSms = new AliyunSms(); + private ICache redisCache = CacheFactory.CaChe(); #endregion #region 视图功能 @@ -1010,6 +1016,119 @@ namespace Learun.Application.Web.Controllers #endregion + #region 短信发送、校验 + + /// + /// 忘记密码 + /// + /// + public ActionResult ForgotPassword() + { + 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 (!CommonHelper.IsValidMobile(userEntity.F_Mobile)) + { + return Fail("手机号格式不正确!"); + } + if (codeType == "firstlogin" && userEntity.F_HaveLogMark == true) + { + return Fail("当前用户非首次登录,请使用账号密码进行登录!"); + } + var listStr = new List(); + var result = aliyunSms.SendSmsToSingle(userEntity.F_Mobile, SmsType.LoginBind, listStr); + if (result.Result.code == "OK") + { + redisCache.Write("sendcodeinpc_" + codeType + "_" + userEntity.F_Mobile, result.Result.randomNum, new TimeSpan(0, 5, 0), CacheId.sms); + //日志 + 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 + " 验证码:" + result.Result.randomNum; + 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 ForgotPasswordHandle(string codeType, string phone, string verifycode, string newpassword) + { + //短信验证码校验 + if (string.IsNullOrEmpty(codeType)) + { + return Fail("未指定短信类型。"); + } + if (string.IsNullOrEmpty(phone)) + { + return Fail("手机号不能为空。"); + } + var code = redisCache.Read("sendcodeinpc_" + codeType + "_" + phone, CacheId.sms); + if (!string.IsNullOrEmpty(code) && code == verifycode) + { + //return Success("验证成功。"); + UserEntity userEntity = userBll.GetEntityByMobile(phone); + if (userEntity == null) + { + return Fail("用户不存在"); + } + userBll.setPassword(userEntity.F_UserId, newpassword); + + return Success("密码修改成功"); + } + else + { + return Fail("验证失败,验证码错误或已失效。"); + } + } + + #endregion + /// /// 获取IP /// 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 ff53bdbe1..584fb2354 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 @@ -4371,6 +4371,7 @@ + @@ -7332,6 +7333,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 @@ -8431,6 +8436,7 @@ + diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Views/Login/Default.cshtml b/Learun.Framework.Ultimate V7/Learun.Application.Web/Views/Login/Default.cshtml index 828199847..f734c692f 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Views/Login/Default.cshtml +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Views/Login/Default.cshtml @@ -99,6 +99,8 @@