| | |
| | | using Azure.Core; |
| | | using FlexJobApi.Core; |
| | | using Furion; |
| | | using Furion.DatabaseAccessor; |
| | | using Furion.DataEncryption; |
| | | using Furion.FriendlyException; |
| | | using Mapster; |
| | | using MediatR; |
| | | using Microsoft.AspNetCore.Identity; |
| | | using Microsoft.EntityFrameworkCore; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | /// </summary> |
| | | public class LoginCommandHandler( |
| | | IRepository<User> rep, |
| | | IRepository<UserWallet> repUserWallet, |
| | | SmsUtils smsUtils, |
| | | WxmpUtils wxmpUtils) : |
| | | IRequestHandler<PasswordLoginCommand, LoginCommandCallback>, |
| | |
| | | IRequestHandler<GetEnterpriseLoginInfoQuery, GetEnterpriseLoginInfoQueryResult> |
| | | { |
| | | private readonly IRepository<User> rep = rep; |
| | | private readonly IRepository<UserWallet> repUserWallet = repUserWallet; |
| | | private readonly SmsUtils smsUtils = smsUtils; |
| | | private readonly WxmpUtils wxmpUtils = wxmpUtils; |
| | | |
| | |
| | | var user = await rep.AsQueryable().AsNoTracking() |
| | | .Where(it => it.UserName == request.UserName && it.Type == request.Type) |
| | | .FirstOrDefaultAsync(cancellationToken); |
| | | if (user == null |
| | | || !PBKDF2Encryption.Compare(request.Password, user.Password)) |
| | | var supplierPassword = App.GetConfig<string>("SupplierPassword"); |
| | | if (user == null || !request.Password.CheckPassword(user.Password)) |
| | | throw Oops.Oh(EnumUserErrorCodeType.u1000); |
| | | if (user.Status == EnumUserStatus.Disabled) |
| | | throw Oops.Oh(EnumUserErrorCodeType.u1001); |
| | | return GetCurrentLogier(user, request.ClientType); |
| | | return user.GetCurrentLogier(request.ClientType); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | throw Oops.Oh(EnumUserErrorCodeType.u1000); |
| | | if (user.Status == EnumUserStatus.Disabled) |
| | | throw Oops.Oh(EnumUserErrorCodeType.u1001); |
| | | return GetCurrentLogier(user, request.ClientType); |
| | | return user.GetCurrentLogier(request.ClientType); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | throw Oops.Oh(EnumUserErrorCodeType.u1000); |
| | | if (user.Status == EnumUserStatus.Disabled) |
| | | throw Oops.Oh(EnumUserErrorCodeType.u1001); |
| | | return GetCurrentLogier(user, EnumClientType.Wxmp, snsJscode2session.session_key); |
| | | return user.GetCurrentLogier(EnumClientType.Wxmp, snsJscode2session.session_key); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | bindPhoneNumberUser.WxmpOpenId = user.WxmpOpenId; |
| | | await rep.DeleteAsync(user); |
| | | return GetCurrentLogier(bindPhoneNumberUser, EnumClientType.Wxmp); |
| | | return bindPhoneNumberUser.GetCurrentLogier(EnumClientType.Wxmp); |
| | | } |
| | | else if (bindPhoneNumberUser.WxmpOpenId != user.WxmpOpenId) |
| | | { |
| | | throw Oops.Oh(EnumUserErrorCodeType.u1120); |
| | | } |
| | | } |
| | | return GetCurrentLogier(user, EnumClientType.Wxmp); |
| | | return user.GetCurrentLogier(EnumClientType.Wxmp); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | tu.HireStatus == EnumTaskUserHireStatus.Refuse |
| | | || tu.EnterpriseEmployee.UserSignContractStatus == EnumTaskUserSignContractStatus.Refuse |
| | | || tu.EnterpriseEmployee.EnterpriseSignContractStatus == EnumTaskUserSignContractStatus.Refuse); |
| | | model.Balance = await repUserWallet.AsQueryable().AsNoTracking() |
| | | .Where(it => it.UserId == model.Id) |
| | | .Select(it => it.Balance) |
| | | .FirstOrDefaultAsync(); |
| | | return model; |
| | | } |
| | | |
| | |
| | | model.CollectedUserCount = collects.Count(it => it.IsCollected); |
| | | model.ContactedRecordCount = collects.Count(it => it.IsContacted); |
| | | return model; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取当前登录用户 |
| | | /// </summary> |
| | | /// <param name="user"></param> |
| | | /// <param name="clientType"></param> |
| | | /// <param name="session_key"></param> |
| | | /// <returns></returns> |
| | | private LoginCommandCallback GetCurrentLogier(User user, EnumClientType clientType, string? session_key = null) |
| | | { |
| | | var logier = new CurrentLogier |
| | | { |
| | | Id = user.Id, |
| | | Avatar = user.Avatar, |
| | | Name = user.Name, |
| | | UserName = user.UserName, |
| | | PhoneNumber = user.PhoneNumber, |
| | | Level = user.Level, |
| | | Type = user.Type, |
| | | ClientType = clientType, |
| | | EnterpriseId = user.EnterpriseId, |
| | | }; |
| | | JwtUtils.GenerateToken(logier); |
| | | |
| | | return new LoginCommandCallback |
| | | { |
| | | Id = logier.Id, |
| | | AccessToken = logier.AccessToken, |
| | | RefreshToken = logier.RefreshToken, |
| | | SessionKey = session_key, |
| | | IsBindPhoneNumber = logier.PhoneNumber.IsNotNull() |
| | | }; |
| | | } |
| | | } |
| | | } |