src/fursvp.api/Controllers/AuthController.cs
/// <summary>
/// Logs in a tester with the email address provided by verifying a cached verification code.
/// </summary>
/// <param name="verifyEmailRequest">The email address and verification code.</param>
/// <returns>OkObjectResult with the generated token on success, UnauthorizedResult otherwise.</returns>
Logs in a tester with the email address provided by verifying a cached verification code.
Logs in a tester with the email address provided by verifying a cached verification code .
[HttpPost]
        [Route("verifyemail")]
        public IActionResult VerifyEmail([FromBody]VerifyEmailRequest verifyEmailRequest)
        {
            if (verifyEmailRequest == null)
            {
                return BadRequest();
            }
            var verificationCodeCacheKey = VerificationCodeCacheKey(verifyEmailRequest.EmailAddress);
            if (MemoryCache.TryGetValue(verificationCodeCacheKey, out string verificationCode))
            {
                if (verificationCode == verifyEmailRequest.VerificationCode)
                {
                    ExpireVerificationCode(verifyEmailRequest.EmailAddress);
                    var token = CreateVerificationToken(verifyEmailRequest.EmailAddress, out string sessionId);
                    MemoryCache.Set("SessionId:" + sessionId, true);
                    return Ok(token);
                }
                IncrementFailedVerificationAttemptsOrExpire(verifyEmailRequest.EmailAddress);
            }
            return Unauthorized();
        }
[ HttpPost ] [ Route ( " " ) ] public IActionResult VerifyEmail ( [ FromBody ] VerifyEmailRequest verifyEmailRequest ) { if ( verifyEmailRequest == null ) { return BadRequest ( ) ; } var verificationCodeCacheKey = VerificationCodeCacheKey ( verifyEmailRequest . EmailAddress ) ; if ( MemoryCache . TryGetValue ( verificationCodeCacheKey , out string verificationCode ) ) { if ( verificationCode == verifyEmailRequest . VerificationCode ) { ExpireVerificationCode ( verifyEmailRequest . EmailAddress ) ; var token = CreateVerificationToken ( verifyEmailRequest . EmailAddress , out string sessionId ) ; MemoryCache . Set ( " " + sessionId , true ) ; return Ok ( token ) ; } IncrementFailedVerificationAttemptsOrExpire ( verifyEmailRequest . EmailAddress ) ; } return Unauthorized ( ) ; }
Logs in a tester with the email address provided by verifying a cached verification code.
Logs in a tester with the email address provided by verifying a cached verification code .
// authentication successful.
OkObjectResult with the generated token on success, UnauthorizedResult otherwise.
OkObjectResult with the generated token on success UnauthorizedResult otherwise .
VerifyEmailRequest
[FromBody]
verifyEmailRequest
The email address and verification code.
The email address and verification code .