This commit is contained in:
mmrbnjd
2025-07-03 16:38:14 +03:30
parent 87d2360b32
commit 23043dd094
4 changed files with 153 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ using Common.Enums;
using Common.Models.Auth;
using Hushian.Application.Contracts.Persistence;
using Hushian.Application.Models;
using Hushian.Application.Validation;
using Hushian.Domain.Entites;
using Identity.Models;
using Microsoft.EntityFrameworkCore;
@@ -21,17 +22,19 @@ namespace Hushian.Application.Services
{
private readonly IGenericRepository<VerificationCode> _VerificationCodeRepository;
private readonly IGenericRepository<Company> _CompanyRepository;
private readonly IGenericRepository<Exper> _ExperRepository;
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, IGenericRepository<Company> companyRepository)
public VerificationService(IGenericRepository<VerificationCode> verificationCodeRepository, IMessageSender messageSender, IGenericRepository<User> userRepository, AuthService authService, IGenericRepository<Company> companyRepository, IGenericRepository<Exper> experRepository)
{
_VerificationCodeRepository = verificationCodeRepository;
_messageSender = messageSender;
_UserRepository = userRepository;
_authService = authService;
_CompanyRepository = companyRepository;
_ExperRepository = experRepository;
}
public async Task<int> GenerateCodeForLoginUser(string Mobile)
@@ -58,6 +61,18 @@ namespace Hushian.Application.Services
});
return response.ID;
}
public async Task<int> GenerateCodeByForgetPassword(string Mobile)
{
string Code = await GenerateCode();
var response = await _VerificationCodeRepository.ADD
(new Identity.Models.VerificationCode(VerificationCodeType.ForgetPassword, 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>();
@@ -86,11 +101,41 @@ namespace Hushian.Application.Services
}
else if (resultConf.Type == VerificationCodeType.ForgetPassword)
{
if ((string.IsNullOrEmpty(model.value) || model.value.Length < 5))
response.Errors.Add("کلمه عبور باید بیشتر از 5 کاراکتر باشد");
List<string> errors = new();
if (model.value.CheckLawPassword(ref errors))
response.Errors.AddRange(errors);
else
{
if (resultConf.Mobile.StartsWith("09"))
{
var anyCompany = await _CompanyRepository.Get().FirstOrDefaultAsync(w => w.Mobile == resultConf.Mobile);
anyCompany.Password = model.value.GetHash();
anyCompany.Verified = true;
if (await _CompanyRepository.UPDATEBool(anyCompany))
{
response.Success = true;
response.Value = new AuthResponse();
}
else
{
response.Errors.Add("خطای سیستمی در احراز");
}
}
else
{
var anyexper=await _ExperRepository.Get().FirstOrDefaultAsync(w => w.UserName == resultConf.Mobile);
anyexper.Password = model.value.GetHash();
if (await _ExperRepository.UPDATEBool(anyexper))
{
response.Success = true;
response.Value = new AuthResponse();
}
else
{
response.Errors.Add("خطای سیستمی در احراز");
}
}
}
}
else if (resultConf.Type == VerificationCodeType.PhoneNumberConfirmed)