/** * new user validation method */ public function isValid(&$errors, $anyEmail = false) { // check to see if username has been taken // $user = User::getByUsername($this->username); if ($user != null) { $errors[] = 'The username "' . $this->username . '" is already in use.'; } // check to see if email address has been taken // $values = array(); $email = $this->email; if (preg_match("/(\\w*)(\\+.*)(@.*)/", $this->email, $values)) { $email = $values[1] . $values[3]; } foreach (self::getAll() as $registered_user) { $values = array(); if (preg_match("/(\\w*)(\\+.*)(@.*)/", $registered_user->email, $values)) { $registered_user->email = $values[1] . $values[3]; } if (strtolower($email) == strtolower($registered_user->email)) { $errors[] = 'The email address "' . $this->email . '" is already in use.'; break; } } // promo code presence check // $promo_found = false; if (Input::has('promo')) { $pdo = DB::connection('mysql')->getPdo(); $sth = $pdo->prepare('SELECT * FROM project.promo_code WHERE promo_code = :promo AND expiration_date > NOW()'); $sth->execute(array(':promo' => Input::get('promo'))); $result = $sth->fetchAll(PDO::FETCH_ASSOC); if ($result == false || sizeof($result) < 1) { if (!Input::has('email-verification')) { $errors[] = '"' . Input::get('promo') . '" is not a valid SWAMP promotional code or has expired.'; } } else { $promo_found = true; } } // user_external_id presense check // $user_external_id = Input::has('user_external_id'); // check to see if the domain name is valid // if (!$promo_found && !$user_external_id && $anyEmail !== true) { $domain = User::getEmailDomain($this->email); if (!User::isValidEmailDomain($domain)) { $errors[] = 'Email addresses from "' . $domain . '" are not allowed.'; } } return sizeof($errors) == 0; }