* Copyright 2001-2012 Strangecode, LLC * * This file is part of The Strangecode Codebase. * * The Strangecode Codebase is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your option) * any later version. * * The Strangecode Codebase 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 General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * The Strangecode Codebase. If not, see . */ /** * login.php */ // Redefine include_path including the codebase/services but allow local templates override global ones. ini_set('include_path', join(PATH_SEPARATOR, array( get_include_path(), dirname(__FILE__) . '/templates' ))); // We may want to use the add/edit interface from another script, so this // allows us to remember which page we came from so we can go back there. if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER']) || preg_match('!^(https?://\w+|/\w+)!', getFormData('boomerang'))) { $url = preg_match('!^(https?://\w+|/\w+)!', getFormData('boomerang')) ? getFormData('boomerang') : $_SERVER['HTTP_REFERER']; $app->setBoomerangURL($url, 'login'); } if ($auth->isLoggedIn()) { if ($app->validBoomerangURL('login')) { $app->dieBoomerangURL('login'); } $app->dieBoomerangURL($app->getParam('redirect_home_url', '/')); } // Cookie-based storage preferences. require_once 'codebase/lib/Prefs.inc.php'; $login_prefs = new Prefs('login'); $login_prefs->setParam(array('storagetype' => 'cookie')); $frm['username'] = getFormdata('username', $login_prefs->get('username')); $frm['password'] = getFormdata('password'); $frm['remember_me'] = ('' != $login_prefs->get('username')) ? '1' : ''; if (getFormdata('username', false)) { // Form has been submitted, check if the user login information is correct. if ($auth->login($frm['username'], $frm['password'])) { if (getFormData('remember_me')) { $login_prefs->set('username', getFormData('username')); } else { $login_prefs->set('username', ''); } // $app->raiseMsg(_("You are now logged in."), MSG_SUCCESS, __FILE__, __LINE__); $app->logMsg(sprintf('User %s successfully logged in.', $frm['username']), LOG_INFO, __FILE__, __LINE__); if ($app->validBoomerangURL('login')) { $app->dieBoomerangURL('login'); } } else { $app->raiseMsg(_("Log in failed, please try again."), MSG_NOTICE, __FILE__, __LINE__); $app->logMsg(sprintf('User %s failed log in (encrypted password: %s)', $frm['username'], $auth->encryptPassword($frm['password'])), LOG_NOTICE, __FILE__, __LINE__); } } // Titles and navigation header. $nav->add(_("Log in")); $nav->set('id', 'login'); // Templates. include 'header.' . $app->getParam('template_ext'); include 'login_form.ihtml'; include 'footer.' . $app->getParam('template_ext');