Created
March 24, 2019 19:33
-
-
Save Mirch/5fba760a2be851f07317d912f3bbe463 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost("register")] | |
public async Task<IActionResult> Register([FromBody]UserCredentials credentials) | |
{ | |
var alreadyExists = _context.Users.Any(u => u.Email == credentials.Email); | |
if (alreadyExists) | |
{ | |
return BadRequest("User already exists."); | |
} | |
(string hashedPass, string salt) = _hashingService.Hash(credentials.Password); | |
var user = new User() { Email = credentials.Email, HashedPassword = hashedPass, Salt = salt }; | |
_context.Users.Add(user); | |
await _context.SaveChangesAsync(); | |
return Ok(BuildToken(user.Email)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment