コード例 #1
0
ファイル: Tools.php プロジェクト: catlabinteractive/neuron
 public static function getInput($dat, $key, $type, $default = null)
 {
     if (is_string($dat)) {
         global ${$dat};
         $dat = ${$dat};
     }
     if (!isset($dat[$key])) {
         return $default;
     } else {
         // Check if the value has the right type
         if (NeuronCoreTools::checkInput($dat[$key], $type)) {
             switch ($type) {
                 // For date's return timestamp.
                 case 'date':
                     $time = explode('-', $dat[$key]);
                     return mktime(0, 0, 1, $time[1], $time[2], $time[0]);
                     break;
                 case 'datetime':
                     return new DateTime($dat[$key]);
                     break;
                 case 'base64':
                     return base64_decode($dat[$key]);
                     break;
                 default:
                     return $dat[$key];
                     break;
             }
         } else {
             if ($type == 'bool') {
                 return false;
             } else {
                 return $default;
             }
         }
     }
 }
コード例 #2
0
 /**
  * @param $email
  * @param $username
  * @param $password
  * @return bool|string
  * @throws \Neuron\Exceptions\InvalidParameter
  */
 private function processRegister($email, $username, $password)
 {
     $mapper = MapperFactory::getUserMapper();
     ExpectedType::check($mapper, UserMapper::class);
     // Check email invalid
     if (!$email) {
         return 'EMAIL_INVALID';
     }
     // Check username input
     if (!$username) {
         return 'USERNAME_INVALID';
     }
     // Check if password is good
     if (!Tools::checkInput($password, 'password')) {
         return 'PASSWORD_INVALID';
     }
     // Check if email is unique
     $user = $mapper->getFromEmail($email);
     if ($user) {
         return 'EMAIL_DUPLICATE';
     }
     // Check if username is unique
     $user = $mapper->getFromUsername($username);
     if ($user) {
         return 'USERNAME_DUPLICATE';
     }
     // Create the user
     $user = new User();
     $user->setEmail($email);
     $user->setUsername($username);
     $user->setPassword($password);
     $user = $mapper->create($user);
     if ($user) {
         return $this->module->register($this->request, $user);
     } else {
         return $mapper->getError();
     }
 }
コード例 #3
0
ファイル: Request.php プロジェクト: catlabinteractive/neuron
 /**
  * Similar to fetching a value from $_REQUEST
  * @param $field
  * @param string $type
  * @param mixed $default
  * @param string $separator
  * @return mixed|null
  */
 public function input($field, $type = 'string', $default = null, $separator = ',')
 {
     // Check for array type
     $array = false;
     if (substr($type, -2) === '[]') {
         $arrtype = substr($type, 0, -2);
         $type = 'string';
         $array = true;
     }
     // Check post
     $value = Tools::getInput($this->getPost(), $field, $type);
     if ($value === null) {
         // Check get
         $value = Tools::getInput($this->getParameters(), $field, $type);
     }
     if ($value === null) {
         return $default;
     }
     // Check if array?
     if ($array) {
         $values = explode($separator, $value);
         $value = array();
         foreach ($values as $v) {
             if (Tools::checkInput($v, $arrtype)) {
                 $value[] = $v;
             }
         }
     }
     return $value;
 }
コード例 #4
0
 public function testDateInput()
 {
     $this->assertTrue(Tools::checkInput('2015-06-01T10:00', 'datetime'));
     $this->assertFalse(Tools::checkInput('06-01-2015T10:00', 'datetime'));
 }