/**
  * Signs up a new user by e-mail
  *
  * @url POST /user/signup/
  */
 public function signUp()
 {
     global $messages, $authIssueText;
     $websiteName = Settings::getInstance()->p['websiteName'];
     //$eMailSendFrom = Settings::getInstance()->p['supportEmail'];
     $email = $_POST['email'];
     $password = $_POST['password'];
     $country = $_POST['country'];
     if (strlen($email) == 0 || strlen(password) == 0) {
         throw new RestException(400, "Wrong or missing parameters.");
     }
     $language = "it";
     // Settings::getInstance()->p['language'];
     $sql = "SELECT UserStateId FROM User WHERE Email = '{$email}'";
     $result = $this->mysqli->query($sql) or die($authIssueText);
     $recordsCount = mysqli_num_rows($result);
     $row = mysqli_fetch_array($result);
     if ($recordsCount > 0 && $row['UserStateId'] != 0) {
         throw new RestException(403, "Forbidden - The user already exists." . $sql);
     } else {
         $registrationCode = generateRandomString(10);
         if (!parent::CreateUser($email, $password, $registrationCode, $country, $language)) {
             throw new RestException(400, "Bad Request - The request was invalid or cannot be otherwise served.");
         } else {
             $newUserMessage = $messages[$language]["createUserMessage"];
             $newUserMessage = str_replace("<<SendTo>>", $email, $newUserMessage);
             $newUserMessage = str_replace("<<RegistrationCode>>", $registrationCode, $newUserMessage);
             $mailer = new PHPMailer();
             $mailer->isSMTP();
             // Set mailer to use SMTP
             $mailer->Host = Settings::getInstance()->p['emailHost'];
             // Specify main and backup SMTP servers
             $mailer->SMTPAuth = true;
             // Enable SMTP authentication
             $mailer->Username = Settings::getInstance()->p['email'];
             // SMTP username
             $mailer->Password = Settings::getInstance()->p['emailPassword'];
             // SMTP password
             //$mailer->SMTPSecure = 'tls';                            			// Enable TLS encryption, `ssl` also accepted
             $mailer->Port = Settings::getInstance()->p['emailPort'];
             // TCP port to connect to
             $mailer->setFrom(Settings::getInstance()->p['email'], 'Support');
             $mailer->addAddress($email);
             $mailer->addReplyTo(Settings::getInstance()->p['email'], 'Information');
             $mailer->isHTML(false);
             // Set email format to HTML
             $mailer->Subject = $websiteName . ' ';
             $mailer->Body = $newUserMessage;
             // HTML message body <b>in bold!</b>
             $mailer->AltBody = $newUserMessage;
             // Plain text body for non-HTML mail clients
             if (!$mailer->send()) {
                 echo 'Message could not be sent.';
                 echo 'Mailer Error: ' . $mailer->ErrorInfo;
                 return "ERROR";
             }
             return "OK";
         }
     }
 }