From 1978a2687b298a69bc72d6eda0be8235bbca37d8 Mon Sep 17 00:00:00 2001 From: username@email.com <yzy2002yzy@163.com> Date: 星期一, 01 九月 2025 13:22:12 +0800 Subject: [PATCH] 修改了一些字段 --- Admin.NET/FZCTB.NET.API.Application/Auth/AuthService.cs | 217 +++++++++++++++++++++++++++++++++++------------------ 1 files changed, 143 insertions(+), 74 deletions(-) diff --git a/Admin.NET/FZCTB.NET.API.Application/Auth/AuthService.cs b/Admin.NET/FZCTB.NET.API.Application/Auth/AuthService.cs index 376ef20..252f050 100644 --- a/Admin.NET/FZCTB.NET.API.Application/Auth/AuthService.cs +++ b/Admin.NET/FZCTB.NET.API.Application/Auth/AuthService.cs @@ -1,24 +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 FZCTB.NET.API.Application.Auth.DTO; +using FZCZTB.NET.MD.CutomerMd; +using FZCZTB.NET.MD.CutomerMd.Extend; +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 { @@ -26,25 +25,25 @@ /// 閴存潈鏈嶅姟 /// </summary> [ApiDescriptionSettings("FZCAPISYS", Order = 149)] - public class AuthService: IDynamicApiController + public class AuthService : IDynamicApiController { - - - private readonly UserManager _userManager; - private readonly SqlSugarRepository<FBS_Customer> _sysUserRep; - 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_Customer> sysUserRep, + SqlSugarRepository<FBS_CustormerUsers> sysUserRep, + SqlSugarRepository<FBS_CoutomerExRole> sysUserExRol, IHttpContextAccessor httpContextAccessor, SysOnlineUserService sysOnlineUserService, SysConfigService sysConfigService, @@ -54,12 +53,16 @@ SysCacheService sysCacheService, SysMenuService sysMenuService, SysUserService sysUserService, - UserManager userManager, - ICaptcha captcha) + IOptions<SMSConfigOptions> smsConfigOptions, + SqlSugarRepository<FBS_ExRole> exrel, + + ICaptcha captcha + + ) { _captcha = captcha; _sysUserRep = sysUserRep; - _userManager = userManager; + _sysSmsService = sysSmsService; _eventPublisher = eventPublisher; _sysUserService = sysUserService; @@ -69,6 +72,42 @@ _httpContextAccessor = httpContextAccessor; _sysOnlineUserService = sysOnlineUserService; _sysLdapService = sysLdapService; + _smsOptions = smsConfigOptions.Value; + _sysExRol = exrel; + _sysUserExRol = sysUserExRol; + } + + /// <summary> + /// 鍒囨崲瑙掕壊 宸茬櫥褰曡繘鍘昏鑹叉垨鑰呭垏鎹㈣鑹叉槸璋冪敤锛岄渶瑕佹浛鎹oken,鐩稿綋浜庣櫥褰� + /// </summary> + [DisplayName("鍒囨崲瑙掕壊")] + public async Task<CustomerLoginOutput> ChangeLogoInExRule(string RuleCode) + { + var id = App.User.FindFirst(ClaimConst.UserId)?.Value.ToLong() ?? 0; + if (id == 0) + { + throw Oops.Oh("鐢ㄦ埛鍑瘉閿欒"); + } + var rols = await _sysExRol.GetFirstAsync(x => x.Code == RuleCode && x.Status == StatusEnum.Enable); + if (rols == null) + throw Oops.Oh("瑙掕壊宸茬粡涓嬬嚎"); + + // 鑾峰彇鐧诲綍绉熸埛鍜岀敤鎴� + // 鑾峰彇鐧诲綍绉熸埛鍜岀敤鎴� + var user = await _sysUserRep.AsQueryable().Where(x => x.Id == id).FirstAsync(); + if (user == null) + { + throw Oops.Oh("璇ョ敤鎴锋病鏈夋敞鍐�"); + } + if (user.IsEn == false) + { + throw Oops.Oh("鐢ㄥ紓甯�"); + } + 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> @@ -80,24 +119,62 @@ [DisplayName("鎵嬫満鍙风櫥褰�")] public virtual async Task<CustomerLoginOutput> LoginPhone([Required] CustomerLoginPhoneInput input) { - if(input.Code!="TEST") - // 鏍¢獙鐭俊楠岃瘉鐮� - _sysSmsService.VerifyCode(new SmsVerifyCodeInput { Phone = input.Phone, Code = input.Code }); + 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 user = await _sysUserRep.AsQueryable().Where(x => x.Account == input.Phone).Includes(x => x.CoutomerExRols, y => y.ExRole).FirstAsync(); - if (user == null) + 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("璇ョ敤鎴锋病鏈夋敞鍐�"); + throw Oops.Oh("娌℃湁鎵惧埌璇ユ墜鏈虹敤鎴�"); } - if(user.Status== StatusEnum.Disable) + if (userList.Count > 1) { - throw Oops.Oh("鐢ㄥ紓甯�"); - } + // 鐢熸垚闅忔満楠岃瘉鐮� + 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 await CreateToken(user, input.ExRuleCode??""); + + + }); + } + return aRet; + } + + return await CreateToken(userList[0], input.ExRuleCode ?? ""); } /// <summary> /// 鎵嬫満鍙风櫥褰� 馃敄 @@ -108,18 +185,17 @@ [DisplayName("寰俊鎵爜鐧诲綍")] public virtual async Task<CustomerLoginOutput> WeiXinLoginPhone([Required] CustomerLoginPhoneInput input) { - throw Oops.Oh("鍜嬩笉鏀寔寰俊鎵爜鐧诲綍"); + throw Oops.Oh("鏆傛椂涓嶆敮鎸佸井淇℃壂鐮佺櫥褰�"); // 鏍¢獙鐭俊楠岃瘉鐮� - _sysSmsService.VerifyCode(new SmsVerifyCodeInput { Phone = input.Phone, Code = input.Code }); + //_sysSmsService.VerifyCode(new SmsVerifyCodeInput { Phone = input.Phone, Code = input.Code }); - // 鑾峰彇鐧诲綍绉熸埛鍜岀敤鎴� - var user = await _sysUserRep.AsQueryable().Where(x=>x.Account==input.Phone).Includes(x => x.CoutomerExRols, y => y.ExRole).FirstAsync(); - if(user==null) - { - - } + //// 鑾峰彇鐧诲綍绉熸埛鍜岀敤鎴� + //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 ); + //return await CreateToken(user, input.ExRuleCode ); } /// <summary> @@ -129,7 +205,7 @@ /// <param name="sysUserEventTypeEnum"></param>\ /// <returns></returns> [NonAction] - internal async Task<CustomerLoginOutput> CreateToken(FBS_Customer 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); @@ -139,11 +215,12 @@ var accessToken = JWTEncryption.Encrypt(new Dictionary<string, object> { { ClaimConst.UserId, user.Id }, - { ClaimConst.TenantId, user.TenantId }, - { ClaimConst.Account, user.Account }, - { ClaimConst.RealName, user.RealName }, - + { ClaimConst.TenantId, user.CusExtendId }, + { ClaimConst.Account, user.PhoneNumber.PrivacyStr() }, + { ClaimConst.RealName, user.Nickname??user.Name }, + { ClaimConst.UserType, "Customer" }, + { ClaimConst.CustomerExId, user.CusExtendId }, { ClaimConst.CustomerLogoinType, ExRuleCode }, }, tokenExpire); @@ -177,26 +254,18 @@ { AccessToken = accessToken, RefreshToken = refreshToken, - - - - - - + TheLastLogo = true, + IsManager = user.IsManager } }; payload.Output.ExRoles = new List<CustomerExRoleVm>(); - foreach (var item in user.CoutomerExRols) + payload.Output.ExRoles = await _sysUserExRol.AsQueryable().Where(x => x.CusExtendId == user.CusExtendId).Includes(x => x.ExRole).Select(x => new CustomerExRoleVm { - - payload.Output.ExRoles.Add(new CustomerExRoleVm - { - Code = item.ExRole.Code, - Name = item.ExRole.Name, - HasFlsh = item.HasFlsh - }); - } + Code = x.ExRole.Code, + HasFlsh = x.steps == CusExtendStep.Pass, + Name = x.ExRole.Name + }).ToListAsync(); //鏆傛椂涓嶅嚭鐢ㄦ埛浜嬩欢 // 鍙戝竷绯荤粺鐢ㄦ埛鎿嶄綔浜嬩欢 @@ -204,4 +273,4 @@ return payload.Output; } } -} +} \ No newline at end of file -- Gitblit v1.9.1