mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Implementing OTAC login
This commit is contained in:
parent
a3f5910f2d
commit
8fdfc5ce85
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using IdentityServer4.Models;
|
||||
@ -28,6 +29,11 @@ namespace Kyoo.Api
|
||||
public string Password;
|
||||
public bool StayLoggedIn;
|
||||
}
|
||||
|
||||
public class OtacRequest
|
||||
{
|
||||
public string Otac;
|
||||
}
|
||||
|
||||
public class AccountData
|
||||
{
|
||||
@ -81,6 +87,18 @@ namespace Kyoo.Api
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost("otac-login")]
|
||||
public async Task<IActionResult> OtacLogin([FromBody] OtacRequest otac)
|
||||
{
|
||||
User user = _userManager.Users.FirstOrDefault(x => x.OTAC == otac.Otac);
|
||||
if (user == null)
|
||||
return BadRequest(new [] { new {code = "InvalidOTAC", description = "No user was found for this OTAC."}});
|
||||
if (user.OTACExpires <= DateTime.UtcNow)
|
||||
return BadRequest(new [] { new {code = "ExpiredOTAC", description = "The OTAC has expired. Try to login with your password."}});
|
||||
await _signInManager.SignInAsync(user, true);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("logout")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Logout()
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 0112c08ae4bdee6bd7ed63a6cf09fc6e19ed8b2a
|
||||
Subproject commit 5d6a7cf319ce57dc5cf12a10e0195af5705b566f
|
Loading…
x
Reference in New Issue
Block a user