This commit is contained in:
mmrbnjd
2024-04-17 15:49:34 +03:30
parent f829d80851
commit 3f0a37a08b
27 changed files with 1253 additions and 79 deletions

View File

@@ -1,5 +1,9 @@
using Back.Services;
using Back.Common;
using Back.Data.Models;
using Back.Services;
using Back.Validations;
using FluentValidation;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Shared.DTOs;
@@ -12,10 +16,25 @@ namespace Back.Controllers
{
private readonly ServBase _sBase;
private readonly MobileValidation _mobilevalidation;
public BaseController(ServBase sBase, MobileValidation mobilevalidation)
private readonly servCompany _servCompany;
private readonly servUser _servUser;
private readonly servPermission _servPermission;
private readonly ServValidatinMsg _servValidatinMsg;
private readonly servSendMsg _servSendMsg;
private readonly CompanyRegistrationValidation _companyRegistrationValidation;
public BaseController(ServBase sBase, MobileValidation mobilevalidation
, servCompany servCompany, servUser servUser
, servPermission servPermission, ServValidatinMsg servValidatinMsg
, servSendMsg servSendMsg, CompanyRegistrationValidation companyRegistrationValidation)
{
_sBase = sBase;
_mobilevalidation = mobilevalidation;
_servCompany = servCompany;
_servUser = servUser;
_servPermission = servPermission;
_servValidatinMsg = servValidatinMsg;
_servSendMsg = servSendMsg;
_companyRegistrationValidation = companyRegistrationValidation;
}
[HttpGet("Pricing")]
public async Task<ActionResult<List<BasePriceDto>>> Pricing()
@@ -24,14 +43,14 @@ namespace Back.Controllers
public async Task<ActionResult<DateTime>> DateTimeServer()
=> Ok(DateTime.Now);
[HttpGet("LastBlog")]
public async Task<ActionResult<PagingDto<BlogDto>>> LastBlog(int PageIndex,int PageSize)
=> Ok(await _sBase.GetBlog(PageIndex,PageSize));
public async Task<ActionResult<PagingDto<BlogDto>>> LastBlog(int PageIndex, int PageSize)
=> Ok(await _sBase.GetBlog(PageIndex, PageSize));
[HttpGet("GetBlogByID/{ID}")]
public async Task<ActionResult<BlogDtoFull?>> GetBlogByID(int ID)
{
var result = await _sBase.GetBlogByID(ID);
if (result == null)
return NotFound();
return NotFound();
return Ok(result);
}
[HttpGet("LastQuestion")]
@@ -42,18 +61,112 @@ namespace Back.Controllers
{
var resultValidationmodel = await _mobilevalidation.ValidateAsync(model.Mobile);
if (!resultValidationmodel.IsValid)
return BadRequest(resultValidationmodel.Errors.Select(s=>s.ErrorMessage ).ToList());
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
return Ok(await _sBase.CreateCsrAndPrivateKey(model));
}
[HttpPost("ReadPublicKeyFromCER")]
public async Task<ActionResult<PublicKeyDTO>> ReadPublicKeyFromCER(string modelfromBase64)
{
var result = await _sBase.ReadPublicKeyFromCER(modelfromBase64);
if (result.type== "error")
if (result.type == "error")
return BadRequest();
return Ok(result);
return Ok(result);
}
[HttpPost("CompanyRegistration")]
[AllowAnonymous]
public async Task<ActionResult<string>> CompanyRegistration([FromBody] CompanyRegistrationDTO item)
{
var resultValidationmodel = await _companyRegistrationValidation.ValidateAsync(item);
if (!resultValidationmodel.IsValid)
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
try
{
var user = new User()
{
Fullname = item.FullnameUser,
Mobile = item.Mobile,
Username = item.Username,
Password = item.Mobile.encrypted(),
IsActive = false
};
user = await _servUser.AddUser(user);
var company =await _servCompany.GetCompanyOrgByMobileAndCompanynotActive(item.Mobile);
if (company==null)
{
company = new Company()
{
Name = item.CompanyName,
Mobile = item.Mobile,
RegisterDate = DateTime.Now.ConvertMiladiToShamsi(),
IsActive = false
};
}
else
{
company.Name = item.CompanyName;
company.RegisterDate = DateTime.Now.ConvertMiladiToShamsi();
company.IsActive = false;
}
company = await _servCompany.AddORUpdateCompany(company);
var allper = await _servPermission.GetPermissions();
var roluser = new RolUser()
{
CompanyID = company.ID,
UserID = user.ID,
IsAdmin = true
};
roluser = await _servPermission.AddRolUser(roluser);
await _servPermission.AddRangePermissionPeriodByCompany(new List<PermissionPeriod>()
{
new PermissionPeriod(){CompanyID=company.ID,PermissionID=2,CalculationTypeID=2,RemainingAmount=0,TotalAmount=0},
new PermissionPeriod(){CompanyID=company.ID,PermissionID=3,CalculationTypeID=1,RemainingAmount=5,TotalAmount=5},
new PermissionPeriod(){CompanyID=company.ID,PermissionID=4,CalculationTypeID=1,RemainingAmount=5,TotalAmount=5},
new PermissionPeriod(){CompanyID=company.ID,PermissionID=5,CalculationTypeID=1,RemainingAmount=5,TotalAmount=5},
new PermissionPeriod(){CompanyID=company.ID,PermissionID=16,CalculationTypeID=1,RemainingAmount=5,TotalAmount=5},
new PermissionPeriod(){CompanyID=company.ID,PermissionID=6,CalculationTypeID=2,RemainingAmount=0,TotalAmount=0}
});
await _servPermission.AddPermissionUser(roluser.ID, allper.Select(s => s.ID).ToArray());
var ID = await _servValidatinMsg.GenerateCode(new VerificationCode
{
prm = company.ID.ToString(),
val = user.ID.ToString(),
Type = "CompanyRegistration"
});
_servSendMsg.Authentication(company.Mobile, ID.ToString());
return Ok(ID);
}
catch (Exception ex)
{
//SysLog log = new SysLog()
//{
// TraceIdentifierID = HttpContext.TraceIdentifier,
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
// Method = HttpContext.Request.Method,
// Value = ex.Message,
// Route = HttpContext.Request.Path,
// Type = "catch"
//};
//_contextMongodb.InsertItem(log);
return BadRequest("خطای سیستمی رخ داده");
}
}
}
}

View File

@@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Shared.DTOs;
using System.Security.Cryptography;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
namespace Back.Controllers
{
@@ -18,11 +19,14 @@ namespace Back.Controllers
private readonly MobileValidation _mobilevalidation;
private readonly servTicket _servTicket;
private readonly ServValidatinMsg _servValidatinMsg;
public TicketController(MobileValidation mobilevalidation, servTicket servTicket, ServValidatinMsg servValidatinMsg)
private readonly servSendMsg _servSendMsg;
public TicketController(MobileValidation mobilevalidation, servTicket servTicket
, ServValidatinMsg servValidatinMsg, servSendMsg servSendMsg)
{
_mobilevalidation = mobilevalidation;
_servTicket = servTicket;
_servValidatinMsg = servValidatinMsg;
_servSendMsg = servSendMsg;
}
[HttpPost("NewTicketNoAuthentication")]
@@ -41,9 +45,9 @@ namespace Back.Controllers
{
prm = Ticket.ID.ToString(),
val = item.Mobile,
Type = "NewTicketNoAuthentication"
Type = "NewTicketNoAuthentication"
});
_servSendMsg.Authentication(item.Mobile, ID.ToString());
return Ticket == null ? BadRequest() : Ok(ID);
}
}

View File

@@ -0,0 +1,38 @@
using Back.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Shared.DTOs;
namespace Back.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class UserController : ControllerBase
{
private readonly servUser _servUser;
public UserController(servUser servUser)
{
_servUser = servUser;
}
[HttpPost("authenticate")]
[AllowAnonymous]
public async Task<ActionResult<UserAuthenticationDTO>> Login(Authentication model)
{
if (!ModelState.IsValid) return BadRequest(model);
var result = await _servUser.UserAuthentication(model.Username, model.Password);
if (result != null) return Ok(result);
else return NotFound("کاربری با این مشخصات یافت نشد");
}
}
}

View File

@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Shared.DTOs;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
namespace Back.Controllers
{
@@ -14,11 +15,14 @@ namespace Back.Controllers
{
private readonly ServValidatinMsg _servValidatinMsg;
private readonly GetVerificationValidation _getVerificationValidation;
public VerificationController(ServValidatinMsg servValidatinMsg, GetVerificationValidation getVerificationValidation)
private readonly servSendMsg _servSendMsg;
private readonly servCompany _servCompany;
public VerificationController(ServValidatinMsg servValidatinMsg, GetVerificationValidation getVerificationValidation
, servCompany servCompany)
{
_servValidatinMsg = servValidatinMsg;
_getVerificationValidation = getVerificationValidation;
_servCompany = servCompany;
}
[HttpGet("GetVerification/{ID}")]
[AllowAnonymous]
@@ -44,6 +48,22 @@ namespace Back.Controllers
if (!resultValidationmodel.IsValid)
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
// _getVerificationValidation.verificationCode
switch (_getVerificationValidation.verificationCode.Type)
{
case "NewTicketNoAuthentication":
_servSendMsg.Authentication(_getVerificationValidation.verificationCode.val, ID.ToString());
break;
case "CompanyRegistration":
var company=await _servCompany.GetCompanyOrg(Convert.ToInt32(_getVerificationValidation.verificationCode.prm),false);
_servSendMsg.Authentication(company.Mobile, ID.ToString());
break;
default:
return BadRequest("این نوع احراز تعریف نشده");
}
return NoContent();
}
[HttpPost("Submit")]
@@ -64,12 +84,21 @@ namespace Back.Controllers
case "NewTicketNoAuthentication":
Sucstatus = await _servValidatinMsg.SubmittedTicket(VerificationCode);
break;
case "CompanyRegistration":
//string UserID = VerificationCode.val;
Sucstatus = await _servValidatinMsg.SubmittedCompanyRegistration(VerificationCode);
// return Ok(await _servUser.UserAuthentication(UserID));
//else return BadRequest();
break;
default:
return BadRequest("این نوع احراز تعریف نشده");
}
if (Sucstatus)
await _servValidatinMsg.Delete(VerificationCode);
return Ok(Sucstatus);
}
else return BadRequest("اطلاعات شما منطبق با سامانه نیست");