Skip to content

Commit

Permalink
fix(User) : add reset Password api
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdijafariii committed Aug 16, 2024
1 parent 2e47312 commit c6e78e8
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions AnalysisData/AnalysisData/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,41 @@
using Microsoft.AspNetCore.Mvc;

namespace AnalysisData.Controllers;

[ApiController]
[Route("api/[controller]")]
public class UserController : ControllerBase
{
private readonly IUserService _userService;
private readonly IPermissionService _permissionService;

public UserController(IUserService userService,IPermissionService permissionService)
public UserController(IUserService userService, IPermissionService permissionService)
{
_userService = userService;
_permissionService = permissionService;
}

[HttpPost("login")]
public IActionResult Login([FromBody] UserLoginModel userLoginModel)
{
var user = _userService.Login(userLoginModel);
return Ok(new { user.Result.FirstName , user.Result.LastName , user.Result.ImageURL });
return Ok(new { user.Result.FirstName, user.Result.LastName, user.Result.ImageURL });
}

[Authorize(Roles = "admin")]
[HttpPost("register")]
public async Task<IActionResult> Register([FromBody] UserRegisterModel userRegisterModel)
{
var check = await _userService.Register(userRegisterModel);
var check = await _userService.Register(userRegisterModel);
if (check)
{
return Ok("success");
}

return BadRequest("not success");
}


[HttpGet("permissions")]
public IActionResult GetPermissions()
{
Expand All @@ -48,15 +51,16 @@ public IActionResult GetPermissions()
var username = userClaims.FindFirstValue("username");
var firstName = userClaims.FindFirstValue("firstname");
var lastName = userClaims.FindFirstValue("lastname");
return Ok(new { username,firstName,lastName,permission });
return Ok(new { username, firstName, lastName, permission });
}


[HttpPost("reset-password")]
public async Task<IActionResult> ResetPassword([FromBody] ResetPasswordModel resetPasswordModel)
{
var userClaim = User;
var check = await _userService.ResetPassword(userClaim ,resetPasswordModel.NewPassword);
var check = await _userService.ResetPassword(userClaim, resetPasswordModel.NewPassword,
resetPasswordModel.ConfirmPassword);
if (check)
{
return Ok("success");
Expand Down

0 comments on commit c6e78e8

Please sign in to comment.