using System; using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; using System.Threading.Tasks; using gswi.Interface.Services; using gswi.Model.DTOs; using gswi.Share.Common; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.IdentityModel.Tokens; namespace gswi.Controllers { [Route("api/auth")] [ApiController] public class AuthController : ControllerBase { private readonly IAuthService _authService; public AuthController( IAuthService authServce ) { _authService = authServce; } /* Data requests */ // Get /api/auth/users [HttpGet("users")] [Authorize] public async Task> GetAllAuthUsers() { return await _authService.GetAllAuthUsersAsync(); } // POST /api/auth/users/get/filtered [HttpPost("users/get/filtered")] [Authorize] public async Task GetFilteredAuthUsers(AuthUserSelectCriterion selectCriterion) { return await _authService.GetFilteredAuthUsersAsync(selectCriterion); } // Get /api/auth/users/get/ [HttpGet("users/get/{email}")] [Authorize] public async Task GetUserFromEMail(string email) { return await _authService.GetAuthUserByEMailAsync(email); } // Get /api/auth/users/find/ [HttpGet("users/find/{email}")] [Authorize] public async Task FindUserFromEMail(string email) { return await _authService.FindAuthUserByEMailAsync(email); } /* Auth requests */ // POST /api/auth/register [HttpPost("register")] public async Task Register(AuthUserDTO userDTO) { await _authService.AddAuthUserAsync(userDTO); } // POST /api/auth/register/ [HttpPost("register/{id}")] public async Task ConfirmEMail(string id) { return await _authService.ConfirmEMail(id); } // POST /api/auth/login [HttpPost("login")] public async Task Login(AuthUserDTO userDTO) { return await _authService.Login(userDTO); } // POST /api/auth/forgot-password [HttpPost("forgot-password")] public async Task ForgotPassword([FromBody] string email) { await _authService.ForgotPassword(email); } // POST /api/auth/confirm-forgot-password [HttpPost("confirm-forgot-password")] public async Task ConfirmForgotPassword([FromBody] string id) { return await _authService.ConfirmForgotPassword(id); } // POST /api/auth/reset-password [HttpPost("reset-password")] public async Task ResetPassword(ResetPasswordDTO rpDTO) { await _authService.ResetPassword(rpDTO); } // POST /api/auth/update-user [HttpPost("update-user")] public async Task UpdateUser(UpdateUserDTO updateUserDTO) { await _authService.UpdateUser(updateUserDTO); } // POST /api/auth/update-user-as-admin [HttpPost("update-user-as-admin")] [Authorize] public async Task UpdateUserAsAdmin(AdminUpdateUserDTO updateUserDTO) { await _authService.UpdateUserAsAdmin(updateUserDTO); } // POST /api/auth/refresh [HttpPost("refresh")] public async Task Refresh(TokenDTO tokenDTO) { return await _authService.Refresh(tokenDTO); } // POST /api/auth/revoke [HttpPost("revoke")] public async Task Revoke(TokenDTO tokenDTO) { await _authService.Revoke(tokenDTO); } // POST /api/auth/delete-user [HttpPost("delete-user")] public async Task DeleteAuthUserAsync(AuthUserDTO userDTO) { await _authService.DeleteAuthUserAsync(userDTO); } // POST /api/auth/delete-user [HttpPost("delete-user-by-mail/{mail}")] public async Task DeleteAuthUserByEMailAsync(string mail) { await _authService.DeleteAuthUserByEMailAsync(mail); } } }