/**
  * Get option by key
  *
  * @param string[] $columns Column values for filtering
  *
  * @return mixed Option value
  *
  * @since  1.0.0
  * @author Dennis Eichhorn <*****@*****.**>
  */
 public function get($columns)
 {
     //$key = md5(json_encode($columns));
     $options = false;
     switch ($this->connection->getType()) {
         case \phpOMS\DataStorage\Database\DatabaseType::MYSQL:
             $sth = $this->connection->con->prepare('SELECT `' . static::$columns[0] . '`, `settings_content` FROM `' . $this->connection->prefix . static::$table . '` WHERE ' . '`' . $this->connection->prefix . static::$table . '`.`' . static::$columns[0] . '` IN (' . implode(',', $columns) . ')');
             $sth->execute();
             $options = $sth->fetchAll(\PDO::FETCH_KEY_PAIR);
             $this->setOptions($options);
             break;
     }
     return $options;
 }
示例#2
0
 /**
  * Login user
  *
  * @param string $login    Username
  * @param string $password Password
  *
  * @return int Login code
  *
  * @since  1.0.0
  * @author Dennis Eichhorn <*****@*****.**>
  */
 public function login($login, $password)
 {
     try {
         $result = null;
         switch ($this->connection->getType()) {
             case \phpOMS\DataStorage\Database\DatabaseType::MYSQL:
                 $sth = $this->connection->con->prepare('SELECT
                         `' . $this->connection->prefix . 'account_data`.*,
                         `' . $this->connection->prefix . 'account`.*
                     FROM
                         `' . $this->connection->prefix . 'account_data`
                     LEFT JOIN
                         `' . $this->connection->prefix . 'account`
                     ON
                         `account_data_account` = `account_id`
                     WHERE
                         `account_data_login` = :login');
                 $sth->bindValue(':login', $login, \PDO::PARAM_STR);
                 $sth->execute();
                 $result = $sth->fetchAll();
                 break;
         }
         // TODO: check if user is allowed to login on THIS page (backend|frontend|etc...)
         if (!isset($result[0])) {
             return \phpOMS\Auth\LoginReturnType::WRONG_USERNAME;
         }
         $result = $result[0];
         if ($result['account_data_tries'] <= 0) {
             return \phpOMS\Auth\LoginReturnType::WRONG_INPUT_EXCEEDED;
         }
         if (password_verify($password, $result['account_data_password'])) {
             $this->session->set('UID', $result['account_id']);
             $this->session->save();
             return \phpOMS\Auth\LoginReturnType::OK;
         }
         return \phpOMS\Auth\LoginReturnType::WRONG_PASSWORD;
     } catch (\Exception $e) {
         return \phpOMS\Auth\LoginReturnType::FAILURE;
     }
 }