Files
mixtape/zero.Api/Modules_legacy/Security/AuthenticationController.cs
T

47 lines
1.0 KiB
C#
Raw Normal View History

2020-04-15 15:13:38 +02:00
using Microsoft.AspNetCore.Mvc;
2020-04-08 13:07:15 +02:00
using System.Threading.Tasks;
using zero.Core.Api;
2020-04-15 15:13:38 +02:00
using zero.Core.Entities;
2020-04-16 00:56:22 +02:00
using zero.Core.Identity;
2020-04-15 15:13:38 +02:00
using zero.Web.Models;
2020-04-08 13:07:15 +02:00
namespace zero.Web.Controllers
{
2020-04-15 15:13:38 +02:00
[ZeroAuthorize(false)]
2020-04-08 13:07:15 +02:00
public class AuthenticationController : BackofficeController
{
2021-11-23 22:56:22 +01:00
IAuthenticationService Api;
2020-04-08 13:07:15 +02:00
2020-05-21 13:41:09 +02:00
2021-11-23 22:56:22 +01:00
public AuthenticationController(IAuthenticationService api)
2020-04-08 13:07:15 +02:00
{
Api = api;
}
2021-11-23 22:56:22 +01:00
public async Task<EditModel<ZeroUser>> GetUser() => Edit(await Api.GetUser());
2021-11-26 15:47:11 +01:00
public Result IsLoggedIn() => Result.Maybe(Api.IsLoggedIn());
2020-05-11 11:30:56 +02:00
2020-04-15 15:13:38 +02:00
[HttpPost]
2021-11-26 15:47:11 +01:00
public async Task<Result> LoginUser([FromBody] LoginModel model) => await Api.Login(model.Email, model.Password, model.IsPersistent);
2020-04-08 13:07:15 +02:00
2020-04-15 15:13:38 +02:00
[HttpPost, ZeroAuthorize]
2021-11-26 15:47:11 +01:00
public async Task<Result> LogoutUser()
2020-04-08 13:07:15 +02:00
{
2020-04-15 15:13:38 +02:00
await Api.Logout();
2021-11-26 15:47:11 +01:00
return Result.Success();
2020-04-08 13:07:15 +02:00
}
2020-05-21 13:41:09 +02:00
[HttpPost, ZeroAuthorize]
2021-11-26 15:47:11 +01:00
public async Task<Result> SwitchApp(string appId)
2020-05-21 13:41:09 +02:00
{
2021-11-26 15:47:11 +01:00
return Result.Maybe(await Api.TrySwitchApp(appId));
2020-05-21 13:41:09 +02:00
}
2020-04-08 13:07:15 +02:00
}
}