77
88namespace WebApi . Features . Accounts
99{
10- [ Authorize ( Roles = "Admin" ) ]
10+ [ Authorize ]
1111 [ Route ( "api/[controller]" ) , ApiController ]
1212 public class AccountsController : ControllerBase
1313 {
@@ -19,6 +19,7 @@ public AccountsController(IMediator mediator)
1919 }
2020
2121 // POST: api/accounts/register
22+ [ Authorize ( Roles = "Admin" ) ]
2223 [ HttpPost ( "register" ) ]
2324 public async Task < IActionResult > Register ( RegisterViewModel viewModel )
2425 {
@@ -36,16 +37,28 @@ public async Task<IActionResult> Register(RegisterViewModel viewModel)
3637 return new CreatedResult ( "" , employeeInfo ) ;
3738 }
3839
39- [ Authorize ]
40+ // PUT: api/accounts/update-password
41+ [ Authorize ( Roles = "Admin" ) ]
42+ [ HttpPut ( "update-password" ) ]
43+ public async Task < IActionResult > UpdatePassword ( ChangePasswordViewModel viewModel )
44+ {
45+ // Change a specific Employee account's password
46+ var result = await _mediator . Send ( new UpdatePassword . Command ( viewModel ) ) ;
47+ if ( ! result ) return StatusCode ( 500 ) ;
48+
49+ return Ok ( ) ;
50+ }
51+
52+ // PUT: api/accounts/change-password
4053 [ HttpPut ( "change-password" ) ]
41- public async Task < IActionResult > ChangePassword ( UpdatePasswordViewModel viewModel )
54+ public async Task < IActionResult > ChangePassword ( ChangePasswordViewModel viewModel )
4255 {
4356 // Check if Old password is correct
4457 var validatePassword = await _mediator . Send ( new Auth . ValidatePassword . Query ( viewModel . UserName , viewModel . OldPassword ) ) ;
4558 if ( ! validatePassword ) return BadRequest ( "Incorrect password" ) ;
4659
4760 // Change account password
48- var result = await _mediator . Send ( new UpdatePassword . Command ( viewModel ) ) ;
61+ var result = await _mediator . Send ( new ChangePassword . Command ( viewModel ) ) ;
4962 if ( ! result . Succeeded ) return BadRequest ( "Unable to change password" ) ;
5063
5164 return Ok ( ) ;
0 commit comments