Example #1
0
 /**
  *      Check if user want to remember his password
  *      If true - auth him
  */
 public function is_remember()
 {
     if (User::info()) {
         return false;
     }
     if (!isset($_COOKIE[$this->_session])) {
         return false;
     }
     $cookie = Cookie::getArray($this->_session);
     if (!isset($cookie['remember']) || (int) $cookie['remember'] == 0) {
         return false;
     }
     if (!isset($cookie['id']) || (int) $cookie['id'] == 0) {
         return false;
     }
     if (isset($cookie['exit']) && (int) $cookie['exit'] == 1) {
         return false;
     }
     if (!isset($cookie['exit'])) {
         Cookie::set($this->_session, array('remember' => (int) $cookie['remember'], 'exit' => 0, 'id' => $cookie['id']), 60 * 60 * 24 * 7);
     }
     $user = DB::select($this->_tbl . '.*', array($this->_tbl_roles . '.alias', 'role'))->from($this->_tbl)->join($this->_tbl_roles)->on($this->_tbl . '.role_id', '=', $this->_tbl_roles . '.id')->where($this->_tbl . '.status', '=', 1)->where($this->_tbl . '.id', '=', $cookie['id']);
     if (APPLICATION) {
         $user->where($this->_tbl_roles . '.alias', '!=', 'user');
     } else {
         $user->where($this->_tbl_roles . '.alias', '=', 'user');
     }
     $user = $user->find();
     if (!$user) {
         return false;
     }
     if ($this->auth($user, $cookie['remember'])) {
         HTTP::redirect(Arr::get($_SERVER, 'REQUEST_URI'));
     }
     return false;
 }