...
This commit is contained in:
@@ -4,12 +4,10 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Common.Dtos.Exper
|
namespace Common.Dtos
|
||||||
{
|
{
|
||||||
public class ChangePassword_ExperDto
|
public class ChangePasswordDto
|
||||||
{
|
{
|
||||||
//From User And CompanyManager
|
|
||||||
public int ID { get; set; }
|
|
||||||
public string? OldPassWord { get; set; }
|
public string? OldPassWord { get; set; }
|
||||||
public string NewPassWord { get; set; }
|
public string NewPassWord { get; set; }
|
||||||
}
|
}
|
@@ -1,5 +1,7 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
using Common.Dtos;
|
||||||
using Common.Dtos.Company;
|
using Common.Dtos.Company;
|
||||||
|
using Common.Dtos.Exper;
|
||||||
using Hushian.Application.Contracts.Persistence;
|
using Hushian.Application.Contracts.Persistence;
|
||||||
using Hushian.Application.Models;
|
using Hushian.Application.Models;
|
||||||
using Hushian.Application.Validation;
|
using Hushian.Application.Validation;
|
||||||
@@ -99,6 +101,41 @@ namespace Hushian.Application.Services
|
|||||||
company.allowBot = @checked;
|
company.allowBot = @checked;
|
||||||
return await _CompanyRepository.UPDATEBool(company);
|
return await _CompanyRepository.UPDATEBool(company);
|
||||||
}
|
}
|
||||||
|
public async Task<ResponseBase<bool>> ChangePasswordCompany(ChangePasswordDto model, int CompanyID)
|
||||||
|
{
|
||||||
|
ResponseBase<bool> Response = new();
|
||||||
|
|
||||||
|
var company = await _CompanyRepository.Get().FirstOrDefaultAsync(f => f.ID == CompanyID);
|
||||||
|
if (string.IsNullOrEmpty(model.OldPassWord) || model.OldPassWord.GetHash()!=company.Password)
|
||||||
|
{
|
||||||
|
Response.Errors.Add("کلمه عبور فعلی صحیح نمی باشد");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
company.Password = model.NewPassWord.GetHash();
|
||||||
|
Response.Value= await _CompanyRepository.UPDATEBool(company);
|
||||||
|
if (!Response.Value) Response.Errors.Add("خطا در ذخیره سازی");
|
||||||
|
else Response.Success = true;
|
||||||
|
}
|
||||||
|
return Response;
|
||||||
|
}
|
||||||
|
public async Task<ResponseBase<int>> ForgetPasswordCompany(string Mobile)
|
||||||
|
{
|
||||||
|
ResponseBase<int> Response = new();
|
||||||
|
|
||||||
|
var company = await _CompanyRepository.Get().FirstOrDefaultAsync(f => f.Mobile == Mobile);
|
||||||
|
if (company==null)
|
||||||
|
{
|
||||||
|
Response.Errors.Add("کاربری یافت نشد");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Response.Value= await _VerificationService.GenerateCodeByForgetPassword(Mobile);
|
||||||
|
Response.Success = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
return Response;
|
||||||
|
}
|
||||||
private async Task<ResponseBase<bool>> NewCompany(RegisterCompanyDto dto)
|
private async Task<ResponseBase<bool>> NewCompany(RegisterCompanyDto dto)
|
||||||
{
|
{
|
||||||
ResponseBase<bool> Response = new();
|
ResponseBase<bool> Response = new();
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
using Common.Dtos.Exper;
|
using Common.Dtos;
|
||||||
|
using Common.Dtos.Exper;
|
||||||
using Hushian.Application.Contracts.Persistence;
|
using Hushian.Application.Contracts.Persistence;
|
||||||
using Hushian.Application.Models;
|
using Hushian.Application.Models;
|
||||||
using Hushian.Application.Validation;
|
using Hushian.Application.Validation;
|
||||||
using Hushian.Domain.Entites;
|
using Hushian.Domain.Entites;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -15,6 +17,7 @@ namespace Hushian.Application.Services
|
|||||||
{
|
{
|
||||||
private readonly IGenericRepository<Company> _CompanyRepository;
|
private readonly IGenericRepository<Company> _CompanyRepository;
|
||||||
private readonly IGenericRepository<Exper> _ExperRepository;
|
private readonly IGenericRepository<Exper> _ExperRepository;
|
||||||
|
private readonly VerificationService _VerificationService;
|
||||||
public async Task<ResponseBase<bool>> ADDExper(ADD_ExperDto dto, int CompanyID)
|
public async Task<ResponseBase<bool>> ADDExper(ADD_ExperDto dto, int CompanyID)
|
||||||
{
|
{
|
||||||
var Response = new ResponseBase<bool>();
|
var Response = new ResponseBase<bool>();
|
||||||
@@ -53,5 +56,63 @@ namespace Hushian.Application.Services
|
|||||||
|
|
||||||
return Response;
|
return Response;
|
||||||
}
|
}
|
||||||
|
//Get Info
|
||||||
|
// Update
|
||||||
|
public async Task<ResponseBase<bool>> ChangePasswordExperFromExper(ChangePasswordDto model, int ExperID)
|
||||||
|
{
|
||||||
|
ResponseBase<bool> Response = new();
|
||||||
|
|
||||||
|
var exper = await _ExperRepository.Get().FirstOrDefaultAsync(f => f.ID == ExperID);
|
||||||
|
if (string.IsNullOrEmpty(model.OldPassWord) || model.OldPassWord.GetHash() != exper.Password)
|
||||||
|
{
|
||||||
|
Response.Errors.Add("کلمه عبور فعلی صحیح نمی باشد");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
exper.Password = model.NewPassWord.GetHash();
|
||||||
|
Response.Value = await _ExperRepository.UPDATEBool(exper);
|
||||||
|
if (!Response.Value) Response.Errors.Add("خطا در ذخیره سازی");
|
||||||
|
else Response.Success = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
return Response;
|
||||||
|
}
|
||||||
|
public async Task<ResponseBase<bool>> ChangePasswordExperFromCompanyManaget(ChangePasswordDto model, int ExperID, int CompanyID)
|
||||||
|
{
|
||||||
|
ResponseBase<bool> Response = new();
|
||||||
|
var exper = await _ExperRepository.Get().FirstOrDefaultAsync(f => f.ID == ExperID);
|
||||||
|
|
||||||
|
if (exper.CompanyID == CompanyID)
|
||||||
|
{
|
||||||
|
exper.Password = model.NewPassWord.GetHash();
|
||||||
|
Response.Value = await _ExperRepository.UPDATEBool(exper);
|
||||||
|
if (!Response.Value) Response.Errors.Add("خطا در ذخیره سازی");
|
||||||
|
else Response.Success = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Response.Errors.Add("کاربری یافت نشد");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return Response;
|
||||||
|
}
|
||||||
|
public async Task<ResponseBase<int>> ForgetPasswordExper(string UserName)
|
||||||
|
{
|
||||||
|
ResponseBase<int> Response = new();
|
||||||
|
|
||||||
|
var company = await _ExperRepository.Get().FirstOrDefaultAsync(f => f.UserName == UserName);
|
||||||
|
if (company == null)
|
||||||
|
{
|
||||||
|
Response.Errors.Add("کاربری یافت نشد");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Response.Value = await _VerificationService.GenerateCodeByForgetPassword(UserName);
|
||||||
|
Response.Success = true;
|
||||||
|
}
|
||||||
|
return Response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ using Common.Enums;
|
|||||||
using Common.Models.Auth;
|
using Common.Models.Auth;
|
||||||
using Hushian.Application.Contracts.Persistence;
|
using Hushian.Application.Contracts.Persistence;
|
||||||
using Hushian.Application.Models;
|
using Hushian.Application.Models;
|
||||||
|
using Hushian.Application.Validation;
|
||||||
using Hushian.Domain.Entites;
|
using Hushian.Domain.Entites;
|
||||||
using Identity.Models;
|
using Identity.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -21,17 +22,19 @@ namespace Hushian.Application.Services
|
|||||||
{
|
{
|
||||||
private readonly IGenericRepository<VerificationCode> _VerificationCodeRepository;
|
private readonly IGenericRepository<VerificationCode> _VerificationCodeRepository;
|
||||||
private readonly IGenericRepository<Company> _CompanyRepository;
|
private readonly IGenericRepository<Company> _CompanyRepository;
|
||||||
|
private readonly IGenericRepository<Exper> _ExperRepository;
|
||||||
private readonly IMessageSender _messageSender;
|
private readonly IMessageSender _messageSender;
|
||||||
private readonly IGenericRepository<User> _UserRepository;
|
private readonly IGenericRepository<User> _UserRepository;
|
||||||
private readonly AuthService _authService;
|
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;
|
_VerificationCodeRepository = verificationCodeRepository;
|
||||||
_messageSender = messageSender;
|
_messageSender = messageSender;
|
||||||
_UserRepository = userRepository;
|
_UserRepository = userRepository;
|
||||||
_authService = authService;
|
_authService = authService;
|
||||||
_CompanyRepository = companyRepository;
|
_CompanyRepository = companyRepository;
|
||||||
|
_ExperRepository = experRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> GenerateCodeForLoginUser(string Mobile)
|
public async Task<int> GenerateCodeForLoginUser(string Mobile)
|
||||||
@@ -58,6 +61,18 @@ namespace Hushian.Application.Services
|
|||||||
});
|
});
|
||||||
return response.ID;
|
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)
|
public async Task<ResponseBase<AuthResponse>> VerificationCode(ConfirmedCodeDto model)
|
||||||
{
|
{
|
||||||
var response = new ResponseBase<AuthResponse>();
|
var response = new ResponseBase<AuthResponse>();
|
||||||
@@ -86,10 +101,40 @@ namespace Hushian.Application.Services
|
|||||||
}
|
}
|
||||||
else if (resultConf.Type == VerificationCodeType.ForgetPassword)
|
else if (resultConf.Type == VerificationCodeType.ForgetPassword)
|
||||||
{
|
{
|
||||||
if ((string.IsNullOrEmpty(model.value) || model.value.Length < 5))
|
List<string> errors = new();
|
||||||
response.Errors.Add("کلمه عبور باید بیشتر از 5 کاراکتر باشد");
|
if (model.value.CheckLawPassword(ref errors))
|
||||||
|
response.Errors.AddRange(errors);
|
||||||
else
|
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("خطای سیستمی در احراز");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user