Ejemplo n.º 1
0
 public static function attempt($array, $remember = false)
 {
     //Table::show(self::$hashedFields);
     //
     $hashed = array();
     //
     foreach ($array as $key => $value) {
         if (Table::contains(self::$hashedFields, $key)) {
             Table::add($hashed, Hash::make($array[$key]), $key);
         }
     }
     //
     //Table::show($hashed);
     //
     $where = "";
     $ok = false;
     //
     $i = 0;
     foreach ($array as $key => $value) {
         if ($i > 0) {
             $where .= " and ";
         }
         if (Table::contains(self::$hashedFields, $key)) {
             $where .= "{$key}='" . $hashed[$key] . "' ";
         } else {
             $where .= "{$key}='{$value}' ";
         }
         $i++;
     }
     $sql = "select * from " . self::$table . " where " . $where;
     //echo $sql;
     //
     if (Database::countS($sql) > 0) {
         //returning true value
         $ok = true;
         //
         // session
         $user = Database::read($sql);
         $saved = Config::get('auth.saved_fields');
         //
         $static = array();
         //
         foreach ($user[0] as $key => $value) {
             if (array_key_exists($key, $saved)) {
                 $static[$key] = $value;
             }
         }
         //
         Session::put('auths', $static);
         //
         // remember cookie
         if ($remember) {
             Cookie::create(Config::get('auth.rememeber_cookie'), $user[0]["rememberToken"], time() + 3600 * 24 * 7);
         }
     }
     //
     return $ok;
 }
Ejemplo n.º 2
0
 protected static function diffResource($only, $except)
 {
     $all = array('index', 'show', 'add', 'insert', 'edit', 'update', 'delete');
     //
     if (isset($except)) {
         $i = 0;
         foreach ($all as $value) {
             if (Table::contains($except, $value)) {
                 unset($all[$i]);
             }
             $i++;
         }
     }
     //
     if (isset($only)) {
         foreach ($all as $key => $value) {
             $ext = false;
             foreach ($only as $value2) {
                 if ($value == $value2) {
                     $ext = true;
                     break;
                 }
             }
             if (!$ext) {
                 unset($all[$key]);
             }
         }
     }
     return $all;
 }
Ejemplo n.º 3
0
 public static function checkRegister($root)
 {
     $data = self::getRegister($root);
     //
     $schemas = self::getSchemas($root);
     //
     // contains
     for ($i = 0; $i < Table::count($data); $i++) {
         if (!Table::contains($schemas, $data[$i]['name'])) {
             $data[$i]['state'] = "droped";
             $data[$i]['exec'] = time();
         }
     }
     //
     self::setRegister($data, $root);
 }