Esempio n. 1
0
File: jx.php Progetto: jonlb/JxCMS
 /**
  * Logs a user in.
  *
  * @param   string   username
  * @param   string   password
  * @param   boolean  enable auto-login
  * @return  boolean
  */
 public function _login($user, $password, $remember)
 {
     // Make sure we have a user object
     //Jx_Debug::dump($user,'User passed in');
     $user = $this->_get_object($user);
     //Jx_Debug::dump(null,'In _login');
     //Jx_Debug::dump($user->password,'User password after getting object');
     //Jx_Debug::dump($password,'Password passed in');
     // If the passwords match, perform a login
     if (Jx_Acl::check_for_cap('allow_login', $user) and $user->password === $password) {
         if ($remember === TRUE) {
             // Create a new autologin token
             $token = Model::factory('user_token');
             // Set token data
             $token->user = $user->id;
             $token->expires = time() + $this->_config['lifetime'];
             $token->create();
             // Set the autologin Cookie
             Cookie::set('authautologin', $token->token, $this->_config['lifetime']);
         }
         // Finish the login
         //Jx_Debug::dump(null, 'finishing login');
         $this->complete_login($user);
         return TRUE;
     }
     // Login failed
     return FALSE;
 }
Esempio n. 2
0
File: site.php Progetto: jonlb/JxCMS
 public function before()
 {
     $this->auth = Auth::instance();
     $user = $this->auth->get_user();
     //Jx_Debug::dump($this->auth,'auth object');
     //Jx_Debug::dump($user, 'User object');
     $capabilities = FALSE;
     //first check $this->security_all
     if ($this->security_all !== FALSE) {
         if (is_array($this->security_all)) {
             $capabilities = $this->security_all;
         } else {
             $capabilities = array($this->security_all);
         }
     }
     if ($this->security_action !== FALSE && array_key_exists($this->request->action, $this->security_action)) {
         $c = $this->security_action[$this->request->action];
         if (is_array($c)) {
             $capabilities = array_merge($capabilities, $c);
         } else {
             $capabilities[] = $c;
         }
     }
     //Jx_Debug::dump($capabilities, 'checking for capabilities');
     if (FALSE !== $capabilities) {
         if (in_array(Jx_Acl::get_login_cap(), $capabilities) && !$this->auth->logged_in()) {
             //Jx_Debug::dump(null,'not logged in');
             Session::instance()->set('redirect', array('fromUrl' => $this->request->uri));
             $this->request->redirect(Route::get('users')->uri(array('action' => 'login')));
         } else {
             if (!Jx_Acl::check_for_cap($capabilities, $user)) {
                 //Jx_Debug::dump(null, 'no capability');
                 Session::instance()->set('redirect', array('fromUrl' => $this->request->uri));
                 //$this->request->redirect(Route::get('users')->uri(array('action'=>'denied')));
             }
         }
     }
     //Jx_Debug::dump(null, 'checks passed');
     if ($this->auto_render) {
         $this->template = Jx_View::factory($this);
     }
     return parent::before();
 }