| | |
| | | using Admin.NET.Core.Service; |
| | | using Admin.NET.Core; |
| | | using 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 |
| | | { |
| | |
| | | [ApiDescriptionSettings("FZCAPISYS", Order = 149)] |
| | | 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, |
| | |
| | | _smsOptions = smsConfigOptions.Value; |
| | | _sysExRol = exrel; |
| | | _sysUserExRol = sysUserExRol; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 切换角色 已登录进去角色或者切换角色是调用,需要替换Token,相当于登录 |
| | | /// </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> |
| | |
| | | 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) |
| | |
| | | IsManger = item.IsManager |
| | | |
| | | |
| | | |
| | | |
| | | }); |
| | | } |
| | | return aRet; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | return await CreateToken(userList[0], input.ExRuleCode??""); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 切换角色 已登录进去角色或者切换角色是调用,需要替换Token,相当于登录 |
| | | /// </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> |
| | | /// 手机号登录 🔖 |
| | | /// </summary> |
| | |
| | | //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 ); |
| | |
| | | AccessToken = accessToken, |
| | | RefreshToken = refreshToken, |
| | | 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 |
| | | { |
| | |
| | | HasFlsh = x.steps == CusExtendStep.Pass, |
| | | Name = x.ExRole.Name |
| | | }).ToListAsync(); |
| | | |
| | | |
| | | //暂时不出用户事件 |
| | | // 发布系统用户操作事件 |