Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // *** Request model ***
- public class ValidateEmailRequest
- {
- public string Username { get; set; }
- public string B64SecToken { get; set; }
- }
- // *** Service (repository) method implementation ***
- public void ValidateEmail(ValidateEmailRequest request)
- {
- var target = _users.FirstOrDefault(x =>
- x.Username == request.Username && x.SecurityToken == request.B64SecToken);
- if (target == null)
- throw new InvalidOperationException("Authentication failed");
- target.IsConfirmed = true;
- }
- // *** Validate email action implementation (return generated email validation token) ***
- [HttpPost("[action]")]
- public ActionResult ValidateEmail([FromBody] ValidateEmailRequest request)
- {
- try
- {
- _userRepository.ValidateEmail(request);
- return Ok();
- }
- catch (InvalidOperationException ex)
- {
- return BadRequest(ex.Message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement