148 lines
4.4 KiB
C#
148 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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;
|
|
|
|
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<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)
|
|
{
|
|
return await _authService.GetFilteredAuthUsersAsync(selectCriterion);
|
|
}
|
|
|
|
// Get /api/auth/users/get/<mail>
|
|
[HttpGet("users/get/{email}")]
|
|
[Authorize]
|
|
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)
|
|
{
|
|
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/<id>
|
|
[HttpPost("register/{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)
|
|
{
|
|
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<EMailStringDTO> 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<TokenDTO> 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);
|
|
}
|
|
}
|
|
} |