This commit is contained in:
mmrbnjd
2025-07-03 16:05:44 +03:30
parent bc65878608
commit 87d2360b32
8 changed files with 338 additions and 51 deletions

View File

@@ -11,6 +11,7 @@ using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@@ -19,16 +20,18 @@ namespace Hushian.Application.Services
public class VerificationService
{
private readonly IGenericRepository<VerificationCode> _VerificationCodeRepository;
private readonly IGenericRepository<Company> _CompanyRepository;
private readonly IMessageSender _messageSender;
private readonly IGenericRepository<User> _UserRepository;
private readonly AuthService _authService;
public VerificationService(IGenericRepository<VerificationCode> verificationCodeRepository, IMessageSender messageSender, IGenericRepository<User> userRepository, AuthService authService)
public VerificationService(IGenericRepository<VerificationCode> verificationCodeRepository, IMessageSender messageSender, IGenericRepository<User> userRepository, AuthService authService, IGenericRepository<Company> companyRepository)
{
_VerificationCodeRepository = verificationCodeRepository;
_messageSender = messageSender;
_UserRepository = userRepository;
_authService = authService;
_CompanyRepository = companyRepository;
}
public async Task<int> GenerateCodeForLoginUser(string Mobile)
@@ -43,6 +46,18 @@ namespace Hushian.Application.Services
});
return response.ID;
}
public async Task<int> GenerateCodeByPhoneNumberConfirmed(string Mobile)
{
string Code = await GenerateCode();
var response = await _VerificationCodeRepository.ADD
(new Identity.Models.VerificationCode(VerificationCodeType.PhoneNumberConfirmed, Code, Mobile));
await _messageSender.SendMassage(new Models.Message.Message()
{
msg = Code,
To = Mobile
});
return response.ID;
}
public async Task<ResponseBase<AuthResponse>> VerificationCode(ConfirmedCodeDto model)
{
var response = new ResponseBase<AuthResponse>();
@@ -80,7 +95,20 @@ namespace Hushian.Application.Services
}
else if (resultConf.Type == VerificationCodeType.PhoneNumberConfirmed)
{
var anyCompany=await _CompanyRepository.Get().FirstOrDefaultAsync(w => w.Mobile == resultConf.Mobile && !w.Verified);
if (anyCompany!=null)
{
anyCompany.Verified = true;
if(await _CompanyRepository.UPDATEBool(anyCompany))
{
response.Success = true;
response.Value = new AuthResponse();
}
else
{
response.Errors.Add("خطای سیستمی در احراز");
}
}
}
else
{
@@ -98,6 +126,22 @@ namespace Hushian.Application.Services
}
public async Task<bool> ReSendCode(int ID)
{
var model=await _VerificationCodeRepository.Get().FirstOrDefaultAsync(f=>f.ID==ID);
if (model==null)
{
return false;
}
else
{
return await _messageSender.SendMassage(new Models.Message.Message()
{
msg = model.Code,
To = model.Mobile
});
}
}
private async Task<string> GenerateCode()
{