...
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Service">
|
||||
<HintPath>..\..\Dlls\Service.dll</HintPath>
|
||||
<HintPath>..\..\..\LocalGit\TaxPayerTools\Service\bin\Debug\Service.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
|
@@ -60,7 +60,7 @@ namespace Back.Controllers
|
||||
[HttpPost("CreateCsrAndPrivateKey")]
|
||||
public async Task<ActionResult<TaxToolsDTO>> CreateCsrAndPrivateKey(CsrPrivateKeyDto model)
|
||||
{
|
||||
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(model.Mobile,false));
|
||||
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(model.Mobile, ActionMobileValidation.No));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
return Ok(await _sBase.CreateCsrAndPrivateKey(model));
|
||||
@@ -164,7 +164,7 @@ namespace Back.Controllers
|
||||
// Type = "catch"
|
||||
//};
|
||||
//_contextMongodb.InsertItem(log);
|
||||
return BadRequest("خطای سیستمی رخ داده");
|
||||
return BadRequest(new List<string> { "خطای سیستمی رخ داده" });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -172,7 +172,7 @@ namespace Back.Controllers
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<string>> ForgetPassWord(ForgetPasswordItem Item)
|
||||
{
|
||||
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(Item.Username, true));
|
||||
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(Item.Username, ActionMobileValidation.ExistMobile));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
|
@@ -12,18 +12,37 @@ namespace Back.Controllers
|
||||
public class CompanyController : ControllerBase
|
||||
{
|
||||
private readonly servCompany _servCompany;
|
||||
public CompanyController(servCompany servCompany)
|
||||
private readonly servUser _servUser;
|
||||
public CompanyController(servCompany servCompany, servUser servUser)
|
||||
{
|
||||
_servUser = servUser;
|
||||
_servCompany = servCompany;
|
||||
}
|
||||
[HttpPost("ChangeLogo")]
|
||||
public async Task<ActionResult<bool>> ChangeLogo(byte[] logo)
|
||||
{
|
||||
//var result = await _sBase.ReadPublicKeyFromCER(modelfromBase64);
|
||||
//if (result.type == "error")
|
||||
// return BadRequest();
|
||||
|
||||
return Ok();
|
||||
if (logo == null)
|
||||
return BadRequest();
|
||||
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
var UserID = claim.Value;
|
||||
var result = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
var company = result?.RolUsers.First().Company;
|
||||
company.Logo= logo;
|
||||
return Ok(await _servCompany.AddORUpdateCompanyBoolResult(company));
|
||||
}
|
||||
[HttpGet("ChangeName/{name}")]
|
||||
public async Task<ActionResult<bool>> ChangeName(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name) || name.Length<=3)
|
||||
return BadRequest(new List<string> { "نام صحیح نمی باشد"});
|
||||
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
var UserID = claim.Value;
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
var company = user?.RolUsers.First().Company;
|
||||
company.Name = name;
|
||||
user.Fullname=name;
|
||||
await _servUser.UpdateUser(user);
|
||||
return Ok(await _servCompany.AddORUpdateCompanyBoolResult(company));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ namespace Back.Controllers
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<int>> NewTicketNoAuthentication(CTicketNoAuthenticationDto item)
|
||||
{
|
||||
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(item.Mobile,false));
|
||||
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(item.Mobile,ActionMobileValidation.No));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
using Back.Services;
|
||||
using Back.Data.Models;
|
||||
using Back.Services;
|
||||
using Back.Validations;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -12,11 +14,19 @@ namespace Back.Controllers
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
private readonly servUser _servUser;
|
||||
public UserController(servUser servUser)
|
||||
private readonly servCompany _servCompany;
|
||||
private readonly MobileValidation _mobilevalidation;
|
||||
private readonly ServValidatinMsg _servValidatinMsg;
|
||||
private readonly servSendMsg _servSendMsg;
|
||||
public UserController(servUser servUser, MobileValidation mobilevalidation, servCompany servCompany
|
||||
, ServValidatinMsg servValidatinMsg, servSendMsg servSendMsg)
|
||||
{
|
||||
|
||||
_servUser = servUser;
|
||||
|
||||
_mobilevalidation = mobilevalidation;
|
||||
_servCompany = servCompany;
|
||||
_servValidatinMsg = servValidatinMsg;
|
||||
_servSendMsg = servSendMsg;
|
||||
}
|
||||
[HttpPost("authenticate")]
|
||||
[AllowAnonymous]
|
||||
@@ -50,7 +60,27 @@ namespace Back.Controllers
|
||||
return Ok(await _servUser.ChangePassword(item.newPass.Trim(), Convert.ToInt32(UserID)));
|
||||
|
||||
}
|
||||
[HttpGet("ChangeUserName/{newUsername}")]
|
||||
public async Task<ActionResult<bool>> ChangeUserName(string newUsername)
|
||||
{
|
||||
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(newUsername, ActionMobileValidation.nonExistMobile));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
var UserID = HttpContext.User.Claims.First(c => c.Type == "UserID").Value;
|
||||
|
||||
var ID = await _servValidatinMsg.GenerateCode(new VerificationCode
|
||||
{
|
||||
prm = UserID,
|
||||
val = newUsername,
|
||||
Type = "ChangeUserName"
|
||||
});
|
||||
|
||||
_servSendMsg.Authentication(newUsername, ID.ToString());
|
||||
return Ok(ID);
|
||||
|
||||
// return Ok(await _servUser.ChangeUserName(newUsername, Convert.ToInt32(UserID)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -69,8 +69,14 @@ namespace Back.Controllers
|
||||
_servSendMsg.Authentication(_getVerificationValidation.verificationCode.prm, ID.ToString());
|
||||
break;
|
||||
|
||||
|
||||
case "ChangeUserName":
|
||||
_servSendMsg.Authentication(_getVerificationValidation.verificationCode.val, ID.ToString());
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
return BadRequest("این نوع احراز تعریف نشده");
|
||||
return BadRequest(new List<string> { "این نوع احراز تعریف نشده" });
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
@@ -79,7 +85,7 @@ namespace Back.Controllers
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<bool>> Submit(VerificationCodeDto item)
|
||||
{
|
||||
var VerificationCode= await _servValidatinMsg.GetVerificationCode(item.ID);
|
||||
var VerificationCode= await _servValidatinMsg.GetVerificationCodeByID(item.ID);
|
||||
if (VerificationCode==null)
|
||||
return NotFound("آیتمی یافت نشد");
|
||||
|
||||
@@ -101,8 +107,12 @@ namespace Back.Controllers
|
||||
//else return BadRequest();
|
||||
break;
|
||||
|
||||
case "ChangeUserName":
|
||||
Sucstatus = await _servUser.ChangeUserName(VerificationCode.val, Convert.ToInt32(VerificationCode.prm));
|
||||
break;
|
||||
|
||||
default:
|
||||
return BadRequest("این نوع احراز تعریف نشده");
|
||||
return BadRequest(new List<string> { "این نوع احراز تعریف نشده" });
|
||||
}
|
||||
|
||||
if (Sucstatus)
|
||||
@@ -110,17 +120,17 @@ namespace Back.Controllers
|
||||
|
||||
return Ok(Sucstatus);
|
||||
}
|
||||
else return BadRequest("اطلاعات شما منطبق با سامانه نیست");
|
||||
else return BadRequest(new List<string> { "اطلاعات شما منطبق با سامانه نیست" });
|
||||
|
||||
}
|
||||
else return BadRequest("کد احراز صحیح نمی باشد");
|
||||
else return BadRequest(new List<string> { "کد احراز صحیح نمی باشد" });
|
||||
|
||||
}
|
||||
[HttpDelete("Remove/{ID}")]
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<bool>> Remove(int ID)
|
||||
{
|
||||
var VerificationCode = await _servValidatinMsg.GetVerificationCode(ID);
|
||||
var VerificationCode = await _servValidatinMsg.GetVerificationCodeByID(ID);
|
||||
await _servValidatinMsg.Delete(VerificationCode);
|
||||
return NoContent();
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ namespace Back.Data.Infrastructure.Repository
|
||||
{
|
||||
public class RepositoryBase<T> : IAsyncRepository<T> where T : class
|
||||
{
|
||||
protected readonly SqlDbContext _dbContext;
|
||||
public readonly SqlDbContext _dbContext;
|
||||
private DbSet<T> _query;
|
||||
public RepositoryBase(SqlDbContext dbContext)
|
||||
{
|
||||
|
@@ -22,6 +22,7 @@ builder.Services.AddDbContext<SqlDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("Base"));
|
||||
});
|
||||
builder.Services.AddScoped(typeof(IAsyncRepository<>), typeof(RepositoryBase<>));
|
||||
builder.Services.AddScoped(typeof(RepositoryBase<>), typeof(RepositoryBase<>));
|
||||
builder.Services.AddScoped<Back.Services.ServBase>();
|
||||
builder.Services.AddScoped<MobileValidation> ();
|
||||
builder.Services.AddScoped<Service.Main>();
|
||||
|
@@ -28,6 +28,10 @@ namespace Back.Services
|
||||
|
||||
}
|
||||
public async Task<VerificationCode> GetVerificationCode(int ID)
|
||||
{
|
||||
return await _verificationCodeRepo.Get(w => w.Code == ID).FirstOrDefaultAsync();
|
||||
}
|
||||
public async Task<VerificationCode> GetVerificationCodeByID(int ID)
|
||||
{
|
||||
return await _verificationCodeRepo.Get(w => w.ID == ID).FirstOrDefaultAsync();
|
||||
}
|
||||
@@ -68,7 +72,7 @@ namespace Back.Services
|
||||
public async Task<int> GenerateCode(VerificationCode code)
|
||||
{
|
||||
code.Code = Random.Shared.Next(1000, 9000);
|
||||
while (await GetVerificationCode(code.ID) != null)
|
||||
while (await GetVerificationCode(code.Code) != null)
|
||||
code.Code = Random.Shared.Next(1000, 9000);
|
||||
|
||||
|
||||
|
@@ -100,11 +100,59 @@ namespace Back.Services
|
||||
|
||||
}
|
||||
}
|
||||
public async Task<bool> ExistMobileAndCompanyIsActive(string mobile)
|
||||
public async Task<bool> AddORUpdateCompanyBoolResult(Company item)
|
||||
{
|
||||
return await _repoCompany.GetAll().AnyAsync(w => w.Mobile == mobile && w.IsActive);
|
||||
|
||||
try
|
||||
{
|
||||
//SysLog log = new SysLog()
|
||||
//{
|
||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddORUpdateCompany",
|
||||
// Value = "*" + JsonConvert.SerializeObject(item),
|
||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||
// Type = "User"
|
||||
//};
|
||||
//_contextMongodb.InsertItem(log);
|
||||
|
||||
if (item.ID == null || item.ID == 0)
|
||||
{
|
||||
return await _repoCompany.AddBoolResultAsync(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
return await _repoCompany.UpdateAsync(item);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//SysLog log = new SysLog()
|
||||
//{
|
||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddORUpdateCompany",
|
||||
// Value = ex.Message,
|
||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||
// Type = "catch"
|
||||
//};
|
||||
//_contextMongodb.InsertItem(log);
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> ExistMobileInCompany(string mobile,bool IsActive=true)
|
||||
{
|
||||
var resquest= _repoCompany.GetAll().Where(w => w.Mobile == mobile );
|
||||
if (IsActive)
|
||||
resquest = resquest.Where(w => w.IsActive);
|
||||
|
||||
return await resquest.AnyAsync();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using Back.Common;
|
||||
using Back.Data.Contracts;
|
||||
using Back.Data.Infrastructure.Repository;
|
||||
using Back.Data.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
@@ -17,16 +18,19 @@ namespace Back.Services
|
||||
|
||||
private readonly servNotification _servNotification;
|
||||
private readonly IAsyncRepository<User> _RepoUser;
|
||||
private readonly RepositoryBase<Company> _RepoCompany;
|
||||
private readonly IAsyncRepository<PermissionPeriod> _RepoPermissionPeriod;
|
||||
public servUser(IConfiguration configuration
|
||||
, servNotification servNotification
|
||||
, IAsyncRepository<User> RepoUser
|
||||
, IAsyncRepository<PermissionPeriod> RepoPermissionPeriod)
|
||||
, IAsyncRepository<PermissionPeriod> RepoPermissionPeriod
|
||||
, RepositoryBase<Company> repoCompany)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_servNotification = servNotification;
|
||||
_RepoUser = RepoUser;
|
||||
_RepoPermissionPeriod = RepoPermissionPeriod;
|
||||
_RepoCompany = repoCompany;
|
||||
}
|
||||
public async Task<User?> GetUserByUserNameAndPassword(string UserName, string Password)
|
||||
{
|
||||
@@ -37,30 +41,30 @@ namespace Back.Services
|
||||
// .ThenInclude(ti=>ti.Company)
|
||||
//.ThenInclude(ti => ti.PermissionPeriods)
|
||||
// .ThenInclude(ti => ti.Permission)
|
||||
.Include(ti=>ti.RolUsers)
|
||||
.Include(ti => ti.RolUsers)
|
||||
.ThenInclude(ti => ti.Company)
|
||||
//.ThenInclude(ti => ti.PermissionPeriods)
|
||||
// .ThenInclude(ti => ti.CalculationType)
|
||||
//.ThenInclude(ti => ti.PermissionPeriods)
|
||||
// .ThenInclude(ti => ti.CalculationType)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
public async Task<UserAuthenticationDTO?> UserAuthentication(string UserNameORUserID, string Password="",bool newtoken=true)
|
||||
public async Task<UserAuthenticationDTO?> UserAuthentication(string UserNameORUserID, string Password = "", bool newtoken = true)
|
||||
{
|
||||
UserAuthenticationDTO ret = new UserAuthenticationDTO();
|
||||
User? user = null;
|
||||
|
||||
if (string.IsNullOrEmpty(Password) && int.TryParse(UserNameORUserID,out int UserID))
|
||||
if (string.IsNullOrEmpty(Password) && int.TryParse(UserNameORUserID, out int UserID))
|
||||
user = await GetUserByUserID(UserID);
|
||||
else
|
||||
user =await GetUserByUserNameAndPassword(UserNameORUserID, Password);
|
||||
user = await GetUserByUserNameAndPassword(UserNameORUserID, Password);
|
||||
|
||||
if (user == null)
|
||||
return null;
|
||||
|
||||
string Jwt_Lifetime_Minutes = await GetJwt_Lifetime_Minutes();
|
||||
ret.UserName = user.Username;
|
||||
ret.Token =newtoken ? await CerateToken(user.ID, user.Username, Jwt_Lifetime_Minutes) : user.Token;
|
||||
ret.Token = newtoken ? await CerateToken(user.ID, user.Username, Jwt_Lifetime_Minutes) : user.Token;
|
||||
ret.FullName = user.Fullname;
|
||||
ret.Photo = user.Photo==null ? null : Convert.ToBase64String(user.Photo);
|
||||
ret.Photo = user.Photo == null ? null : Convert.ToBase64String(user.Photo);
|
||||
//foreach (var rol in user.RolUsers)
|
||||
//{
|
||||
// if (!rol.Company.IsActive)
|
||||
@@ -132,8 +136,8 @@ namespace Back.Services
|
||||
|
||||
};
|
||||
var dt = newtoken ? DateTime.Now : user.DateLastLogin.ToMiladiByTime();
|
||||
ret.enterDate= dt;
|
||||
ret.exitDate= dt.AddMinutes(Convert.ToInt32(Jwt_Lifetime_Minutes));
|
||||
ret.enterDate = dt;
|
||||
ret.exitDate = dt.AddMinutes(Convert.ToInt32(Jwt_Lifetime_Minutes));
|
||||
return ret;
|
||||
}
|
||||
public async Task<User> AddUser(User item)
|
||||
@@ -151,9 +155,9 @@ namespace Back.Services
|
||||
}
|
||||
public async Task<bool> ExistUser(string UserName)
|
||||
{
|
||||
|
||||
return await _RepoUser.GetAll().AnyAsync(w=>w.Username==UserName);
|
||||
|
||||
|
||||
return await _RepoUser.GetAll().AnyAsync(w => w.Username == UserName);
|
||||
|
||||
}
|
||||
public async Task<User> GetUserByUsername(string UserName)
|
||||
{
|
||||
@@ -166,53 +170,53 @@ namespace Back.Services
|
||||
.ThenInclude(ti => ti.Company)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
public async Task SetTokenAndDateLogininDB(int UserID,string Token)
|
||||
public async Task SetTokenAndDateLogininDB(int UserID, string Token)
|
||||
{
|
||||
var user = await GetUserByUserID(UserID);
|
||||
if (user != null)
|
||||
{
|
||||
user.Token = Token;
|
||||
user.DateLastLogin=DateTime.Now.ConvertMiladiToShamsiByTime();
|
||||
await _RepoUser.UpdateAsync(user);
|
||||
user.DateLastLogin = DateTime.Now.ConvertMiladiToShamsiByTime();
|
||||
await _RepoUser.UpdateAsync(user);
|
||||
}
|
||||
}
|
||||
public async Task<bool> ChangePasswordByMobile(string mobile, string newpassword)
|
||||
{
|
||||
var user =await GetUserByUsername(mobile);
|
||||
var user = await GetUserByUsername(mobile);
|
||||
if (user == null)
|
||||
return false;
|
||||
user.Password = newpassword.encrypted();
|
||||
return await _RepoUser.UpdateAsync(user);
|
||||
return await _RepoUser.UpdateAsync(user);
|
||||
}
|
||||
public async Task<DashBoardDTO> GetDashBoard(int CompanyID,int UserID)
|
||||
public async Task<DashBoardDTO> GetDashBoard(int CompanyID, int UserID)
|
||||
{
|
||||
DashBoardDTO request=new DashBoardDTO();
|
||||
var period=await _RepoPermissionPeriod
|
||||
.Get(w=>w.CompanyID==CompanyID && (!w.IsLocked.HasValue || !w.IsLocked.Value)).ToListAsync();
|
||||
DashBoardDTO request = new DashBoardDTO();
|
||||
var period = await _RepoPermissionPeriod
|
||||
.Get(w => w.CompanyID == CompanyID && (!w.IsLocked.HasValue || !w.IsLocked.Value)).ToListAsync();
|
||||
foreach (var item in period)
|
||||
{
|
||||
request.AlistofServices.Add(new ServiceInDashBoardDTO
|
||||
{
|
||||
PermissionID= item.PermissionID,
|
||||
PermissionID = item.PermissionID,
|
||||
PermissionName = item.Permission.Title,
|
||||
CalTypeID= item.CalculationTypeID,
|
||||
CalTypeID = item.CalculationTypeID,
|
||||
CalTypeTitle = item.CalculationType.Title,
|
||||
Total = item.CalculationTypeID == 1 ? item.TotalAmount.ToString() :"",
|
||||
Total = item.CalculationTypeID == 1 ? item.TotalAmount.ToString() : "",
|
||||
Remaining = item.CalculationTypeID == 1 ? item.RemainingAmount.ToString()
|
||||
: item.CalculationTypeID== 2 ? "" : item.RemainingAmount.ToString().ShamciToFormatShamci()
|
||||
: item.CalculationTypeID == 2 ? "" : item.RemainingAmount.ToString().ShamciToFormatShamci()
|
||||
});
|
||||
}
|
||||
request.LastLoginDate= _RepoUser.Get(w=>w.ID==UserID).Select(s=>s.DateLastLogin).FirstOrDefault();
|
||||
if(!string.IsNullOrEmpty(request.LastLoginDate))
|
||||
request.LastLoginDate = _RepoUser.Get(w => w.ID == UserID).Select(s => s.DateLastLogin).FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(request.LastLoginDate))
|
||||
request.LastLoginDate.ShamciToFormatShamci();
|
||||
|
||||
var user = await GetUserByUserID(UserID);
|
||||
if (user.Mobile == user.Username)
|
||||
request.Warning.Add(new AlertDTO { Status=0,Message= "موبایل و نام کاربری بهتر است شبیه هم نباشند" });
|
||||
request.Warning.Add(new AlertDTO { Status = 0, Message = "موبایل و نام کاربری بهتر است شبیه هم نباشند" });
|
||||
if (user.Mobile.encrypted() == user.Password)
|
||||
request.Warning.Add(new AlertDTO { Status = 0, Message = "موبایل و کلمه عبور بهتر است شبیه هم نباشند" });
|
||||
var Company = user.RolUsers.Where(w=>w.CompanyID== CompanyID).Select(s=>s.Company).FirstOrDefault();
|
||||
if (Company!=null)
|
||||
var Company = user.RolUsers.Where(w => w.CompanyID == CompanyID).Select(s => s.Company).FirstOrDefault();
|
||||
if (Company != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Company.Email) || string.IsNullOrEmpty(Company.Phone)
|
||||
|| string.IsNullOrEmpty(Company.EconomicCode) || string.IsNullOrEmpty(Company.UniqeMemory)
|
||||
@@ -221,15 +225,15 @@ namespace Back.Services
|
||||
request.Warning.Add(new AlertDTO { Status = 0, Message = "بهتر است اطلاعات شرکت بروزرسانی شود" });
|
||||
}
|
||||
}
|
||||
var nots= await _servNotification.GetNotifications();
|
||||
var nots = await _servNotification.GetNotifications();
|
||||
if (nots.Any())
|
||||
request.Notifications= nots.Select(s=>new AlertDTO
|
||||
request.Notifications = nots.Select(s => new AlertDTO
|
||||
{
|
||||
Message=s.Message,
|
||||
Status=s.Type,
|
||||
Path=s.Path,
|
||||
ViewSize=s.ViewSize
|
||||
}).ToList();
|
||||
Message = s.Message,
|
||||
Status = s.Type,
|
||||
Path = s.Path,
|
||||
ViewSize = s.ViewSize
|
||||
}).ToList();
|
||||
return request;
|
||||
}
|
||||
public async Task<User> UpdateUser(User user)
|
||||
@@ -253,10 +257,54 @@ namespace Back.Services
|
||||
user.Password = newPass.encrypted();
|
||||
return await _RepoUser.UpdateAsync(user);
|
||||
}
|
||||
public async Task<bool> PermissionChangePassword(string oldPass,int UserID)
|
||||
public async Task<bool> ChangeUserName(string newUserName, int UserID)
|
||||
{
|
||||
return await _RepoUser.GetAll().AnyAsync(w => w.ID == UserID && w.Password==oldPass.encrypted() && w.IsActive);
|
||||
var user = await GetUserByUserID(UserID);
|
||||
if (user == null)
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
using var transaction = _RepoCompany._dbContext.Database.BeginTransaction();
|
||||
var company = user.RolUsers.First().Company;
|
||||
company.Mobile = newUserName;
|
||||
if (await _RepoCompany.UpdateAsync(company))
|
||||
{
|
||||
user.Username = newUserName;
|
||||
user.Mobile = newUserName;
|
||||
if (await _RepoUser.UpdateAsync(user))
|
||||
{
|
||||
transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
// return Ok(await _servCompany.AddORUpdateCompanyBoolResult(company));
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
}
|
||||
public async Task<bool> PermissionChangePassword(string oldPass, int UserID)
|
||||
{
|
||||
return await _RepoUser.GetAll().AnyAsync(w => w.ID == UserID && w.Password == oldPass.encrypted() && w.IsActive);
|
||||
|
||||
}
|
||||
public async Task<bool> ExistMobileInUser(string mobile, bool IsActive = true)
|
||||
{
|
||||
var resquest = _RepoUser.Get(w => w.Mobile == mobile || w.Username == mobile);
|
||||
if (IsActive)
|
||||
resquest = resquest.Where(w => w.IsActive);
|
||||
|
||||
return await resquest.AnyAsync();
|
||||
}
|
||||
//--------internal
|
||||
private async Task<string> GetJwt_Lifetime_Minutes()
|
||||
@@ -286,7 +334,7 @@ namespace Back.Services
|
||||
|
||||
return Jwt_Lifetime_Minutes;
|
||||
}
|
||||
private async Task<string> CerateToken(int UserId, string UserName,string Jwt_Lifetime_Minutes)
|
||||
private async Task<string> CerateToken(int UserId, string UserName, string Jwt_Lifetime_Minutes)
|
||||
{
|
||||
#region CreateToken
|
||||
var securityKey = new SymmetricSecurityKey(
|
||||
@@ -303,10 +351,10 @@ namespace Back.Services
|
||||
Fixedvalues.Issuer, Fixedvalues.Audience, claimsForToken,
|
||||
DateTime.Now, DateTime.Now.AddMinutes(Convert.ToInt32(Jwt_Lifetime_Minutes)), signingCredentials);
|
||||
|
||||
|
||||
|
||||
string Token = new JwtSecurityTokenHandler()
|
||||
.WriteToken(jwtSecurityToke);
|
||||
await SetTokenAndDateLogininDB(UserId, Token);
|
||||
await SetTokenAndDateLogininDB(UserId, Token);
|
||||
//_contextMongodb.InsertItem(new SysLog()
|
||||
//{
|
||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||
|
@@ -14,7 +14,7 @@ namespace Back.Validations
|
||||
.NotNull().WithMessage("موبایل نمی تواند باشد")
|
||||
.Length(11).WithMessage("فرمت موبایل صحیح نمی باشد")
|
||||
.Must(m => m.StartsWith("09")).WithMessage("فرمت موبایل صحیح نمی باشد")
|
||||
.Must(mo=> !servCompany.ExistMobileAndCompanyIsActive(mo).Result)
|
||||
.Must(mo=> !servCompany.ExistMobileInCompany(mo).Result)
|
||||
.WithMessage("این موبایل قبلا ثبت شده");
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ namespace Back.Validations
|
||||
CascadeMode = CascadeMode.Stop;
|
||||
RuleFor(model => model)
|
||||
.Custom((model, context) => {
|
||||
verificationCode= _servValidatinMsg.GetVerificationCode(model).Result;
|
||||
verificationCode= _servValidatinMsg.GetVerificationCodeByID(model).Result;
|
||||
if (verificationCode==null)
|
||||
context.AddFailure("کد یافت نشد");
|
||||
|
||||
|
@@ -5,9 +5,16 @@ using System;
|
||||
|
||||
namespace Back.Validations
|
||||
{
|
||||
public class MobileValidation : AbstractValidator<Tuple<string,bool>>
|
||||
public enum ActionMobileValidation
|
||||
{
|
||||
public MobileValidation(servCompany servCompany)
|
||||
No,
|
||||
ExistMobile,
|
||||
nonExistMobile,
|
||||
|
||||
}
|
||||
public class MobileValidation : AbstractValidator<Tuple<string, ActionMobileValidation>>
|
||||
{
|
||||
public MobileValidation(servCompany servCompany,servUser servUser)
|
||||
{
|
||||
CascadeMode = CascadeMode.Stop;
|
||||
RuleFor(m => m.Item1)
|
||||
@@ -17,17 +24,27 @@ namespace Back.Validations
|
||||
.Must(m => m.StartsWith("09")).WithMessage("فرمت موبایل صحیح نمی باشد");
|
||||
RuleFor(m => m)
|
||||
.Custom((model, context) => {
|
||||
if (model.Item2)
|
||||
if (model.Item2== ActionMobileValidation.ExistMobile)
|
||||
{
|
||||
if (!servCompany.ExistMobileAndCompanyIsActive(model.Item1).Result)
|
||||
if (!servCompany.ExistMobileInCompany(model.Item1).Result)
|
||||
{
|
||||
context.AddFailure("این موبایل یافت نشد");
|
||||
}
|
||||
}
|
||||
|
||||
if (model.Item2 == ActionMobileValidation.nonExistMobile)
|
||||
{
|
||||
if (servCompany.ExistMobileInCompany(model.Item1,false).Result)
|
||||
context.AddFailure("این موبایل در سیستم تعریف شده");
|
||||
|
||||
else
|
||||
{
|
||||
if (servUser.ExistMobileInUser(model.Item1, false).Result)
|
||||
context.AddFailure("این موبایل در سیستم تعریف شده");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user