diff --git a/Back/Back.csproj b/Back/Back.csproj
index 69ae328..18bc412 100644
--- a/Back/Back.csproj
+++ b/Back/Back.csproj
@@ -34,7 +34,7 @@
- ..\..\Dlls\Service.dll
+ ..\..\..\LocalGit\TaxPayerTools\Service\bin\Debug\Service.dll
diff --git a/Back/Controllers/BaseController.cs b/Back/Controllers/BaseController.cs
index ac83cc0..a3fcff2 100644
--- a/Back/Controllers/BaseController.cs
+++ b/Back/Controllers/BaseController.cs
@@ -60,7 +60,7 @@ namespace Back.Controllers
[HttpPost("CreateCsrAndPrivateKey")]
public async Task> 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 { "خطای سیستمی رخ داده" });
}
}
@@ -172,7 +172,7 @@ namespace Back.Controllers
[AllowAnonymous]
public async Task> 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());
diff --git a/Back/Controllers/CompanyController.cs b/Back/Controllers/CompanyController.cs
index 0491279..f2f583d 100644
--- a/Back/Controllers/CompanyController.cs
+++ b/Back/Controllers/CompanyController.cs
@@ -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> 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> ChangeName(string name)
+ {
+ if (string.IsNullOrEmpty(name) || name.Length<=3)
+ return BadRequest(new List { "نام صحیح نمی باشد"});
+ 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));
}
}
}
diff --git a/Back/Controllers/TicketController.cs b/Back/Controllers/TicketController.cs
index 4212ade..b3a5166 100644
--- a/Back/Controllers/TicketController.cs
+++ b/Back/Controllers/TicketController.cs
@@ -34,7 +34,7 @@ namespace Back.Controllers
[AllowAnonymous]
public async Task> 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());
diff --git a/Back/Controllers/UserController.cs b/Back/Controllers/UserController.cs
index 72a3e99..29bf20e 100644
--- a/Back/Controllers/UserController.cs
+++ b/Back/Controllers/UserController.cs
@@ -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> 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)));
+ }
diff --git a/Back/Controllers/VerificationController.cs b/Back/Controllers/VerificationController.cs
index 1fed6bf..da8635f 100644
--- a/Back/Controllers/VerificationController.cs
+++ b/Back/Controllers/VerificationController.cs
@@ -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 { "این نوع احراز تعریف نشده" });
}
return NoContent();
@@ -79,7 +85,7 @@ namespace Back.Controllers
[AllowAnonymous]
public async Task> 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 { "این نوع احراز تعریف نشده" });
}
if (Sucstatus)
@@ -110,17 +120,17 @@ namespace Back.Controllers
return Ok(Sucstatus);
}
- else return BadRequest("اطلاعات شما منطبق با سامانه نیست");
+ else return BadRequest(new List { "اطلاعات شما منطبق با سامانه نیست" });
}
- else return BadRequest("کد احراز صحیح نمی باشد");
+ else return BadRequest(new List { "کد احراز صحیح نمی باشد" });
}
[HttpDelete("Remove/{ID}")]
[AllowAnonymous]
public async Task> Remove(int ID)
{
- var VerificationCode = await _servValidatinMsg.GetVerificationCode(ID);
+ var VerificationCode = await _servValidatinMsg.GetVerificationCodeByID(ID);
await _servValidatinMsg.Delete(VerificationCode);
return NoContent();
}
diff --git a/Back/Data/Infrastructure/Repository/RepositoryBase.cs b/Back/Data/Infrastructure/Repository/RepositoryBase.cs
index 7f8d859..b7ad7da 100644
--- a/Back/Data/Infrastructure/Repository/RepositoryBase.cs
+++ b/Back/Data/Infrastructure/Repository/RepositoryBase.cs
@@ -16,7 +16,7 @@ namespace Back.Data.Infrastructure.Repository
{
public class RepositoryBase : IAsyncRepository where T : class
{
- protected readonly SqlDbContext _dbContext;
+ public readonly SqlDbContext _dbContext;
private DbSet _query;
public RepositoryBase(SqlDbContext dbContext)
{
diff --git a/Back/Program.cs b/Back/Program.cs
index 1d4a754..3890015 100644
--- a/Back/Program.cs
+++ b/Back/Program.cs
@@ -22,6 +22,7 @@ builder.Services.AddDbContext(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("Base"));
});
builder.Services.AddScoped(typeof(IAsyncRepository<>), typeof(RepositoryBase<>));
+builder.Services.AddScoped(typeof(RepositoryBase<>), typeof(RepositoryBase<>));
builder.Services.AddScoped();
builder.Services.AddScoped ();
builder.Services.AddScoped();
diff --git a/Back/Services/ServValidatinMsg.cs b/Back/Services/ServValidatinMsg.cs
index bf4c5bf..059dbc9 100644
--- a/Back/Services/ServValidatinMsg.cs
+++ b/Back/Services/ServValidatinMsg.cs
@@ -28,6 +28,10 @@ namespace Back.Services
}
public async Task GetVerificationCode(int ID)
+ {
+ return await _verificationCodeRepo.Get(w => w.Code == ID).FirstOrDefaultAsync();
+ }
+ public async Task GetVerificationCodeByID(int ID)
{
return await _verificationCodeRepo.Get(w => w.ID == ID).FirstOrDefaultAsync();
}
@@ -68,7 +72,7 @@ namespace Back.Services
public async Task 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);
diff --git a/Back/Services/servCompany.cs b/Back/Services/servCompany.cs
index 4e05919..d53062b 100644
--- a/Back/Services/servCompany.cs
+++ b/Back/Services/servCompany.cs
@@ -100,11 +100,59 @@ namespace Back.Services
}
}
- public async Task ExistMobileAndCompanyIsActive(string mobile)
+ public async Task 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 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();
+ }
+
diff --git a/Back/Services/servUser.cs b/Back/Services/servUser.cs
index ce67ff8..2151b95 100644
--- a/Back/Services/servUser.cs
+++ b/Back/Services/servUser.cs
@@ -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 _RepoUser;
+ private readonly RepositoryBase _RepoCompany;
private readonly IAsyncRepository _RepoPermissionPeriod;
public servUser(IConfiguration configuration
, servNotification servNotification
, IAsyncRepository RepoUser
- , IAsyncRepository RepoPermissionPeriod)
+ , IAsyncRepository RepoPermissionPeriod
+ , RepositoryBase repoCompany)
{
_configuration = configuration;
_servNotification = servNotification;
_RepoUser = RepoUser;
_RepoPermissionPeriod = RepoPermissionPeriod;
+ _RepoCompany = repoCompany;
}
public async Task 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 UserAuthentication(string UserNameORUserID, string Password="",bool newtoken=true)
+ public async Task 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 AddUser(User item)
@@ -151,9 +155,9 @@ namespace Back.Services
}
public async Task ExistUser(string UserName)
{
-
- return await _RepoUser.GetAll().AnyAsync(w=>w.Username==UserName);
-
+
+ return await _RepoUser.GetAll().AnyAsync(w => w.Username == UserName);
+
}
public async Task 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 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 GetDashBoard(int CompanyID,int UserID)
+ public async Task 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 UpdateUser(User user)
@@ -253,10 +257,54 @@ namespace Back.Services
user.Password = newPass.encrypted();
return await _RepoUser.UpdateAsync(user);
}
- public async Task PermissionChangePassword(string oldPass,int UserID)
+ public async Task 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 PermissionChangePassword(string oldPass, int UserID)
+ {
+ return await _RepoUser.GetAll().AnyAsync(w => w.ID == UserID && w.Password == oldPass.encrypted() && w.IsActive);
+
+ }
+ public async Task 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 GetJwt_Lifetime_Minutes()
@@ -286,7 +334,7 @@ namespace Back.Services
return Jwt_Lifetime_Minutes;
}
- private async Task CerateToken(int UserId, string UserName,string Jwt_Lifetime_Minutes)
+ private async Task 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,
diff --git a/Back/Validations/CompanyRegistrationValidation.cs b/Back/Validations/CompanyRegistrationValidation.cs
index a515607..153d812 100644
--- a/Back/Validations/CompanyRegistrationValidation.cs
+++ b/Back/Validations/CompanyRegistrationValidation.cs
@@ -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("این موبایل قبلا ثبت شده");
}
}
diff --git a/Back/Validations/GetVerificationValidation.cs b/Back/Validations/GetVerificationValidation.cs
index 1ec7526..0480cca 100644
--- a/Back/Validations/GetVerificationValidation.cs
+++ b/Back/Validations/GetVerificationValidation.cs
@@ -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("کد یافت نشد");
diff --git a/Back/Validations/MobileValidation.cs b/Back/Validations/MobileValidation.cs
index c42c150..897b90b 100644
--- a/Back/Validations/MobileValidation.cs
+++ b/Back/Validations/MobileValidation.cs
@@ -5,9 +5,16 @@ using System;
namespace Back.Validations
{
- public class MobileValidation : AbstractValidator>
+ public enum ActionMobileValidation
{
- public MobileValidation(servCompany servCompany)
+ No,
+ ExistMobile,
+ nonExistMobile,
+
+ }
+ public class MobileValidation : AbstractValidator>
+ {
+ 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("این موبایل در سیستم تعریف شده");
+ }
+ }
- });
+ });
}
}
}
diff --git a/TaxPayerFull/Layout/LinfoUser.razor b/TaxPayerFull/Layout/LinfoUser.razor
index 42e8d41..3379f8b 100644
--- a/TaxPayerFull/Layout/LinfoUser.razor
+++ b/TaxPayerFull/Layout/LinfoUser.razor
@@ -23,7 +23,7 @@
stroke-linejoin="round" />
- @userinfo.FullName
+ @userinfo.Company.Name
diff --git a/TaxPayerFull/Layout/PanelLayout.razor b/TaxPayerFull/Layout/PanelLayout.razor
index 6f788e0..a0d5611 100644
--- a/TaxPayerFull/Layout/PanelLayout.razor
+++ b/TaxPayerFull/Layout/PanelLayout.razor
@@ -5,6 +5,7 @@
@inject UserAuthenticationDTO userinfo
@inject HttpClient _hc
@inject NavigationManager nav
+@inject localService localserv;
@@ -199,6 +200,7 @@
+
@functions {
private async Task Logout()
{
diff --git a/TaxPayerFull/Pages/Panel.razor b/TaxPayerFull/Pages/UserPanel/Panel.razor
similarity index 100%
rename from TaxPayerFull/Pages/Panel.razor
rename to TaxPayerFull/Pages/UserPanel/Panel.razor
diff --git a/TaxPayerFull/Pages/UserPanel/Profile.razor b/TaxPayerFull/Pages/UserPanel/Profile.razor
index 2f0b4ae..e571eac 100644
--- a/TaxPayerFull/Pages/UserPanel/Profile.razor
+++ b/TaxPayerFull/Pages/UserPanel/Profile.razor
@@ -1,4 +1,5 @@
@page "/Profile"
+@page "/Profile/{from}"
@using Front.Services
@using Shared.DTOs
@layout PanelLayout
@@ -53,19 +54,19 @@
@@ -78,16 +79,16 @@
@@ -98,16 +99,16 @@
@@ -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();
+ _hc._nav.NavigateTo($"Verification/{VerificationID}");
+
+
+ }
+ else
+ {
+ var errors = await request.Content.ReadFromJsonAsync>();
+ 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())
+ {
+ userinfo.FullName= userinfo.Company.Name = newname;
+ ShowSuccessAlert("تغییر نام با موفقیت انجام شد");
+
+ }
+ else
+ {
+ ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
+ }
+
+
+ }
+ else
+ {
+ var errors = await request.Content.ReadFromJsonAsync>();
+ 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 ( "حجم فایل بیشتر از حد مجاز می باشد");
}
}
+
}
\ No newline at end of file
diff --git a/TaxPayerFull/Pages/Verification.razor b/TaxPayerFull/Pages/Verification.razor
index 5a665f0..54cb5ec 100644
--- a/TaxPayerFull/Pages/Verification.razor
+++ b/TaxPayerFull/Pages/Verification.razor
@@ -2,6 +2,7 @@
@page "/Verification/{ID:int}"
@inject HttpClient _hc
@inject NavigationManager nav
+@inject UserAuthenticationDTO userinfo
احراز هویت
@@ -123,7 +124,8 @@
}
else
{
- ShowDangerAlert(await request.Content.ReadFromJsonAsync());
+ var listerror = await request.Content.ReadFromJsonAsync>();
+ 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());
+ var listerror = await request.Content.ReadFromJsonAsync>();
+ 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("/");
}
}
diff --git a/TaxPayerFull/Program.cs b/TaxPayerFull/Program.cs
index 251cf3a..3e28ba5 100644
--- a/TaxPayerFull/Program.cs
+++ b/TaxPayerFull/Program.cs
@@ -17,9 +17,9 @@ builder.Services.AddScoped();
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");