Improved permissions
This commit is contained in:
@@ -4,25 +4,22 @@ using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
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
|
||||
{
|
||||
namespace gswi.Controllers {
|
||||
[Route("api/auth")]
|
||||
[ApiController]
|
||||
public class AuthController : ControllerBase
|
||||
{
|
||||
public class AuthController : ControllerBase {
|
||||
private readonly IAuthService _authService;
|
||||
|
||||
public AuthController(
|
||||
IAuthService authServce
|
||||
)
|
||||
{
|
||||
) {
|
||||
_authService = authServce;
|
||||
}
|
||||
|
||||
@@ -30,118 +27,102 @@ namespace gswi.Controllers
|
||||
// Get /api/auth/users
|
||||
[HttpGet("users")]
|
||||
[Authorize]
|
||||
public async Task<List<AuthUserDTO>> GetAllAuthUsers()
|
||||
{
|
||||
public async Task<List<AuthUserDTO>> GetAllAuthUsers() {
|
||||
return await _authService.GetAllAuthUsersAsync();
|
||||
}
|
||||
|
||||
|
||||
// POST /api/auth/users/get/filtered
|
||||
[HttpPost("users/get/filtered")]
|
||||
[Authorize]
|
||||
public async Task<GetFilteredAuthUsersResultDTO> GetFilteredAuthUsers(AuthUserSelectCriterion selectCriterion)
|
||||
{
|
||||
public async Task<GetFilteredAuthUsersResultDTO> GetFilteredAuthUsers(AuthUserSelectCriterion selectCriterion) {
|
||||
return await _authService.GetFilteredAuthUsersAsync(selectCriterion);
|
||||
}
|
||||
|
||||
// Get /api/auth/users/get/<mail>
|
||||
[HttpGet("users/get/{email}")]
|
||||
[Authorize]
|
||||
public async Task<AuthUserDTO> GetUserFromEMail(string email)
|
||||
{
|
||||
public async Task<AuthUserDTO> GetUserFromEMail(string email) {
|
||||
return await _authService.GetAuthUserByEMailAsync(email);
|
||||
}
|
||||
|
||||
// Get /api/auth/users/find/<mail>
|
||||
[HttpGet("users/find/{email}")]
|
||||
[Authorize]
|
||||
public async Task<AuthUserDTO> FindUserFromEMail(string email)
|
||||
{
|
||||
public async Task<AuthUserDTO> FindUserFromEMail(string email) {
|
||||
return await _authService.FindAuthUserByEMailAsync(email);
|
||||
}
|
||||
|
||||
/* Auth requests */
|
||||
// POST /api/auth/register
|
||||
[HttpPost("register")]
|
||||
public async Task Register(AuthUserDTO userDTO)
|
||||
{
|
||||
public async Task Register(AuthUserDTO userDTO) {
|
||||
await _authService.AddAuthUserAsync(userDTO);
|
||||
}
|
||||
|
||||
// POST /api/auth/register/<id>
|
||||
[HttpPost("register/{id}")]
|
||||
public async Task<bool> ConfirmEMail(string id)
|
||||
{
|
||||
public async Task<bool> ConfirmEMail(string id) {
|
||||
return await _authService.ConfirmEMail(id);
|
||||
}
|
||||
|
||||
// POST /api/auth/login
|
||||
[HttpPost("login")]
|
||||
public async Task<TokenDTO> Login(AuthUserDTO userDTO)
|
||||
{
|
||||
public async Task<TokenDTO> Login(AuthUserDTO userDTO) {
|
||||
return await _authService.Login(userDTO);
|
||||
}
|
||||
|
||||
// POST /api/auth/forgot-password
|
||||
[HttpPost("forgot-password")]
|
||||
public async Task ForgotPassword([FromBody] string email)
|
||||
{
|
||||
public async Task ForgotPassword([FromBody] string email) {
|
||||
await _authService.ForgotPassword(email);
|
||||
}
|
||||
|
||||
// POST /api/auth/confirm-forgot-password
|
||||
[HttpPost("confirm-forgot-password")]
|
||||
public async Task<EMailStringDTO> ConfirmForgotPassword([FromBody] string id)
|
||||
{
|
||||
public async Task<EMailStringDTO> ConfirmForgotPassword([FromBody] string id) {
|
||||
return await _authService.ConfirmForgotPassword(id);
|
||||
}
|
||||
|
||||
// POST /api/auth/reset-password
|
||||
[HttpPost("reset-password")]
|
||||
public async Task ResetPassword(ResetPasswordDTO rpDTO)
|
||||
{
|
||||
public async Task ResetPassword(ResetPasswordDTO rpDTO) {
|
||||
await _authService.ResetPassword(rpDTO);
|
||||
}
|
||||
|
||||
// POST /api/auth/update-user
|
||||
[HttpPost("update-user")]
|
||||
public async Task UpdateUser(UpdateUserDTO updateUserDTO)
|
||||
{
|
||||
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)
|
||||
{
|
||||
public async Task UpdateUserAsAdmin(AdminUpdateUserDTO updateUserDTO) {
|
||||
await _authService.UpdateUserAsAdmin(updateUserDTO);
|
||||
}
|
||||
|
||||
// POST /api/auth/refresh
|
||||
[HttpPost("refresh")]
|
||||
public async Task<TokenDTO> Refresh(TokenDTO tokenDTO)
|
||||
{
|
||||
public async Task<TokenDTO> Refresh(TokenDTO tokenDTO) {
|
||||
return await _authService.Refresh(tokenDTO);
|
||||
}
|
||||
|
||||
// POST /api/auth/revoke
|
||||
[HttpPost("revoke")]
|
||||
public async Task Revoke(TokenDTO tokenDTO)
|
||||
{
|
||||
public async Task Revoke(TokenDTO tokenDTO) {
|
||||
await _authService.Revoke(tokenDTO);
|
||||
}
|
||||
|
||||
// POST /api/auth/delete-user
|
||||
[HttpPost("delete-user")]
|
||||
public async Task DeleteAuthUserAsync(AuthUserDTO userDTO)
|
||||
{
|
||||
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)
|
||||
{
|
||||
public async Task DeleteAuthUserByEMailAsync(string mail) {
|
||||
await _authService.DeleteAuthUserByEMailAsync(mail);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user