/** * Index action - add admin user * * @package las * @version 1.0 */ public function indexAction() { // Set title, pick view and send variables $this->tag->setTitle(__('Install')); $this->view->pick('user/signup'); // Check if the form has been sent if ($this->request->isPost() == TRUE) { $user = new Users(); $signup = $user->signup(true); if ($signup instanceof Users) { $hash = md5($signup->id . $signup->email . $signup->password . $this->config->auth->hash_key); $this->response->redirect('user/activation/' . $signup->username . '/' . $hash . '/admin'); } else { $this->view->setVar('errors', $signup); $this->flashSession->warning($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors.")); } } }
/** * Activation Action * * @package las * @version 1.0 */ public function activationAction() { $this->view->pick('msg'); $this->tag->setTitle(__('Activation')); $this->view->setVar('title', __('Activation')); $params = $this->router->getParams(); $user = Users::findFirst(array('username=:user:'******'bind' => array('user' => $params[0]))); if ($user && md5($user->id . $user->email . $user->password . $this->config->auth->hash_key) == $params[1]) { if (isset($params[2]) && $params[2] == 'admin') { $user->activation('login'); $activation = $user->activation('admin'); } else { $activation = $user->activation(); } if ($activation === NULL) { $this->flashSession->notice($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Notice') . '!</strong> ' . __("Activation has already been completed.")); } elseif ($activation === TRUE) { $this->flashSession->success($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Success') . '!</strong> ' . __("Activation completed. Please log in.")); $this->view->setVar('redirect', 'user/signin'); } } else { $this->flashSession->error($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Error') . '!</strong> ' . __("Activation cannot be completed. Invalid username or hash.")); } }
/** * Refresh user data stored in the session from the database. * Returns null if no user is currently logged in. * * @package las * @version 1.0 * * @return mixed */ public function refresh_user() { $user = $this->_session->get($this->_config['session_key']); if (!$user) { return null; } else { // Get user's data from db $user = Users::findFirst($user->id); $roles = $this->get_roles($user); // Regenerate session_id session_regenerate_id(); // Store user in session $this->_session->set($this->_config['session_key'], $user); // Store user's roles in session if ($this->_config['session_roles']) { $this->_session->set($this->_config['session_roles'], $roles); } return $user; } }