/** * 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]); }
/** * Activation User method * * @package las * @version 1.0 */ public function activation($role = 'login') { if ($this->getRole($role)) { // This user has login role, activation has already been completed return NULL; } else { // Add login role $userRole = new RolesUsers(); $userRole->user_id = $this->id; $userRole->role_id = Roles::findFirst('name="' . $role . '"')->id; if ($userRole->create() === true) { return TRUE; } else { \Las\Bootstrap::log($this->getMessages()); return $this->getMessages(); } } }