50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using BarCode.Web.Core.Dto.Login;
|
|
using BarCode.Web.Domain.Infrastructure;
|
|
using BarCode.Web.Domain.Services.Public;
|
|
|
|
namespace BarCode.Web.Repositories
|
|
{
|
|
/// <summary>
|
|
/// 登录仓储
|
|
/// </summary>
|
|
public class LoginRepositories:ILoginRepositories
|
|
{
|
|
public int CompanyId { get; set; } = 0;
|
|
public int StaffId { get; set; } = 0;
|
|
public LoginInDto loginInfo { get; set; }
|
|
private readonly RedisClientService _redisClientService;
|
|
public LoginRepositories(ILogger<LoginRepositories> logger, IHttpContextAccessor httpContextAccessor, RedisClientService redisClientService)
|
|
{
|
|
try
|
|
{
|
|
string authorization = httpContextAccessor?.HttpContext?.Request?.Headers["Authorization"] ?? "";
|
|
if (string.IsNullOrEmpty(authorization)) return;
|
|
|
|
string token = string.Empty;
|
|
if (authorization.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
|
token = authorization.Substring("Bearer ".Length).Trim();
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
this.CompanyId = 0;
|
|
this.StaffId = 0;
|
|
return;
|
|
}
|
|
|
|
_redisClientService = redisClientService;
|
|
var logininfo = _redisClientService.GetStringKey<LoginInDto>($"wms_login_{token}");
|
|
this.loginInfo = loginInfo;
|
|
this.CompanyId = logininfo == null ? 0 : logininfo.UserInfo.CompanyId;
|
|
this.StaffId = logininfo == null ? 0 : logininfo.UserInfo.StaffId;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|