You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.5 KiB
78 lines
2.5 KiB
using System.Security.Claims;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.Extensions.Logging;
|
|
using MediatR;
|
|
using CellularManagement.Application.Common.Extensions;
|
|
using CellularManagement.Domain.Entities;
|
|
using CellularManagement.Domain.Repositories;
|
|
using CellularManagement.Domain.Services;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using System.Threading;
|
|
using System.Linq;
|
|
using System;
|
|
using CellularManagement.Domain.Common;
|
|
using Microsoft.AspNetCore.Http;
|
|
using UAParser;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using CellularManagement.Application.Features.Auth.Models;
|
|
using CellularManagement.Domain.Repositories.Identity;
|
|
using CellularManagement.Domain.Repositories.Base;
|
|
|
|
namespace CellularManagement.Application.Features.Auth.Commands.AuthenticateUser;
|
|
|
|
/// <summary>
|
|
/// 账号登录命令处理器
|
|
/// </summary>
|
|
public sealed class AuthenticateUserCommandHandler : BaseLoginCommandHandler<AuthenticateUserCommand, AuthenticateUserResponse>
|
|
{
|
|
/// <summary>
|
|
/// 初始化处理器
|
|
/// </summary>
|
|
public AuthenticateUserCommandHandler(
|
|
UserManager<AppUser> userManager,
|
|
IJwtProvider jwtProvider,
|
|
ILogger<AuthenticateUserCommandHandler> logger,
|
|
IUserRoleRepository userRoleRepository,
|
|
IRolePermissionRepository rolePermissionRepository,
|
|
IUnitOfWork unitOfWork,
|
|
ILoginLogRepository loginLogRepository,
|
|
IHttpContextAccessor httpContextAccessor)
|
|
: base(userManager, jwtProvider, logger, userRoleRepository, rolePermissionRepository, unitOfWork, loginLogRepository, httpContextAccessor)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理认证请求
|
|
/// </summary>
|
|
public override Task<OperationResult<AuthenticateUserResponse>> Handle(
|
|
AuthenticateUserCommand request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
return HandleLoginAsync(request, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查找用户
|
|
/// </summary>
|
|
protected override Task<AppUser?> FindUserAsync(AuthenticateUserCommand request)
|
|
{
|
|
return _userManager.FindByNameAsync(request.UserName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户标识
|
|
/// </summary>
|
|
protected override string GetUserIdentifier(AuthenticateUserCommand request)
|
|
{
|
|
return request.UserName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取密码
|
|
/// </summary>
|
|
protected override string GetPassword(AuthenticateUserCommand request)
|
|
{
|
|
return request.Password;
|
|
}
|
|
}
|