Exemplo n.º 1
0
 public static function requireLogin()
 {
     if (!self::isLoggedIn()) {
         redirect(Url::login());
     }
     return true;
 }
Exemplo n.º 2
0
 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());
 }
Exemplo n.º 3
0
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);
Exemplo n.º 4
0
 *	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());
    }
}