101 lines
3.8 KiB
C#
101 lines
3.8 KiB
C#
// using Modules.User.Application.Gateways;
|
|
// using Modules.User.Application.Models;
|
|
// using Modules.User.Application.Models.Access;
|
|
// using Modules.User.Database.Repositories;
|
|
// using ClientInfo = Modules.User.Application.Models.ClientInfo;
|
|
// using Session = Modules.User.Application.Models.Session;
|
|
//
|
|
// namespace Modules.User.Database.GatewaysImplementations;
|
|
//
|
|
// public class AccountGateway(SessionRepository sessionRepository, RoleRepository roleRepository) : IAccountGateway
|
|
// {
|
|
// public async Task<List<Session>> GetAccountSessions(Guid accountId)
|
|
// {
|
|
// var sessions = await sessionRepository.GetAll(accountId);
|
|
// return sessions.Select(q => new Session
|
|
// {
|
|
// Id = q.Id,
|
|
// RefreshToken = q.RefreshToken,
|
|
// ClientInfo = new ClientInfo
|
|
// {
|
|
// UserAgent = q.ClientInfo.UserAgent,
|
|
// Location = new Location
|
|
// {
|
|
// Country = q.ClientInfo.Country,
|
|
// Region = q.ClientInfo.Region,
|
|
// },
|
|
// },
|
|
// LastOnline = q.LastUpdate,
|
|
// AccountId = q.AccountId,
|
|
// ExpiredDate = q.ExpiredDate,
|
|
// }).ToList();
|
|
// }
|
|
//
|
|
// public async Task<Session?> TryGetSession(string refreshToken)
|
|
// {
|
|
// var session = await sessionRepository.GetFirstOrDefaultWhere(q => q.RefreshToken == refreshToken.Trim()
|
|
// && q.ExpiredDate > DateTime.UtcNow);
|
|
// return session == null ? null : new Session
|
|
// {
|
|
// Id = session.Id,
|
|
// RefreshToken = session.RefreshToken,
|
|
// ClientInfo = new()
|
|
// {
|
|
// UserAgent = session.ClientInfo.UserAgent,
|
|
// Location = new()
|
|
// {
|
|
// Country = session.ClientInfo.Country,
|
|
// Region = session.ClientInfo.Region,
|
|
// },
|
|
// },
|
|
// AccountId = session.AccountId,
|
|
// ExpiredDate = session.ExpiredDate,
|
|
// };
|
|
// }
|
|
//
|
|
// public async Task<bool> UpdateSessions(Guid accountId, IEnumerable<Session> sessions, IEnumerable<Guid>? forceUpdateSessionIds = null)
|
|
// {
|
|
// return await sessionRepository.SyncSessions(accountId, sessions.Select(q => new Database.Entities.Session
|
|
// {
|
|
// Id = q.Id != Guid.Empty ? q.Id : Guid.NewGuid(),
|
|
// RefreshToken = q.RefreshToken,
|
|
// ClientInfo = new()
|
|
// {
|
|
// UserAgent = q.ClientInfo.UserAgent,
|
|
// Country = q.ClientInfo.Location.Country,
|
|
// Region = q.ClientInfo.Location.Region,
|
|
// },
|
|
// AccountId = q.AccountId,
|
|
// ExpiredDate = q.ExpiredDate,
|
|
// }).ToList(), forceUpdateSessionIds?.ToList());
|
|
// }
|
|
//
|
|
// public async Task<IEnumerable<Role>> GetAccountRoles(Guid accountId)
|
|
// {
|
|
// var accountRoles = await roleRepository.GetAccountRoles(accountId, true);
|
|
//
|
|
// return accountRoles.Select(q => new Role
|
|
// {
|
|
// Id = q.Id,
|
|
// Permissions = [..q.Permissions.Select(x => new Permission
|
|
// {
|
|
// Id = x.Id,
|
|
// Name = x.Name,
|
|
// Code = x.Code,
|
|
// })],
|
|
// Name = q.Name
|
|
// });
|
|
// }
|
|
//
|
|
// public async Task<IEnumerable<Permission>> GetAccountPermissions(Guid accountId)
|
|
// {
|
|
// var accountPermissions = await roleRepository.GetAccountPermissions(accountId);
|
|
//
|
|
// return accountPermissions.Select(q => new Permission
|
|
// {
|
|
// Id = q.Id,
|
|
// Name = q.Name,
|
|
// Code = q.Code,
|
|
// });
|
|
// }
|
|
// } |