From 0c9a162284878860b78eff1fdad6a4a5337624af Mon Sep 17 00:00:00 2001 From: 移动系统liao <liaoxujun@qq.com> Date: 星期四, 21 八月 2025 13:17:37 +0800 Subject: [PATCH] 修正用户API相关参数 --- Admin.NET/FZCTB.NET.API.Application/Auth/AuthService.cs | 238 ++++++++++++++++++++++++++--------------------------------- 1 files changed, 104 insertions(+), 134 deletions(-) diff --git a/Admin.NET/FZCTB.NET.API.Application/Auth/AuthService.cs b/Admin.NET/FZCTB.NET.API.Application/Auth/AuthService.cs index b651365..252f050 100644 --- a/Admin.NET/FZCTB.NET.API.Application/Auth/AuthService.cs +++ b/Admin.NET/FZCTB.NET.API.Application/Auth/AuthService.cs @@ -1,31 +1,23 @@ -锘縰sing Admin.NET.Core.Service; -using Admin.NET.Core; +锘縰sing Admin.NET.Core; +using Admin.NET.Core.Service; +using cylsg.utility.Extend; +using Furion; using Furion.DataEncryption; using Furion.DynamicApiController; using Furion.EventBus; -using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Lazy.Captcha.Core; -using Microsoft.AspNetCore.Http; -using FZCZTB.NET.MD.CutomerMd; -using Microsoft.AspNetCore.Authorization; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel; -using FZCZTB.NET.SYSService.MSM; -using FZCTB.NET.API.Application.Auth.DTO; using Furion.FriendlyException; -using FZCZTB.NET.SYSService.CustomerSYS; -using Furion; -using NewLife; -using cylsg.utility.Extend; -using static QRCoder.PayloadGenerator; +using FZCTB.NET.API.Application.Auth.DTO; +using FZCZTB.NET.MD.CutomerMd; using FZCZTB.NET.MD.CutomerMd.Extend; -using Furion.DependencyInjection; +using FZCZTB.NET.SYSService.MSM; +using Lazy.Captcha.Core; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; +using NewLife; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; namespace FZCTB.NET.API.Application.Auth { @@ -33,25 +25,22 @@ /// 閴存潈鏈嶅姟 /// </summary> [ApiDescriptionSettings("FZCAPISYS", Order = 149)] - public class AuthService: IDynamicApiController + public class AuthService : IDynamicApiController { - - - private readonly SMSConfigOptions _smsOptions; - private readonly SqlSugarRepository<FBS_CustormerUsers> _sysUserRep; - private readonly SqlSugarRepository<FBS_CoutomerExRole> _sysUserExRol; - private readonly SqlSugarRepository<FBS_ExRole> _sysExRol; - private readonly IHttpContextAccessor _httpContextAccessor; - private readonly SysMenuService _sysMenuService; - private readonly SysOnlineUserService _sysOnlineUserService; - private readonly SysConfigService _sysConfigService; - private readonly SysUserService _sysUserService; - private readonly ZCSMSService _sysSmsService; - private readonly SysLdapService _sysLdapService; private readonly ICaptcha _captcha; private readonly IEventPublisher _eventPublisher; + private readonly IHttpContextAccessor _httpContextAccessor; + private readonly SMSConfigOptions _smsOptions; private readonly SysCacheService _sysCacheService; - + private readonly SysConfigService _sysConfigService; + private readonly SqlSugarRepository<FBS_ExRole> _sysExRol; + private readonly SysLdapService _sysLdapService; + private readonly SysMenuService _sysMenuService; + private readonly SysOnlineUserService _sysOnlineUserService; + private readonly ZCSMSService _sysSmsService; + private readonly SqlSugarRepository<FBS_CoutomerExRole> _sysUserExRol; + private readonly SqlSugarRepository<FBS_CustormerUsers> _sysUserRep; + private readonly SysUserService _sysUserService; public AuthService( SqlSugarRepository<FBS_CustormerUsers> sysUserRep, SqlSugarRepository<FBS_CoutomerExRole> sysUserExRol, @@ -66,14 +55,14 @@ SysUserService sysUserService, IOptions<SMSConfigOptions> smsConfigOptions, SqlSugarRepository<FBS_ExRole> exrel, - + ICaptcha captcha - + ) { _captcha = captcha; _sysUserRep = sysUserRep; - + _sysSmsService = sysSmsService; _eventPublisher = eventPublisher; _sysUserService = sysUserService; @@ -89,78 +78,6 @@ } /// <summary> - /// 鎵嬫満鍙风櫥褰� 馃敄 - /// </summary> - /// <param name="input"></param> - /// <returns></returns> - [AllowAnonymous] - [DisplayName("鎵嬫満鍙风櫥褰�")] - public virtual async Task<CustomerLoginOutput> LoginPhone([Required] CustomerLoginPhoneInput input) - { - if(input.Id>0) - { - //鏈�鍚庝竴娆$‘璁ょ櫥闄嗙姸鎬� - var verifyCode = _sysCacheService.Get<string>($"{CacheConst.KeyPhoneVerCode}{input.Phone}"); - if (string.IsNullOrWhiteSpace(verifyCode)) throw Oops.Oh("楠岃瘉鐮佷笉瀛樺湪鎴栧凡澶辨晥锛岃閲嶆柊鑾峰彇锛�"); - - _sysCacheService.Remove($"{CacheConst.KeyPhoneVerCode}{input.Phone}"); - if (verifyCode != input.Code) - throw Oops.Oh("鐧诲綍鐮佸け鏁�"); - var user = await _sysUserRep.AsQueryable().Where(x => x.Id == input.Id && x.IsEn == true).FirstAsync(); - if(user == null) - throw Oops.Oh("娌℃湁鎵惧埌璇ユ墜鏈虹敤鎴�"); - return await CreateToken(user, input.ExRuleCode ?? ""); - } - if(input.Code!="TEST") - // 鏍¢獙鐭俊楠岃瘉鐮� - _sysSmsService.VerifyCode(new SmsVerifyCodeInput { Phone = input.Phone, Code = input.Code }); - - // 鑾峰彇鐧诲綍绉熸埛鍜岀敤鎴� - // 鑾峰彇鐧诲綍绉熸埛鍜岀敤鎴� - var userList = await _sysUserRep.AsQueryable().Where(x => x.PhoneNumber == input.Phone&&x.IsEn==true).Includes(x=>x.CusExtend).ToListAsync(); - if (userList == null) - { - throw Oops.Oh("娌℃湁鎵惧埌璇ユ墜鏈虹敤鎴�"); - } - if(userList.Count>1) - { - // 鐢熸垚闅忔満楠岃瘉鐮� - var random = new Random(); - var verifyCode = random.Next(100000, 999999); - //闇�瑕佷簩娆$櫥闄� - var aRet = new CustomerLoginOutput - { - TheLastLogo = false, - CustomerExs = new List<CustomerExVm>(), - Code = verifyCode.ToString(), - - - - }; - _sysCacheService.Set($"{CacheConst.KeyPhoneVerCode}{input.Phone}", verifyCode.ToString(), TimeSpan.FromSeconds(_smsOptions.lingKai.VerifyTimeOut.ToInt())); - foreach (var item in userList) - { - aRet.CustomerExs.Add(new CustomerExVm - { - CustomerUserID = item.Id, - EnterpriseName = item.CusExtend.EnterpriseName, - UnifiedSocialCreditCode = item.CusExtend.UnifiedSocialCreditCode.MaskMiddle(), - IsManger = item.IsManager - - - }); - } - return aRet; - - } - - - - - return await CreateToken(userList[0], input.ExRuleCode??""); - } - - /// <summary> /// 鍒囨崲瑙掕壊 宸茬櫥褰曡繘鍘昏鑹叉垨鑰呭垏鎹㈣鑹叉槸璋冪敤锛岄渶瑕佹浛鎹oken,鐩稿綋浜庣櫥褰� /// </summary> [DisplayName("鍒囨崲瑙掕壊")] @@ -170,10 +87,9 @@ if (id == 0) { throw Oops.Oh("鐢ㄦ埛鍑瘉閿欒"); - } var rols = await _sysExRol.GetFirstAsync(x => x.Code == RuleCode && x.Status == StatusEnum.Enable); - if(rols==null) + if (rols == null) throw Oops.Oh("瑙掕壊宸茬粡涓嬬嚎"); // 鑾峰彇鐧诲綍绉熸埛鍜岀敤鎴� @@ -187,14 +103,79 @@ { throw Oops.Oh("鐢ㄥ紓甯�"); } - var exr= await _sysUserExRol.GetFirstAsync(x=>x.CusExtendId==user.CusExtendId&&x.ExRoleId== rols.Id); - if (exr==null) + var exr = await _sysUserExRol.GetFirstAsync(x => x.CusExtendId == user.CusExtendId && x.ExRoleId == rols.Id); + if (exr == null) throw Oops.Oh("娌℃湁鐢宠璇ヨ鑹�"); return await CreateToken(user, RuleCode); - } + /// <summary> + /// 鎵嬫満鍙风櫥褰� 馃敄 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [AllowAnonymous] + [DisplayName("鎵嬫満鍙风櫥褰�")] + public virtual async Task<CustomerLoginOutput> LoginPhone([Required] CustomerLoginPhoneInput input) + { + if (input.Id > 0) + { + //鏈�鍚庝竴娆$‘璁ょ櫥闄嗙姸鎬� + var verifyCode = _sysCacheService.Get<string>($"{CacheConst.KeyPhoneVerCode}{input.Phone}"); + if (string.IsNullOrWhiteSpace(verifyCode)) throw Oops.Oh("楠岃瘉鐮佷笉瀛樺湪鎴栧凡澶辨晥锛岃閲嶆柊鑾峰彇锛�"); + + _sysCacheService.Remove($"{CacheConst.KeyPhoneVerCode}{input.Phone}"); + if (verifyCode != input.Code) + throw Oops.Oh("鐧诲綍鐮佸け鏁�"); + var user = await _sysUserRep.AsQueryable().Where(x => x.Id == input.Id && x.IsEn == true).FirstAsync(); + if (user == null) + throw Oops.Oh("娌℃湁鎵惧埌璇ユ墜鏈虹敤鎴�"); + return await CreateToken(user, input.ExRuleCode ?? ""); + } + if (input.Code != "TEST") + // 鏍¢獙鐭俊楠岃瘉鐮� + _sysSmsService.VerifyCode(new SmsVerifyCodeInput { Phone = input.Phone, Code = input.Code }); + + // 鑾峰彇鐧诲綍绉熸埛鍜岀敤鎴� + // 鑾峰彇鐧诲綍绉熸埛鍜岀敤鎴� + var userList = await _sysUserRep.AsQueryable().Where(x => x.PhoneNumber == input.Phone && x.IsEn == true).Includes(x => x.CusExtend).ToListAsync(); + if (userList == null) + { + throw Oops.Oh("娌℃湁鎵惧埌璇ユ墜鏈虹敤鎴�"); + } + if (userList.Count > 1) + { + // 鐢熸垚闅忔満楠岃瘉鐮� + var random = new Random(); + var verifyCode = random.Next(100000, 999999); + //闇�瑕佷簩娆$櫥闄� + var aRet = new CustomerLoginOutput + { + TheLastLogo = false, + CustomerExs = new List<CustomerExVm>(), + Code = verifyCode.ToString(), + }; + _sysCacheService.Set($"{CacheConst.KeyPhoneVerCode}{input.Phone}", verifyCode.ToString(), TimeSpan.FromSeconds(_smsOptions.lingKai.VerifyTimeOut.ToInt())); + foreach (var item in userList) + { + aRet.CustomerExs.Add(new CustomerExVm + { + CustomerUserID = item.Id, + EnterpriseName = item.CusExtend.EnterpriseName, + UnifiedSocialCreditCode = item.CusExtend.UnifiedSocialCreditCode.MaskMiddle(), + IsManger = item.IsManager + + + + + }); + } + return aRet; + } + + return await CreateToken(userList[0], input.ExRuleCode ?? ""); + } /// <summary> /// 鎵嬫満鍙风櫥褰� 馃敄 /// </summary> @@ -212,7 +193,6 @@ //var user = await _sysUserRep.AsQueryable().Where(x=>x.Account==input.Phone).Includes(x => x.CoutomerExRols, y => y.ExRole).FirstAsync(); //if(user==null) //{ - //} //return await CreateToken(user, input.ExRuleCode ); @@ -225,7 +205,7 @@ /// <param name="sysUserEventTypeEnum"></param>\ /// <returns></returns> [NonAction] - internal async Task<CustomerLoginOutput> CreateToken(FBS_CustormerUsers user,string ExRuleCode, SysUserEventTypeEnum sysUserEventTypeEnum = SysUserEventTypeEnum.Login) + internal async Task<CustomerLoginOutput> CreateToken(FBS_CustormerUsers user, string ExRuleCode, SysUserEventTypeEnum sysUserEventTypeEnum = SysUserEventTypeEnum.Login) { // 鍗曠敤鎴风櫥褰� await _sysOnlineUserService.SingleLogin(user.Id); @@ -237,8 +217,8 @@ { ClaimConst.UserId, user.Id }, { ClaimConst.TenantId, user.CusExtendId }, { ClaimConst.Account, user.PhoneNumber.PrivacyStr() }, - { ClaimConst.RealName, user.Nickname??user.Name }, - + { ClaimConst.RealName, user.Nickname??user.Name }, + { ClaimConst.UserType, "Customer" }, { ClaimConst.CustomerExId, user.CusExtendId }, { ClaimConst.CustomerLogoinType, ExRuleCode }, @@ -274,20 +254,11 @@ { AccessToken = accessToken, RefreshToken = refreshToken, - TheLastLogo=true, - - - - - - - + TheLastLogo = true, + IsManager = user.IsManager } - - }; payload.Output.ExRoles = new List<CustomerExRoleVm>(); - payload.Output.ExRoles = await _sysUserExRol.AsQueryable().Where(x => x.CusExtendId == user.CusExtendId).Includes(x => x.ExRole).Select(x => new CustomerExRoleVm { @@ -296,11 +267,10 @@ Name = x.ExRole.Name }).ToListAsync(); - //鏆傛椂涓嶅嚭鐢ㄦ埛浜嬩欢 // 鍙戝竷绯荤粺鐢ㄦ埛鎿嶄綔浜嬩欢 //await _eventPublisher.PublishAsync(sysUserEventTypeEnum, payload); return payload.Output; } } -} +} \ No newline at end of file -- Gitblit v1.9.1