public async Task <IActionResult> Register(ApiUserDto apiUser) { // Function attempts to register the username // Validate request apiUser.Username = apiUser.Username.ToLower(); if (await _repo.UserExists(apiUser.Username)) { return(BadRequest("Username already exists")); } ApiUser newUser = new ApiUser { Username = apiUser.Username }; await _repo.Register(newUser, apiUser.Password); return(StatusCode(201)); // TODO: Send back the route for the new user //return CreatedAtRoute("", await _repo.Register(newUser, password)); }
public async Task <IActionResult> Login(ApiUserDto apiUser) { // Function attempts to log in the user account ApiUser userAccount = await _repo.Login(apiUser.Username, apiUser.Password); if (userAccount == null) { return(Unauthorized()); } // Fetch a JWT Token for this user account return(Ok(new { token = GenerateJwtToken(userAccount.Id.ToString(), userAccount.Username) })); }