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 | // Redefine include_path including the codebase/services but allow local templates override global ones. |
---|
28 | ini_set('include_path', join(PATH_SEPARATOR, array( |
---|
29 | get_include_path(), |
---|
30 | dirname(__FILE__) . '/templates' |
---|
31 | ))); |
---|
32 | |
---|
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. |
---|
35 | if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) { |
---|
36 | $app->setBoomerangURL($_SERVER['HTTP_REFERER'], 'login'); |
---|
37 | } |
---|
38 | $app->sslOn(); |
---|
39 | |
---|
40 | // Cookie-based storage preferences. |
---|
41 | require_once 'codebase/lib/Prefs.inc.php'; |
---|
42 | $login_prefs = new Prefs('login'); |
---|
43 | $login_prefs->setParam(array('storagetype' => 'cookie')); |
---|
44 | |
---|
45 | $frm['username'] = getFormdata('username', $login_prefs->get('username')); |
---|
46 | $frm['password'] = getFormdata('password'); |
---|
47 | $frm['remember_me'] = ('' != $login_prefs->get('username')) ? '1' : ''; |
---|
48 | |
---|
49 | if (getFormdata('username', false)) { |
---|
50 | // Form has been submitted, check if the user login information is correct. |
---|
51 | |
---|
52 | if ($auth->login($frm['username'], $frm['password'])) { |
---|
53 | if (getFormData('remember_me')) { |
---|
54 | $login_prefs->set('username', getFormData('username')); |
---|
55 | } else { |
---|
56 | $login_prefs->set('username', ''); |
---|
57 | } |
---|
58 | $app->raiseMsg(_("You are now logged in."), MSG_SUCCESS, __FILE__, __LINE__); |
---|
59 | $app->logMsg(sprintf('User %s successfully logged in.', $frm['username']), LOG_INFO, __FILE__, __LINE__); |
---|
60 | $app->dieBoomerangURL('login'); |
---|
61 | } else { |
---|
62 | $app->raiseMsg(_("Login failed, please try again."), MSG_NOTICE, __FILE__, __LINE__); |
---|
63 | $app->logMsg(sprintf('User %s failed login (encrypted password: %s)', $frm['username'], $auth->encryptPassword($frm['password'])), LOG_NOTICE, __FILE__, __LINE__); |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | // Titles and navigation header. |
---|
68 | $nav->add(_("Login")); |
---|
69 | $nav->set('id', 'login'); |
---|
70 | |
---|
71 | // Templates. |
---|
72 | include 'header.ihtml'; |
---|
73 | include 'login_form.ihtml'; |
---|
74 | include 'footer.ihtml'; |
---|
75 | |
---|