public function add(User $user)
 {
     // If Empty user submit throw Exception.
     if ($getUser = $this->getUserByUsername($user->GetUsername())) {
         throw new DbUserExistException();
     }
     try {
         $db = $this->connection();
         $sql = "INSERT INTO " . self::$dbTable . " (" . self::$userName . ", " . self::$password . ") VALUES (?, ?)";
         $params = array($user->GetUsername(), $user->GetPassword());
         $query = $db->prepare($sql);
         $query->execute($params);
     } catch (\PDOException $e) {
         throw new \Exception();
     }
 }
Ejemplo n.º 2
0
 public function Add(\model\User $user)
 {
     if ($this->GetRegistrationsForHour() > self::$MAX_REGISTRATIONS_PER_HOUR) {
         throw new \Exception("Max number of registrations per hour reached. Please try again in 30-60 minutes.");
     }
     // Throw exception if username is taken
     if ($this->GetUserByUsername($user->GetUserName())) {
         throw new \Exception(self::$DB_USERNAME_EXISTS);
     }
     try {
         // Prepare db statement
         $statement = self::$db->prepare('INSERT INTO ' . self::$DB_TABLE_NAME . '(user_id, user_name, user_password, date_time)' . ' VALUES ' . '(NULL, :userName, :password, NOW())');
         // Prepare input array
         $inputArray = ['userName' => $user->GetUserName(), 'password' => $user->GetPassword()];
         // Execute db statement
         $statement->execute($inputArray);
         // Check if db insertion was successful
         return $statement->rowCount() == 1;
     } catch (\Exception $exception) {
         throw new \Exception(self::$DB_INSERT_ERROR);
     }
 }