This commit is contained in:
mmrbnjd
2025-06-29 16:14:42 +03:30
parent 86de5d3e39
commit bc65878608
7 changed files with 165 additions and 3 deletions

View File

@@ -26,14 +26,57 @@ namespace Hushian.Application.Services
private readonly IGenericRepository<User> _UserRepository;
private readonly IGenericRepository<Exper> _ExperRepository;
private readonly VerificationService _verificationService;
public AuthService(IOptions<JwtSettings> jwtSettings)
public AuthService(IOptions<JwtSettings> jwtSettings, IGenericRepository<Company> companyRepository, IGenericRepository<User> userRepository, IGenericRepository<Exper> experRepository, VerificationService verificationService)
{
_jwtSettings = jwtSettings.Value;
_CompanyRepository = companyRepository;
_UserRepository = userRepository;
_ExperRepository = experRepository;
_verificationService = verificationService;
}
public async Task<ResponseBase<AuthResponse>> AuthenticationFromCompanySide
(AuthRequestFromCompanySide auth)
{
ResponseBase<AuthResponse> Response = new();
if (auth.Username.StartsWith("09"))
{
// in Company Search
var Company= await _CompanyRepository.Get().FirstOrDefaultAsync(f=>f.Mobile== auth.Username && f.Password==auth.Password.GetHash());
if (Company==null)
{
Response.Errors.Add("کاربری یافت نشد");
}
else
{
Response.Success = true;
Response.Value = new AuthResponse()
{
Fullname = Company.FullName,
Id = Company.ID,
MobileOrUserName = Company.Mobile,
Token = new JwtSecurityTokenHandler().WriteToken(await GenerateToken(Company.Mobile, Company.ID))
};
}
}
else
{
var exper = await _ExperRepository.Get().FirstOrDefaultAsync(f => f.UserName == auth.Username && f.Password == auth.Password.GetHash());
if (exper == null)
{
Response.Errors.Add("کاربری یافت نشد");
}
else
{
Response.Success = true;
Response.Value = new AuthResponse()
{
Fullname = exper.FullName,
Id = exper.ID,
MobileOrUserName = exper.UserName,
Token = new JwtSecurityTokenHandler().WriteToken(await GenerateToken(exper.UserName, exper.ID))
};
}
}
return Response;
}
public async Task<ResponseBase<int>> AuthenticationFromUserSide