Ejemplo n.º 1
0
 function testPredefinedAuthentificator()
 {
     $tested = new SimpleAuthentificator();
     $user = $tested->login('editor', 'rotide');
     if (!$user) {
         return 'editor not logged in!';
     }
     if ($user->getName() !== 'editor') {
         return 'editor name is wrong!';
     }
     if (!$user->getPerms()->can()) {
         return 'perms are not right!';
     }
     $user = $tested->login('en_editor', 'editor_en');
     if (!$user) {
         return 'en_editor not logged in!';
     }
     if ($user->getName() !== 'en_editor') {
         return 'en_editor name is wrong';
     }
     if ($user->getLang() !== 'en') {
         return 'en_editor lang is wrong';
     }
     if ($user->getPerms()->can('page:en', 'ALL', 'hu')) {
         return 'en perms are not right!';
     }
     if ($user->getPerms()->can('USER', 'SAVE', 'EN')) {
         return 'en perms are not right!';
     }
 }
Ejemplo n.º 2
0
 function login($name, $pass)
 {
     try {
         $res = $this->userTable->getWhere("name=:name", array('name' => $name));
         $user = null;
         if ($res && isset($res[1][0])) {
             $user = $res[1][0];
         }
         if ($user && $this->isValidPass($pass, $user['pass'])) {
             $query = "SELECT grp.`{$this->groupTable->getPK()}`, grp.`name`, grp.`perms` \n                     FROM `{$this->groupTable->getName()}` grp,\n                          `{$this->userGroupsTable->getName()}` ugps\n                     WHERE ugps.`user` = :user AND\n                           grp.`{$this->groupTable->getPK()}` = ugps.`group`\n                ";
             $groups = $this->groupTable->execute($query, array('user' => $user[$this->userTable->getPK()]));
             $grps = array();
             foreach ($groups as $grp) {
                 $grps[] = new SimpleGroup(array('id' => intval($user[$this->groupTable->getPK()]), 'name' => $grp['name'], 'perms' => $this->createAuthObj($grp['perms'])));
             }
             return new SimpleUser(array('id' => intval($user[$this->userTable->getPK()]), 'name' => $name, 'lang' => $user['lang'], 'perms' => $this->createAuthObj($user['perms']), 'groups' => $grps));
         } else {
             // this case probably empty DB, or user doesn't exist
             if (file_exists('_SETUPOK')) {
                 return parent::login($name, $pass);
             }
         }
     } catch (Exception $e) {
         echo $e->getMessage();
         // this case probably empty DB, or user doesn't exist
         if (file_exists('_SETUPOK')) {
             return parent::login($name, $pass);
         }
     }
     return null;
 }