Skip to content

Instantly share code, notes, and snippets.

@Mirch
Created March 24, 2019 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mirch/5fba760a2be851f07317d912f3bbe463 to your computer and use it in GitHub Desktop.
Save Mirch/5fba760a2be851f07317d912f3bbe463 to your computer and use it in GitHub Desktop.
[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