source: trunk/services/login.php @ 767

Last change on this file since 767 was 767, checked in by anonymous, 2 years ago

Add App param ‘template_ext’ used to inform services where to find header and footer templates. Minor fixes.

File size: 3.3 KB
RevLine 
[1]1<?php
2/**
[362]3 * The Strangecode Codebase - a general application development framework for PHP
4 * For details visit the project site: <http://trac.strangecode.com/codebase/>
[396]5 * Copyright 2001-2012 Strangecode, LLC
[462]6 *
[362]7 * This file is part of The Strangecode Codebase.
8 *
9 * The Strangecode Codebase is free software: you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your option)
12 * any later version.
[462]13 *
[362]14 * The Strangecode Codebase is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * details.
[462]18 *
[362]19 * You should have received a copy of the GNU General Public License along with
20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/**
[42]24 * login.php
[1]25 */
26
[497]27// Redefine include_path including the codebase/services but allow local templates override global ones.
28ini_set('include_path', join(PATH_SEPARATOR, array(
29    get_include_path(),
30    dirname(__FILE__) . '/templates'
31)));
32
[28]33// We may want to use the add/edit interface from another script, so this
34// allows us to remember which page we came from so we can go back there.
[761]35if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER']) || preg_match('!^(https?://\w+|/\w+)!', getFormData('boomerang'))) {
36    $url = preg_match('!^(https?://\w+|/\w+)!', getFormData('boomerang')) ? getFormData('boomerang') : $_SERVER['HTTP_REFERER'];
37    $app->setBoomerangURL($url, 'login');
[1]38}
39
[762]40if ($auth->isLoggedIn()) {
41    if ($app->validBoomerangURL('login')) {
42        $app->dieBoomerangURL('login');
43    }
44    $app->dieBoomerangURL($app->getParam('redirect_home_url', '/'));
45}
46
[477]47// Cookie-based storage preferences.
[462]48require_once 'codebase/lib/Prefs.inc.php';
49$login_prefs = new Prefs('login');
[477]50$login_prefs->setParam(array('storagetype' => 'cookie'));
[462]51
52$frm['username'] = getFormdata('username', $login_prefs->get('username'));
[1]53$frm['password'] = getFormdata('password');
[468]54$frm['remember_me'] = ('' != $login_prefs->get('username')) ? '1' : '';
[1]55
56if (getFormdata('username', false)) {
[103]57    // Form has been submitted, check if the user login information is correct.
[1]58
59    if ($auth->login($frm['username'], $frm['password'])) {
[462]60        if (getFormData('remember_me')) {
61            $login_prefs->set('username', getFormData('username'));
62        } else {
63            $login_prefs->set('username', '');
64        }
[761]65        // $app->raiseMsg(_("You are now logged in."), MSG_SUCCESS, __FILE__, __LINE__);
[673]66        $app->logMsg(sprintf('User %s successfully logged in.', $frm['username']), LOG_INFO, __FILE__, __LINE__);
[761]67
68        if ($app->validBoomerangURL('login')) {
69            $app->dieBoomerangURL('login');
70        }
[1]71    } else {
[767]72        $app->raiseMsg(_("Log in failed, please try again."), MSG_NOTICE, __FILE__, __LINE__);
73        $app->logMsg(sprintf('User %s failed log in (encrypted password: %s)', $frm['username'], $auth->encryptPassword($frm['password'])), LOG_NOTICE, __FILE__, __LINE__);
[1]74    }
75}
76
77// Titles and navigation header.
[767]78$nav->add(_("Log in"));
[535]79$nav->set('id', 'login');
[1]80
81// Templates.
[767]82include 'header.' . $app->getParam('template_ext');
[497]83include 'login_form.ihtml';
[767]84include 'footer.' . $app->getParam('template_ext');
[1]85
Note: See TracBrowser for help on using the repository browser.