301 lines
10 KiB
C#
301 lines
10 KiB
C#
|
|
using CloudBuilder.Core.DatabaseAccessor;
|
|
using CloudBuilder.Core.Policy;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Transactions;
|
|
using CloudBuilder.Core.Service;
|
|
using CloudBuilder.Security.Service;
|
|
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
|
using Microsoft.AspNetCore.Http;
|
|
using CloudBuilder.Core.Policy;
|
|
using CloudBuilder.Core.DependencyInjection.Request;
|
|
using CloudBuilder.Security.Data;
|
|
using CloudBuilder.Core.Authorization;
|
|
using System;
|
|
|
|
namespace CloudBuilder.Web.Entry.Controllers.Security
|
|
{
|
|
[Authorize(AuthorizePolicy.PERMISSION)]
|
|
[ApiController]
|
|
[Route("[controller]/[action]")]
|
|
public class AuthController : ControllerBase
|
|
{
|
|
private readonly IApplicationService service;
|
|
private readonly IAuthService authService;
|
|
|
|
public AuthController(IApplicationService service, IAuthService authService)
|
|
{
|
|
this.service = service;
|
|
this.authService= authService;
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic Login(LoginData data)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = authService.Login(data);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "SecurityUser", operate: "LoginAgent")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic LoginAgent(LoginData data)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = authService.LoginAgent(data);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic Register(RegisterData data)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = authService.Register(data);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "SecurityUser", operate: "Update")]
|
|
[HttpPost]
|
|
[UnitOfWork]
|
|
public dynamic AmendPassword(LoginData data)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = authService.AmendPassword(data);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpGet]
|
|
public dynamic GetRsaPublicKey()
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = authService.GetRsaPublicKey();
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpPost]
|
|
public dynamic RefreshToken(JwtInfo jwtInfo)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = authService.RefreshToken(jwtInfo);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpPost]
|
|
public dynamic Logout()
|
|
{
|
|
try
|
|
{
|
|
|
|
authService.Logout();
|
|
|
|
return string.Empty;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "SecurityUser", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic ConfirmPassword(string password)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = authService.ConfirmPassword(password);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "SecurityUser", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic BeginBiometricRegistration(string deviceName)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = authService.BeginBiometricRegistration(deviceName);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "SecurityUser", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic FinishBiometricRegistration(FinishBiometricRegistrationData dto)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = authService.FinishBiometricRegistration(dto);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpPost]
|
|
public dynamic BeginBiometricLogin(string username)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = authService.BeginBiometricLogin(username);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpPost]
|
|
public dynamic FinishBiometricLogin(FinishBiometricLoginData dto)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = authService.FinishBiometricLogin(dto);
|
|
return result;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
[PermissionOperate(name: "SecurityUser", operate: "Find")]
|
|
[HttpPost]
|
|
public dynamic RemoveBiometric()
|
|
{
|
|
try
|
|
{
|
|
|
|
authService.RemoveBiometric();
|
|
|
|
return string.Empty;
|
|
}
|
|
catch (ValidatedException vex)
|
|
{
|
|
return vex;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ServiceErrorException(ex);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
} |