Academatica.Api/Academatica.Api.Users/Controllers/UsersController.cs
/// <summary>
/// Endpoint used to check if specified code is equal to an email change confirmation code sent to the user's email address.
/// </summary>
/// <param name="id">User ID.</param>
/// <param name="code">Code to check.</param>
Endpoint used to check if specified code is equal to an email change confirmation code sent to the user's email address.
Endpoint used to check if specified code is equal to an email change confirmation code sent to the user ' s email address .
[HttpGet]
        [Route("{id}/email/confirmation-code")]
        public async Task<IActionResult> CheckUserEmailConfirmationCode(Guid id, [FromQuery] string code)
        {
            var userId = User.FindFirst("sub")?.Value;
            if (userId != id.ToString())
            {
                return Forbid();
            }
            var user = _academaticaDbContext.Users.Where(x => x.Id == id).FirstOrDefault();
            if (user == null)
            {
                return NotFound("Invalid user ID.");
            }
            if (code == null)
            {
                return BadRequest("No confirmation code specified.");
            }
            var cachedCode = await _confirmationCodeManager.GetEmailConfirmationCode(user.Id);
            if (cachedCode == code)
            {
                return Ok(new CheckUserEmailConfirmationCodeResponseDto
                {
                    Success = true
                });
            } else
            {
                return Ok(new CheckUserEmailConfirmationCodeResponseDto
                {
                    Success = false
                });
            }
        }
[ HttpGet ] [ Route ( " " ) ] public async Task < IActionResult > CheckUserEmailConfirmationCode ( Guid id , [ FromQuery ] string code ) { var userId = User . FindFirst ( " " ) ? . Value ; if ( userId != id . ToString ( ) ) { return Forbid ( ) ; } var user = _academaticaDbContext . Users . Where ( x => x . Id == id ) . FirstOrDefault ( ) ; if ( user == null ) { return NotFound ( " " ) ; } if ( code == null ) { return BadRequest ( " " ) ; } var cachedCode = await _confirmationCodeManager . GetEmailConfirmationCode ( user . Id ) ; if ( cachedCode == code ) { return Ok ( new CheckUserEmailConfirmationCodeResponseDto { Success = true } ) ; } else { return Ok ( new CheckUserEmailConfirmationCodeResponseDto { Success = false } ) ; } }
Endpoint used to check if specified code is equal to an email change confirmation code sent to the user's email address.
Endpoint used to check if specified code is equal to an email change confirmation code sent to the user ' s email address .
id
Guid
None
string
[FromQuery]
code
Code to check.
Code to check .