Пример #1
0
 /**
  * addRole
  * @param int $player_id
  * @param int $role_id
  * @return int
  */
 public function addRole($player_id, $role_id)
 {
     $data['player_id'] = intval($player_id);
     $data['role_id'] = intval($role_id);
     $data['id'] = parent::add($data);
     return $data['id'];
 }
Пример #2
0
 public function create($data)
 {
     return parent::add($data);
 }
Пример #3
0
 /**
  * create
  * Creates a new player (registration)
  * Exception codes
  * 1 - Invalid email
  * 2 - Invalid username
  * 4 - Username in use
  * 8 - Email in use
  * 16 - Invalid confirm password
  * 32 - Invalid password
  * 
  * @param array $data
  * @throws Exception
  * @throws InvalidArgumentException
  * @return unknown
  */
 public function create($data)
 {
     /* It's good for UI to produce a list of invalid input */
     $errors = array();
     /* Validate email address against ??(unknown) specification */
     if (!filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
         $errors[] = new InvalidArgumentException('An invalid email address was provided', 1);
     }
     /* Validate username for length */
     if (strlen($data['username']) > 25 || strlen($data['username']) < 3) {
         $errors[] = new InvalidArgumentException('Username length is invalid, it should be more than three characters and less than twenty-five', 2);
     }
     /* Check for the possible existence of accounts with same username */
     if ($this->find($data['username'], 'username')) {
         $errors[] = new InvalidArgumentException('Another account is already registered with the same username', 4);
     }
     /* Check for an existent account with same email-address */
     if ($this->find($data['email'], 'email')) {
         $errors[] = new InvalidArgumentException('Email address is already associated with another account', 8);
     }
     /* Check that confirmation password is the same as password */
     if ($data['confirm_password'] !== $data['password']) {
         $errors[] = new InvalidArgumentException('Confirmation password does not match original', 16);
     }
     unset($data['confirm_password']);
     /* Check password validity against predefined algorithm */
     $configPasswordStrength = 1;
     //$this->container['config']['security']['passwordStrength'];
     $password_regex = array(0 => '/[a-z]{6,}/', 1 => '/[a-zA-Z]{8,}/', 2 => '/[a-zA-Z0-9]{8,}', 3 => '/[a-zA-Z0-9\\!@#\\$%\\^&\\*\\(\\)-_=+\\{\\};:,<\\.>]/{8,}');
     if (preg_match($password_regex[$configPasswordStrength], $data['password']) === false || empty($data['password'])) {
         $password_message = 'Password is too simple, ';
         /* Generate a nice message */
         switch ($configPasswordStrength) {
             case 0:
                 $password_message .= 'should contain alphabetic characters and be six characters or longer';
                 break;
             case 1:
                 $password_message .= 'should contain capitalized characters and be eight characters or longer';
                 break;
             case 2:
                 $password_message .= 'should contain capitalized characters, numbers and be eight characters or longer';
                 break;
             case 3:
                 $password_message .= 'should contain capitalized characters, numbers, symbols and be eight characters or longer';
                 break;
         }
         $errors[] = new InvalidArgumentException($password_message, 32);
     }
     /* If there were any errors, quit early */
     if (count($errors) != 0) {
         throw new Exception(serialize($errors), null, end($errors));
     }
     /* All checks succeeded, continue data formatting */
     $data['password'] = password_hash($data['password'], PASSWORD_BCRYPT);
     $data['title'] = ucfirst($data['username']);
     $data['registered'] = date('Y-m-d H:i:s');
     $data['lastActive'] = $data['registered'];
     $data['active'] = \App::registerHook('playerActivation', $data)[0];
     //this is ghetto. Figure out why it's doing this!
     /* Create the actual record */
     $data['player_id'] = parent::add($data);
     /* Fire playerRegistration hook */
     $pluginData = \App::registerHook('playerRegistration', $data);
     if (is_array($pluginData)) {
         $data = $pluginData;
     }
     return $data;
 }
Пример #4
0
 public function create($args)
 {
     return parent::add($args);
 }