Implementing OTAC login

This commit is contained in:
Zoe Roux 2020-03-20 01:16:48 +01:00
parent a3f5910f2d
commit 8fdfc5ce85
2 changed files with 19 additions and 1 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using IdentityServer4.Models; using IdentityServer4.Models;
@ -28,6 +29,11 @@ namespace Kyoo.Api
public string Password; public string Password;
public bool StayLoggedIn; public bool StayLoggedIn;
} }
public class OtacRequest
{
public string Otac;
}
public class AccountData public class AccountData
{ {
@ -81,6 +87,18 @@ namespace Kyoo.Api
return Ok(); 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")] [HttpGet("logout")]
[Authorize] [Authorize]
public async Task<IActionResult> Logout() public async Task<IActionResult> Logout()

@ -1 +1 @@
Subproject commit 0112c08ae4bdee6bd7ed63a6cf09fc6e19ed8b2a Subproject commit 5d6a7cf319ce57dc5cf12a10e0195af5705b566f