Esempio n. 1
0
 public function do($rule, $data)
 {
     if (!$this->check($rule, $data)) {
         return false;
     }
     $table = $data['table'];
     $action = $data['action'];
     $where = $data['where'];
     $data = $data['data'];
     $db = db::getInstance();
     $dbr = null;
     if ($action === 'select') {
         $dbr = $db->select($table, $data, $where);
     }
     if ($action === 'insert') {
         $dbr = $db->insert($table, $data);
     }
     if ($action === 'update') {
         $dbr = $db->update($table, $data, $where);
     }
     if ($action === 'delete') {
         $dbr = $db->delete($table, $where);
     }
     return $dbr;
 }
Esempio n. 2
0
 public function checkRoles($routeRoles)
 {
     if (empty($routeRoles)) {
         //Every one can access.
         return true;
     }
     $roles = null;
     if ($this->isLoggedIn()) {
         $db = db::getInstance();
         $roles = $db->select('aspa_role', 'role_names', ['user_id' => $this->userInfo['id']]);
         if (!empty($roles)) {
             $roles = $roles[0];
             $roles = json_decode($roles, true);
             if (!in_array('visitor', $roles)) {
                 $roles[] = 'visitor';
             }
             if (!in_array('user', $roles)) {
                 $roles[] = 'user';
             }
         } else {
             $roles = ['visitor', 'user'];
         }
     } else {
         $roles = ['visitor'];
     }
     if (in_array('admin', $roles)) {
         //Admin can access every where.
         return true;
     }
     $r = count(array_intersect($routeRoles, $roles)) >= 1;
     //If user has any one of roles required;
     return $r;
 }
Esempio n. 3
0
 public function clearSessions()
 {
     $db = db::getInstance();
     $db->delete('aspa_session', ['create_time[<]' => utils::datetimePHP2Mysql(time() - configHelper::getCoreConfig()['sessionValidTime'])]);
     return true;
 }