From 8fdfc5ce85996feb8ecc4c3e228d64c55a9c665e Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 20 Mar 2020 01:16:48 +0100 Subject: [PATCH] Implementing OTAC login --- Kyoo/Views/API/AccountAPI.cs | 18 ++++++++++++++++++ Kyoo/Views/WebClient | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Kyoo/Views/API/AccountAPI.cs b/Kyoo/Views/API/AccountAPI.cs index 1a33c40a..3dcbb94a 100644 --- a/Kyoo/Views/API/AccountAPI.cs +++ b/Kyoo/Views/API/AccountAPI.cs @@ -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 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 Logout() diff --git a/Kyoo/Views/WebClient b/Kyoo/Views/WebClient index 0112c08a..5d6a7cf3 160000 --- a/Kyoo/Views/WebClient +++ b/Kyoo/Views/WebClient @@ -1 +1 @@ -Subproject commit 0112c08ae4bdee6bd7ed63a6cf09fc6e19ed8b2a +Subproject commit 5d6a7cf319ce57dc5cf12a10e0195af5705b566f