throw new Exception("Invalid character name", 400); } elseif (!$captcha) { throw new Exception("Captcha was not provided", 400); } else { // Validate Captcha $recaptcha = new \ReCaptcha\ReCaptcha(GOOGLE_RECAPTCHA_PRIVATE_KEY); $verify = $recaptcha->verify($captcha, $app->request->getIp()); if (!$verify->isSuccess()) { throw new Exception("Humanity not confirmed", 400); } // Create user $user = new User(); $user->email = $email; $user->name = $name; $user->avatar = ''; $password = $user->createRandomPassword(6); if ($user_id = $user->Create()) { // Send email $message = "Greetings {$name}!\n\nYour password:\n\n" . $password; if (!Mail::send($email, $name, "Account created", $message)) { throw new Exception("Error sending email", 500); } $app->render_json(["id" => $user_id]); // Create the user token for the first time Token::Update($user_id); } else { throw new Exception("Something went wrong!", 500); } } } });