Procházet zdrojové kódy

修复 手机号登录发送验证码更改手机号能登录的问题

zhontai před 1 rokem
rodič
revize
e63d7019ab

+ 8 - 0
src/platform/ZhonTai.Admin/Core/Consts/CacheKeys.cs

@@ -38,4 +38,12 @@ public static partial class CacheKeys
     /// </summary>
     [Description("短信验证码")]
     public const string SmsCode = "admin:sms:code:";
+
+    /// <summary>
+    /// 获取短信验证码
+    /// </summary>
+    /// <param name="mobile">手机号</param>
+    /// <param name="code">唯一码</param>
+    /// <returns></returns>
+    public static string GetSmsCode(string mobile, string code) => $"{SmsCode}{mobile}:{code}";
 }

+ 0 - 1
src/platform/ZhonTai.Admin/Core/Db/FreeSqlDbContextExtensions.cs

@@ -1,7 +1,6 @@
 using System;
 using ZhonTai.Admin.Core.Repositories;
 using System.Linq.Expressions;
-using ZhonTai.Admin.Tools.TaskScheduler;
 using FreeScheduler;
 using ZhonTai.Admin.Core.Configs;
 

+ 2 - 2
src/platform/ZhonTai.Admin/Services/Auth/AuthService.cs

@@ -458,7 +458,7 @@ public class AuthService : BaseService, IAuthService, IDynamicApi
             sw.Start();
 
             #region 短信验证码验证
-            var codeKey = CacheKeys.SmsCode + input.CodeId;
+            var codeKey = CacheKeys.GetSmsCode(input.Mobile, input.CodeId);
             if (await Cache.ExistsAsync(codeKey))
             {
                 var code = await Cache.GetAsync(codeKey);
@@ -470,7 +470,7 @@ public class AuthService : BaseService, IAuthService, IDynamicApi
             }
             else
             {
-                throw ResultOutput.Exception("验证码已过期,请重新发送");
+                throw ResultOutput.Exception("验证码不存在,请重新发送");
             }
 
             #endregion

+ 1 - 1
src/platform/ZhonTai.Admin/Services/Captcha/CaptchaService.cs

@@ -87,7 +87,7 @@ public class CaptchaService : BaseService, IDynamicApi
 
         var codeId = input.CodeId.IsNull() ? Guid.NewGuid().ToString() : input.CodeId;
         var code = StringHelper.GenerateRandomNumber();
-        await Cache.SetAsync(CacheKeys.SmsCode + codeId, code, TimeSpan.FromMinutes(5));
+        await Cache.SetAsync(CacheKeys.GetSmsCode(input.Mobile, codeId), code, TimeSpan.FromMinutes(5));
 
         //发送短信
         await LazyGetRequiredService<ICapPublisher>().PublishAsync(SubscribeNames.SmsSingleSend,

+ 8 - 0
src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

@@ -1045,6 +1045,14 @@
             短信验证码 admin:sms:code:guid
             </summary>
         </member>
+        <member name="M:ZhonTai.Admin.Core.Consts.CacheKeys.GetSmsCode(System.String,System.String)">
+            <summary>
+            获取短信验证码
+            </summary>
+            <param name="mobile">手机号</param>
+            <param name="code">唯一码</param>
+            <returns></returns>
+        </member>
         <member name="T:ZhonTai.Admin.Core.Consts.DbKeys">
             <summary>
             数据库键名