This commit is contained in:
mmrbnjd
2024-04-29 18:15:46 +03:30
parent 7b8127dc72
commit 319270d567
20 changed files with 356 additions and 96 deletions

View File

@@ -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)));
}