private UserEntity Map(BasicIdentity from) { return(new UserEntity() { Email = from.Email, FirstName = from.FirstName, LastName = from.LastName, Password = from.Password }); }
public BasicIdentity Register(BasicIdentity user, string password) { // validation if (string.IsNullOrWhiteSpace(password)) { throw new Exception("Password is required"); } if (repository.Read(user.Email) != null) { throw new Exception("Username \"" + user.Email + "\" is already taken"); } repository.Add(Map(user)); return(user); }
public IActionResult Register([FromBody] RegistrationRequestModel requestModel) { var user = new BasicIdentity() { Email = requestModel.Email, Password = requestModel.Password }; try { var newUser = _userService.Register(user, requestModel.Password); var loggedInUser = _userService.Authenticate(newUser.Email, newUser.Password); return(Ok(loggedInUser)); } catch (Exception ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }