public async Task <IActionResult> CreateByCredentials([FromBody] CredentialHolder credentialHolder) { if (!ModelState.IsValid) { return(_exceptionHandler.HandleException(new Exception("ModelState was invalid"), isServerSideException: false)); } try { var newUserAccount = await _accountAdapter.CreateByEmailAndPasswordAsync(credentialHolder.Email, credentialHolder.Password); if (newUserAccount != null && !string.IsNullOrEmpty(newUserAccount.Id) && !string.IsNullOrEmpty(newUserAccount.Email)) { return(new CreatedAtActionResult( actionName: Constants.AccountControllerEndpoints.CREATE_BY_ACCOUNT, controllerName: Constants.APIControllers.ACCOUNT, routeValues: RouteData.Values, value: newUserAccount.Id)); } else { throw new Exception("Creating account failed. The user account was null, Email was null or had no id after an attempt to create it"); } } catch (Exception ex) { return(_exceptionHandler.HandleException(ex, isServerSideException: true)); } }
public async Task <IActionResult> LogInAsync([FromBody] CredentialHolder credentials) { if (!ModelState.IsValid) { return(_exceptionHandler.HandleException(new Exception("ModelState was invalid"), isServerSideException: false)); } var result = await _identityAdapter.LogIn(credentials); if (result.IsSucceeded == false) { StringBuilder stringBuilder = new StringBuilder(); foreach (var error in result.Errors) { stringBuilder.AppendLine(error); } return(_exceptionHandler.HandleException(new Exception(stringBuilder.ToString()), isServerSideException: true)); } return(Ok(result.UserToken)); }