Files
mixtape/zero.Web/Controllers/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
{
IAuthenticationApi Api;
2020-04-08 13:07:15 +02:00
2020-05-21 13:41:09 +02:00
2020-11-16 01:07:07 +01:00
public AuthenticationController(IAuthenticationApi api)
2020-04-08 13:07:15 +02:00
{
Api = api;
}
public async Task<EditModel<BackofficeUser>> GetUser() => Edit(await Api.GetUser());
public EntityResult IsLoggedIn() => EntityResult.Maybe(Api.IsLoggedIn());
2020-05-11 11:30:56 +02:00
2020-04-15 15:13:38 +02:00
[HttpPost]
public async Task<EntityResult> 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]
public async Task<EntityResult> LogoutUser()
2020-04-08 13:07:15 +02:00
{
2020-04-15 15:13:38 +02:00
await Api.Logout();
return EntityResult.Success();
2020-04-08 13:07:15 +02:00
}
2020-05-21 13:41:09 +02:00
[HttpPost, ZeroAuthorize]
public async Task<EntityResult> SwitchApp(string appId)
2020-05-21 13:41:09 +02:00
{
2020-11-16 14:48:23 +01:00
return EntityResult.Maybe(await Api.TrySwitchApp(appId));
2020-05-21 13:41:09 +02:00
}
2020-04-08 13:07:15 +02:00
}
}