Ejemplo n.º 1
0
 /**
  * getUserByLogin - Check login data andset email vars
  *
  * @access public
  * @param $emailname
  * @param $password
  * @return boolean
  */
 public function getUserByLogin($username, $password)
 {
     $query = "SELECT username, password FROM zp_user \n\t\t          WHERE username = :username LIMIT 1";
     $stmn = $this->db->{'database'}->prepare($query);
     $stmn->bindValue(':username', $username, PDO::PARAM_STR);
     $stmn->execute();
     $returnValues = $stmn->fetch();
     $userCounter = count($returnValues);
     $stmn->closeCursor();
     //echo 'getUserByLogin count:'. $userCounter;
     if ($userCounter === false || !$this->hasher->CheckPassword($password, $returnValues['password'])) {
         //echo 'return false<br>';
         unset($_SESSION['userdata']);
         unset($_SESSION['template']);
         unset($_COOKIE);
         return false;
     } else {
         //
         $query = "SELECT \n\t\t\t\t\tid,\n\t\t\t\t\tusername,\n\t\t\t\t\trole,\n\t\t\t\t\tlastname AS name\n\t\t\t\t\t\n\t\t\t\t\t\tFROM zp_user \n\t\t\t          WHERE username = :username\n\t\t\t          LIMIT 1";
         //echo $query;
         $stmn = $this->db->{'database'}->prepare($query);
         $stmn->bindValue(':username', $username, PDO::PARAM_STR);
         $stmn->execute();
         $returnValues = $stmn->fetch();
         $stmn->closeCursor();
         $this->name = $returnValues['name'];
         $this->mail = $returnValues['username'];
         $this->userId = $returnValues['id'];
         $user = new users();
         $roles = $user->getRole($returnValues['role']);
         $this->role = $roles['roleName'];
         $setting = new setting();
         $roleArray = explode(',', $this->role);
         $this->sysOrgs = $setting->getSysOrgsStringByRoles($roleArray);
         return true;
     }
 }