Exemple #1
0
 /**
  * Initialize
  *
  * @package     las
  * @version     1.0
  */
 public function initialize()
 {
     // Redirect to home page if user is not admin
     if (!$this->auth->logged_in('admin')) {
         $adminRole = Roles::findFirst('name="admin"');
         if (!RolesUsers::count('role_id=' . $adminRole->id)) {
             $this->response->redirect('install');
         } else {
             $this->response->redirect('');
         }
     }
     // Check the session lifetime
     if ($this->session->has('last_active') && time() - $this->session->get('last_active') > $this->config->session->options->lifetime) {
         $this->session->destroy();
     }
     $this->session->set('last_active', time());
     // Set the language from session
     if ($this->session->has('lang')) {
         $this->i18n->lang($this->session->get('lang'));
         // Set the language from cookie
     } elseif ($this->cookies->has('lang')) {
         $this->i18n->lang($this->cookies->get('lang')->getValue());
     }
     // Get the settings
     $this->las = Arr::from_model(Settings::find(['status = ' . Settings::ACTIVE]), 'category', ['name' => 'value']);
     // Send langs to the view
     $this->view->setVars(['siteLangs' => array_map('__', $this->config->i18n->langs->toArray()), 'las' => $this->las]);
 }
Exemple #2
0
 /**
  * Get user's role relation
  *
  * @package     las
  * @version     1.0
  *
  * @param string $role role to get one RolesUsers
  */
 public function getRole($role = 'login')
 {
     $role = Roles::findFirst(array('name=:role:', 'bind' => array(':role' => $role)));
     // Return null if role does not exist
     if (!$role) {
         return null;
     }
     // Return the role if user has the role otherwise false
     return $this->getRoles(array('role_id=:role:', 'bind' => array(':role' => $role->id)))->getFirst();
 }