exper
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user