source: trunk/services/login.php @ 483

Last change on this file since 483 was 477, checked in by anonymous, 10 years ago

Added cookie storage to Prefs(). Created App->addCookie method. Improved PHP version checks.

File size: 2.6 KB
Line 
1<?php
2/**
3 * The Strangecode Codebase - a general application development framework for PHP
4 * For details visit the project site: <http://trac.strangecode.com/codebase/>
5 * Copyright 2001-2012 Strangecode, LLC
6 *
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.
13 *
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.
18 *
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/**
24 * login.php
25 */
26
27// We may want to use the add/edit interface from another script, so this
28// allows us to remember which page we came from so we can go back there.
29if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) {
30    $app->setBoomerangURL($_SERVER['HTTP_REFERER'], 'login');
31}
32$app->sslOn();
33
34// Cookie-based storage preferences.
35require_once 'codebase/lib/Prefs.inc.php';
36$login_prefs = new Prefs('login');
37$login_prefs->setParam(array('storagetype' => 'cookie'));
38
39$frm['username'] = getFormdata('username', $login_prefs->get('username'));
40$frm['password'] = getFormdata('password');
41$frm['remember_me'] = ('' != $login_prefs->get('username')) ? '1' : '';
42
43if (getFormdata('username', false)) {
44    // Form has been submitted, check if the user login information is correct.
45
46    if ($auth->login($frm['username'], $frm['password'])) {
47        if (getFormData('remember_me')) {
48            $login_prefs->set('username', getFormData('username'));
49        } else {
50            $login_prefs->set('username', '');
51        }
52        $app->raiseMsg(_("You are now logged in."), MSG_SUCCESS, __FILE__, __LINE__);
53        $app->dieBoomerangURL('login');
54        $app->logMsg(sprintf('User %s successfully logged-in.', $frm['username']), LOG_INFO, __FILE__, __LINE__);
55    } else {
56        $app->raiseMsg(_("Login failed, please try again."), MSG_NOTICE, __FILE__, __LINE__);
57        $app->logMsg(sprintf('User %s failed login (encrypted password: %s)', $frm['username'], $auth->encryptPassword($frm['password'])), LOG_NOTICE, __FILE__, __LINE__);
58    }
59}
60
61// Titles and navigation header.
62$nav->add(_("Login"));
63
64// Templates.
65include 'header.ihtml';
66include 'codebase/services/templates/login_form.ihtml';
67include 'footer.ihtml';
68
Note: See TracBrowser for help on using the repository browser.