public static function requireLogin() { if (!self::isLoggedIn()) { redirect(Url::login()); } return true; }
public static function init() { self::$config_name = 'client'; self::$session_name = 'client_token'; self::$session_table = 'client_session'; self::$user_primary_key = 'contact_id'; self::$urls_nologin = array(Url::login(), Url::signup()); }
function redirect($url) { if (empty($url) && class_exists('\\LSS\\Url') && \LSS\Url::_isCallable('home')) { $url = \LSS\Url::home(); } elseif (empty($url)) { $url = '/'; } //should get us home header('Location: ' . $url); exit; }
if (post('login')) { try { //get the client member $client = Client::fetchByEmail(post('email')); if (!$client) { throw new Exception('Client member doesnt exist'); } //check password if (!bcrypt_check(post('password'), $client['password'])) { throw new Exception('Password is invalid'); } //generate token and setup session $token = ClientSession::tokenCreate($client['client_id'], server('REMOTE_ADDR'), server('HTTP_USER_AGENT')); ClientSession::startSession($token); //update last login Client::updateLastLogin($client['client_id']); //redirect request if (session('login_referrer') && strpos(session('login_referrer'), Url::login()) === false) { redirect(session('login_referrer')); } else { redirect(Url::home()); } } catch (Exception $e) { alert($e->getMessage(), false); } } session('login_referrer', server('HTTP_REFERER')); $params = array(); $params['url_login'] = Url::login(); $params['page_title'] = Config::get('site_name') . ' - Admin Login'; Tpl::_get()->output('client_login', $params);
* GNU Lesser General Public License along with OpenLSS. * If not, see <http://www.gnu.org/licenses/>. */ use LSS\Account\Client; use LSS\Account\ClientSession; use LSS\Config; use LSS\Url; if (session_id() != '') { //check for session try { if (ClientSession::checkLogin()) { //register session $token = ClientSession::fetchByToken(ClientSession::getTokenFromSession()); $session = array_merge(Client::fetch($token['staff_id']), $token); ClientSession::storeSession($session); unset($session, $token); //set tpl globals (if Tpl is available) if (is_callable(array('Tpl', '_get'))) { Tpl::_get()->set(array('client_name' => ClientSession::get('name'), 'client_lastlogin' => date(Config::get('account.date.general_format'), ClientSession::get('last_login')))); } } else { if (server('REQUEST_URI') != Url::login()) { redirect(Url::login()); } } } catch (Exception $e) { ClientSession::tokenDestroy(ClientSession::getTokenFromSession()); ClientSession::destroySession(); redirect(Url::login()); } }
<?php /** * OpenLSS - Lighter Smarter Simpler * * This file is part of OpenLSS. * * OpenLSS is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * OpenLSS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the * GNU Lesser General Public License along with OpenLSS. * If not, see <http://www.gnu.org/licenses/>. */ use LSS\Url; //register Url::home() if not already if (!Url::_isCallable('home')) { Url::_register('home', '/index.php'); } Url::_register('client', Url::home() . '?act=client'); Url::_register('profile', Url::client() . '&do=profile'); Url::_register('login', Url::client() . '&do=login'); Url::_register('logout', Url::client() . '&do=logout');
* This file is part of OpenLSS. * * OpenLSS is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * OpenLSS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the * GNU Lesser General Public License along with OpenLSS. * If not, see <http://www.gnu.org/licenses/>. */ use LSS\Account\Client; use LSS\Account\ClientSession; use LSS\Tpl; use LSS\Url; if (post('edit')) { try { Client::update(post('client_id'), post()); alert('client profile updated successfully', true, true); redirect(Url::profile()); } catch (Exception $e) { alert($e->getMessage(), false); } } $params = array_merge(Client::fetch(ClientSession::get('client_id')), post()); Tpl::_get()->output('client_profile', $params);
protected function setupEnv($tpl) { //setup globals if (!empty($this->css)) { $this->set('css', $this->css); } if (!empty($this->js)) { $this->set('js', $this->js); } //stats $stats = $this->stats(); if (!empty($stats)) { $this->set('stats', $stats); } unset($stats); //add global urls if the lib is loaded if (is_callable(array('\\LSS\\Url', '_all'))) { $tpl->url = Url::_all(); } //debug $debug = $this->debug(); if (!empty($debug)) { $this->set('debug', $debug); ob_start(); var_dump($debug); file_put_contents('/tmp/debug', ob_get_clean()); } unset($debug); //export globals to templating engine $tpl->global = $this->constants; return true; }