...
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("این موبایل در سیستم تعریف شده");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@
|
||||
stroke-linejoin="round" />
|
||||
</svg>
|
||||
|
||||
<span>@userinfo.FullName</span>
|
||||
<span>@userinfo.Company.Name</span>
|
||||
</NavLink>
|
||||
</div>
|
||||
|
||||
|
@@ -5,6 +5,7 @@
|
||||
@inject UserAuthenticationDTO userinfo
|
||||
@inject HttpClient _hc
|
||||
@inject NavigationManager nav
|
||||
@inject localService localserv;
|
||||
<HeadContent>
|
||||
<link rel="canonical" href="#">
|
||||
<!-- Favicon -->
|
||||
@@ -199,6 +200,7 @@
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@functions {
|
||||
private async Task Logout()
|
||||
{
|
||||
|
@@ -1,4 +1,5 @@
|
||||
@page "/Profile"
|
||||
@page "/Profile/{from}"
|
||||
@using Front.Services
|
||||
@using Shared.DTOs
|
||||
@layout PanelLayout
|
||||
@@ -53,19 +54,19 @@
|
||||
<div class="mb-3 row">
|
||||
<label for="defaultFormControlInput" class="form-label">کلمه عبور فعلی</label>
|
||||
<div class="col-md-10">
|
||||
<InputText @bind-Value="@changepassModel.oldPass" style="text-align:center;" class="form-control" type="password" id="html5-password-input"/>
|
||||
<InputText @bind-Value="@changepassModel.oldPass" style="text-align:center;" class="form-control" type="password" id="html5-password-input1"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3 row">
|
||||
<label for="defaultFormControlInput" class="form-label">کلمه عبور جدید</label>
|
||||
<div class="col-md-10">
|
||||
<InputText style="text-align:center;" @bind-Value="@changepassModel.newPass" class="form-control" type="password" id="html5-password-input" />
|
||||
<InputText style="text-align:center;" @bind-Value="@changepassModel.newPass" class="form-control" type="password" id="html5-password-input2" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3 row">
|
||||
<label for="defaultFormControlInput" class="form-label">تکرار کلمه عبور جدید</label>
|
||||
<div class="col-md-10">
|
||||
<InputText @bind-Value="@changepassModel.renewPass" style="text-align:center;" class="form-control" type="password" id="html5-password-input" />
|
||||
<InputText @bind-Value="@changepassModel.renewPass" style="text-align:center;" class="form-control" type="password" id="html5-password-input3" />
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">ارسال</button>
|
||||
@@ -78,16 +79,16 @@
|
||||
<div class="card mb-4">
|
||||
<h5 class="card-header">تغییر نام کاربری/ موبایل</h5>
|
||||
<div class="card-body">
|
||||
<form>
|
||||
<EditForm Model="newUsername" OnSubmit="changeUserNameSubmit" FormName="changeUsername">
|
||||
<div class="mb-3 row">
|
||||
<label for="defaultFormControlInput" class="form-label">موبایل جدید</label>
|
||||
<div class="input-group input-group-merge">
|
||||
<input type="text" style="text-align:left;" id="basic-icon-default-phone" class="form-control phone-mask" placeholder="0000 000 0911" aria-label="0000 000 0911" value="@userinfo.UserName" aria-describedby="basic-icon-default-phone2">
|
||||
<InputText @bind-Value="@newUsername" type="text" style="text-align:left;" id="basic-icon-default-phone" class="form-control phone-mask" placeholder="0000 000 0911" aria-label="0000 000 0911" aria-describedby="basic-icon-default-phone2"/>
|
||||
<span id="basic-icon-default-phone2" class="input-group-text"><i class="bx bx-phone"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">ارسال</button>
|
||||
</form>
|
||||
</EditForm>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -98,16 +99,16 @@
|
||||
<div class="card mb-4">
|
||||
<h5 class="card-header">تغییر نام</h5>
|
||||
<div class="card-body">
|
||||
<form>
|
||||
<EditForm Model="newname" OnSubmit="changeNameSubmit" FormName="changename">
|
||||
<div class="mb-3 row">
|
||||
<label for="defaultFormControlInput" class="form-label">نام جدید</label>
|
||||
<div class="input-group input-group-merge">
|
||||
<span id="basic-icon-default-company2" class="input-group-text"><i class="bx bx-buildings"></i></span>
|
||||
<input style="text-align:right;" type="text" id="basic-icon-default-company" value="@userinfo.Company.Name" class="form-control" placeholder="@userinfo.Company.Name" aria-label="@userinfo.Company.Name" aria-describedby="basic-icon-default-company2">
|
||||
<InputText @bind-Value="@newname" style="text-align:right;" type="text" id="basic-icon-default-company" class="form-control" placeholder="@userinfo.Company.Name" aria-label="@userinfo.Company.Name" aria-describedby="basic-icon-default-company2"/>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">ارسال</button>
|
||||
</form>
|
||||
</EditForm>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -118,17 +119,37 @@
|
||||
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string from { get; set; } = "";
|
||||
|
||||
public string _src { get; set; }
|
||||
private long maxFileSize = 1024 * 15;
|
||||
[SupplyParameterFromForm]
|
||||
public ChangePasswordDto changepassModel { get; set; }
|
||||
[SupplyParameterFromForm]
|
||||
public string newUsername { get; set; }
|
||||
[SupplyParameterFromForm]
|
||||
public string newname { get; set; }
|
||||
// alert
|
||||
AlertColor alertColor = AlertColor.Primary;
|
||||
IconName alertIconName = IconName.CheckCircleFill;
|
||||
bool Hidealert = true;
|
||||
string alertMessage = "";
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
if (from == "Verification")
|
||||
{
|
||||
ShowSuccessAlert("تغییر کاربری با موفقیت انجام شد");
|
||||
}
|
||||
|
||||
protected override void OnInitialized() => changepassModel ??= new();
|
||||
await base.OnParametersSetAsync();
|
||||
}
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
newname ??= userinfo.Company.Name;
|
||||
newUsername ??= userinfo.UserName;
|
||||
changepassModel ??= new();
|
||||
}
|
||||
}
|
||||
@functions{
|
||||
private void ShowDangerAlert(string msg)
|
||||
@@ -163,6 +184,54 @@
|
||||
ShowDangerAlert(errors[0]);
|
||||
}
|
||||
}
|
||||
private async Task changeUserNameSubmit()
|
||||
{
|
||||
if (newUsername != userinfo.UserName)
|
||||
{
|
||||
var request = await _hc.Get($"User/ChangeUserName/{newUsername}");
|
||||
if (request.IsSuccessStatusCode)
|
||||
{
|
||||
var VerificationID = await request.Content.ReadFromJsonAsync<int>();
|
||||
_hc._nav.NavigateTo($"Verification/{VerificationID}");
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var errors = await request.Content.ReadFromJsonAsync<List<string>>();
|
||||
ShowDangerAlert(errors[0]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private async Task changeNameSubmit()
|
||||
{
|
||||
if (newname != userinfo.Company.Name)
|
||||
{
|
||||
var request = await _hc.Get($"Company/ChangeName/{newname}");
|
||||
if (request.IsSuccessStatusCode)
|
||||
{
|
||||
if (await request.Content.ReadFromJsonAsync<bool>())
|
||||
{
|
||||
userinfo.FullName= userinfo.Company.Name = newname;
|
||||
ShowSuccessAlert("تغییر نام با موفقیت انجام شد");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var errors = await request.Content.ReadFromJsonAsync<List<string>>();
|
||||
ShowDangerAlert(errors[0]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private async Task changePic(InputFileChangeEventArgs e){
|
||||
if (e.GetMultipleFiles()[0].Size <= maxFileSize)
|
||||
{
|
||||
@@ -188,7 +257,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowDangerAlert ( "خطایی در اجرای عملیات رخ داده");
|
||||
ShowDangerAlert( "خطایی در اجرای عملیات رخ داده");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,4 +266,5 @@
|
||||
ShowDangerAlert ( "حجم فایل بیشتر از حد مجاز می باشد");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
@page "/Verification/{ID:int}"
|
||||
@inject HttpClient _hc
|
||||
@inject NavigationManager nav
|
||||
@inject UserAuthenticationDTO userinfo
|
||||
<PageTitle>احراز هویت</PageTitle>
|
||||
<main>
|
||||
|
||||
@@ -123,7 +124,8 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowDangerAlert(await request.Content.ReadFromJsonAsync<string>());
|
||||
var listerror = await request.Content.ReadFromJsonAsync<List<string>>();
|
||||
ShowDangerAlert(listerror[0]);
|
||||
}
|
||||
|
||||
|
||||
@@ -146,9 +148,16 @@
|
||||
nav.NavigateTo("/Sign-in/VerificationRegister");
|
||||
else if (VerificationCodeModel.Type == "ForgetPassword")
|
||||
nav.NavigateTo("/Sign-in/VerificationFrogetPass");
|
||||
else if (VerificationCodeModel.Type == "ChangeUserName")
|
||||
{
|
||||
userinfo.UserName = VerificationCodeModel.val;
|
||||
|
||||
nav.NavigateTo("/Profile/Verification");
|
||||
}
|
||||
|
||||
else
|
||||
nav.NavigateTo("/");
|
||||
|
||||
nav.NavigateTo("/");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -158,7 +167,8 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowDangerAlert(await request.Content.ReadFromJsonAsync<string>());
|
||||
var listerror = await request.Content.ReadFromJsonAsync<List<string>>();
|
||||
ShowDangerAlert(listerror[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +191,8 @@
|
||||
{
|
||||
if (!successfull)
|
||||
await _hc.DeleteAsync($"Verification/Remove/{VerificationCodeModel?.ID}");
|
||||
|
||||
if (VerificationCodeModel.Type == "ChangeUserName")
|
||||
nav.NavigateTo("/Profile");
|
||||
nav.NavigateTo("/");
|
||||
}
|
||||
}
|
||||
|
@@ -17,9 +17,9 @@ builder.Services.AddScoped<HttpClientController>();
|
||||
builder.Services.AddScoped(sp => new UserAuthenticationDTO());
|
||||
|
||||
|
||||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7075/api/") });
|
||||
//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7075/api/") });
|
||||
|
||||
//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5271/api/") });
|
||||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5271/api/") });
|
||||
|
||||
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("fa-Ir");
|
||||
|
||||
|
Reference in New Issue
Block a user