2024-04-15 17:16:17 +03:30
|
|
|
|
using Back.Data.Models;
|
|
|
|
|
using Back.Services;
|
|
|
|
|
using Back.Validations;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Shared.DTOs;
|
|
|
|
|
|
|
|
|
|
namespace Back.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class VerificationController : ControllerBase
|
|
|
|
|
{
|
2024-04-16 12:23:29 +03:30
|
|
|
|
private readonly ServValidatinMsg _servValidatinMsg;
|
2024-04-15 17:16:17 +03:30
|
|
|
|
private readonly GetVerificationValidation _getVerificationValidation;
|
2024-04-16 12:23:29 +03:30
|
|
|
|
public VerificationController(ServValidatinMsg servValidatinMsg, GetVerificationValidation getVerificationValidation)
|
2024-04-15 17:16:17 +03:30
|
|
|
|
{
|
2024-04-16 12:23:29 +03:30
|
|
|
|
_servValidatinMsg = servValidatinMsg;
|
2024-04-15 17:16:17 +03:30
|
|
|
|
_getVerificationValidation = getVerificationValidation;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
[HttpGet("GetVerification/{ID}")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<ActionResult<VerificationCode>> GetVerification(int ID)
|
|
|
|
|
{
|
|
|
|
|
var resultValidationmodel = await _getVerificationValidation.ValidateAsync(ID);
|
|
|
|
|
if (!resultValidationmodel.IsValid)
|
|
|
|
|
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
|
|
|
|
|
|
|
|
|
return Ok(new VerificationCodeDto {
|
2024-04-15 23:09:11 +03:30
|
|
|
|
ID = ID,
|
2024-04-15 23:31:24 +03:30
|
|
|
|
Code=0,
|
2024-04-15 17:16:17 +03:30
|
|
|
|
prm= _getVerificationValidation.verificationCode.prm,
|
|
|
|
|
Type= _getVerificationValidation.verificationCode.Type,
|
|
|
|
|
val= _getVerificationValidation.verificationCode.val
|
2024-04-15 23:09:11 +03:30
|
|
|
|
});;
|
|
|
|
|
}
|
2024-04-16 22:56:02 +03:30
|
|
|
|
[HttpGet("ReSend/{ID}")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<ActionResult> ReSend(int ID)
|
|
|
|
|
{
|
|
|
|
|
var resultValidationmodel = await _getVerificationValidation.ValidateAsync(ID);
|
|
|
|
|
if (!resultValidationmodel.IsValid)
|
|
|
|
|
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
|
|
|
|
// _getVerificationValidation.verificationCode
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
2024-04-15 23:09:11 +03:30
|
|
|
|
[HttpPost("Submit")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<ActionResult<bool>> Submit(VerificationCodeDto item)
|
|
|
|
|
{
|
2024-04-16 12:23:29 +03:30
|
|
|
|
var VerificationCode= await _servValidatinMsg.GetVerificationCode(item.ID);
|
|
|
|
|
if (VerificationCode==null)
|
|
|
|
|
return NotFound("آیتمی یافت نشد");
|
|
|
|
|
|
|
|
|
|
if (VerificationCode.Code==item.Code)
|
|
|
|
|
{
|
|
|
|
|
if (VerificationCode.prm == item.prm && VerificationCode.val == item.val && VerificationCode.Type == item.Type)
|
|
|
|
|
{
|
2024-04-16 22:56:02 +03:30
|
|
|
|
bool Sucstatus = false;
|
2024-04-16 12:23:29 +03:30
|
|
|
|
switch (VerificationCode.Type)
|
|
|
|
|
{
|
|
|
|
|
case "NewTicketNoAuthentication":
|
2024-04-16 22:56:02 +03:30
|
|
|
|
Sucstatus = await _servValidatinMsg.SubmittedTicket(VerificationCode);
|
|
|
|
|
break;
|
2024-04-16 12:23:29 +03:30
|
|
|
|
default:
|
|
|
|
|
return BadRequest("این نوع احراز تعریف نشده");
|
|
|
|
|
}
|
2024-04-16 22:56:02 +03:30
|
|
|
|
if (Sucstatus)
|
|
|
|
|
await _servValidatinMsg.Delete(VerificationCode);
|
|
|
|
|
|
|
|
|
|
return Ok(Sucstatus);
|
2024-04-16 12:23:29 +03:30
|
|
|
|
}
|
|
|
|
|
else return BadRequest("اطلاعات شما منطبق با سامانه نیست");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else return BadRequest("کد احراز صحیح نمی باشد");
|
|
|
|
|
|
2024-04-15 17:16:17 +03:30
|
|
|
|
}
|
2024-04-16 22:56:02 +03:30
|
|
|
|
[HttpDelete("Remove/{ID}")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<ActionResult<bool>> Remove(int ID)
|
|
|
|
|
{
|
|
|
|
|
var VerificationCode = await _servValidatinMsg.GetVerificationCode(ID);
|
|
|
|
|
await _servValidatinMsg.Delete(VerificationCode);
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
2024-04-15 17:16:17 +03:30
|
|
|
|
}
|
|
|
|
|
}
|