Пример #1
0
 /**
  * Actives user by using a selector:token key
  *
  * @param string $key
  *            Key to use for activation
  */
 public function activateUser(string $key)
 {
     // Get tokendate from db
     $tokenhandler = new ActivationToken($this->db);
     $tokenhandler->setSelectorTokenString($key);
     // Store the current to extracted from selector:token string ($key)
     $token_from_key = $tokenhandler->getActivationToken();
     // Load the tokendata by using the selector from selector:token string ($key)
     $tokenhandler->loadTokenData();
     // Get user id
     $id_user = $tokenhandler->getUserId();
     // No user id means the activation must fail
     if (empty($id_user)) {
         return false;
     }
     // Get the token loaded from db via selector from selector:token string ($key)
     $token_from_db = $tokenhandler->getActivationToken();
     // Matching hashes?
     if (!hash_equals($token_from_key, $token_from_db)) {
         return false;
     }
     // Activate user
     $this->db->qb(['table' => $this->table, 'method' => 'UPDATE', 'fields' => 'state', 'filter' => 'id_user=:id_user', 'params' => [':state' => 0, ':id_user' => $id_user]], true);
     // and delete the token of this user
     $tokenhandler->deleteActivationToken();
     // And finally return user id
     return $id_user;
 }
Пример #2
0
 /**
  * Removes a group from DB and groups list
  *
  * @param integer $id_group
  *
  *
  * @throws DatabaseException
  */
 public function removeGroup($id_group)
 {
     try {
         $this->db->beginTransaction();
         // Delete usergroup
         $this->db->qb(['table' => 'core_groups', 'method' => 'DELETE', 'filter' => 'id_group = :id_group', 'params' => [':id_group' => $id_group]]);
         $this->db->execute();
         // Delete permissions related to this group
         $this->db->qb(['table' => 'core_permissions', 'method' => 'DELETE', 'filter' => 'id_group = :id_group', 'params' => [':id_group' => $id_group]]);
         $this->db->execute();
         // Remove group from current grouplist
         unset($this->groups[$id_group]);
         $this->db->endTransaction();
     } catch (\PDOException $e) {
         $this->db->cancelTransaction();
         throw new GroupException($e->getMessage(), $e->getCode(), $e->getPrevious());
     }
 }
Пример #3
0
 /**
  * Creates log entry in Db and return log id
  *
  * @return int
  */
 public function add() : int
 {
     if (empty($this->logdate) || empty($this->logstamp)) {
         $time = time();
         if (empty($this->logdate)) {
             $this->logdate = date('Y-m-d H:i:s', $time);
         }
         if (empty($this->logstamp)) {
             $this->logstamp = $time;
         }
     }
     if (empty($this->client)) {
         $this->client = $_SERVER['HTTP_USER_AGENT'];
     }
     if (empty($this->ip)) {
         $this->ip = $_SERVER['REMOTE_ADDR'];
     }
     if (empty($this->url)) {
         $this->url = $_SERVER['REQUEST_URI'];
     }
     $this->db->qb(['table' => 'core_bans', 'data' => ['text' => $this->text, 'logdate' => $this->logdate, 'logstamp' => $this->logstamp, 'client' => $this->client, 'ip' => $this->ip, 'url' => $this->url, 'id_user' => $this->id_user, 'code' => $this->code]], true);
     return $this->db->lastInsertId();
 }
Пример #4
0
 /**
  * Returns the timestamp from log when ban got active for this ip
  *
  * @return int
  */
 public function getBanActiveTimestamp() : int
 {
     $this->db->qb(['table' => 'core_bans', 'fields' => 'logstamp', 'filter' => 'ip=:ip AND code=0', 'params' => [':ip' => $this->ip], 'order' => 'logstamp DESC', 'limit' => 1]);
     $data = $this->db->value();
     return $data ? $data : 0;
 }