Rewritten to use NICKNAME_IS_ACTIVE()
[mailer.git] / inc / modules / guest / what-login.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/14/2003 *
4  * ===============                              Last change: 04/28/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-login.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : Login area (redirects to the real login module)  *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Loginbereich (leitet an das richtige Lgin-Modul  *
12  *                     weiter)                                          *
13  * -------------------------------------------------------------------- *
14  * $Revision::                                                        $ *
15  * $Date::                                                            $ *
16  * $Tag:: 0.2.1-FINAL                                                 $ *
17  * $Author::                                                          $ *
18  * Needs to be in all Files and every File needs "svn propset           *
19  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
20  * -------------------------------------------------------------------- *
21  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
43         require($INC);
44 } elseif ((!EXT_IS_ACTIVE('user')) && (!IS_ADMIN())) {
45         addFatalMessage(__FILE__, __LINE__, generateExtensionInactiveNotInstalledMessage('user'));
46         return;
47 }
48
49 // Add description as navigation point
50 ADD_DESCR('guest', __FILE__);
51
52 global $DATA;
53
54 // Initialize variables
55 $errorCode = 0;
56 $uid = false;
57 $hash = '';
58 $URL = '';
59 $add = '';
60
61 // Already logged in?
62 if ((isUserIdSet()) && (isSessionVariableSet('u_hash'))) {
63         // Maybe, then continue with it
64         $uid = getUserId();
65 } elseif ((REQUEST_ISSET_POST('id')) && (REQUEST_ISSET_POST(('password'))) && (isFormSent())) {
66         // Set userid and crypt password when login data was submitted
67         if ((EXT_IS_ACTIVE('nickname')) && (NICKNAME_IS_ACTIVE(REQUEST_POST('id')))) {
68                 // Nickname entered
69                 $uid = SQL_ESCAPE(REQUEST_POST('id'));
70         } else {
71                 // Direct userid entered
72                 $uid  = bigintval(REQUEST_POST('id'));
73         }
74 } elseif (REQUEST_ISSET_POST(('new_pass'))) {
75         // New password requested
76         $uid = 0;
77         if (REQUEST_ISSET_POST('id')) $uid = REQUEST_POST('id');
78 } else {
79         // Not logged in
80         $uid = 0; $hash = '';
81 }
82
83 // Set unset variables
84 if (!REQUEST_ISSET_POST(('new_pass'))) REQUEST_SET_POST('new_pass', '');
85 if (!REQUEST_ISSET_GET('login'))     REQUEST_SET_GET('login'    , '');
86
87 if (IS_MEMBER()) {
88         // Login immidiately...
89         $URL = 'modules.php?module=login';
90 } elseif ((isFormSent()) && (''.$uid.'' != ''.REQUEST_POST('id') . '')) {
91         // Invalid input (no nickname extension installed but nickname entered)
92         $errorCode = getCode('EXTENSION_PROBLEM');
93 } elseif (isFormSent()) {
94         // Try the login (see inc/libs/user_functions.php)
95         $URL = USER_DO_LOGIN(REQUEST_POST('id'), REQUEST_POST('password'));
96 } elseif ((REQUEST_ISSET_POST(('new_pass'))) && (isset($uid))) {
97         // Try the userid/email lookup (see inc/libs/user_functions.php)
98         $errorCode = USER_DO_NEW_PASSWORD(REQUEST_POST('email'), $uid);
99 }
100
101 // Login problems?
102 if (REQUEST_ISSET_GET('login')) {
103         // Use code from URL
104         $errorCode = REQUEST_GET('login');
105 } // END  - if
106
107 // Login problems?
108 if (!empty($errorCode)) {
109         // Ok, which one now?
110         $message = "<tr>
111   <td width=\"10\" class=\"seperator\">&nbsp;</td>
112   <td colspan=\"7\" align=\"center\">
113     <span class=\"guest_failed\">";
114
115         switch ($errorCode) {
116                 case getCode('WRONG_PASS'):
117                         $message .= getMessage('LOGIN_WRONG_PASS');
118                         break;
119
120                 case getCode('WRONG_ID'):
121                         $message .= getMessage('LOGIN_WRONG_ID');
122                         break;
123
124                 case getCode('ID_LOCKED'):
125                         $message .= getMessage('LOGIN_ID_LOCKED');
126                         break;
127
128                 case getCode('ID_UNCONFIRMED'):
129                         $message .= getMessage('LOGIN_ID_UNCONFIRMED');
130                         break;
131
132                 case getCode('NO_COOKIES'):
133                         $message .= getMessage('LOGIN_NO_COOKIES');
134                         break;
135
136                 case getCode('EXTENSION_PROBLEM'):
137                         if (IS_ADMIN()) {
138                                 $message .= sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'nickname');
139                         } else {
140                                 $message .= getMessage('LOGIN_WRONG_ID');
141                         }
142                         break;
143
144                 default:
145                         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unhandled error code %s detected.", $errorCode));
146                         $message .= getMessage('LOGIN_WRONG_ID');
147                         break;
148         }
149         $message .= "</span>
150   </td>
151   <td width=\"10\" class=\"seperator\">&nbsp;</td>
152 </tr>\n";
153         define('LOGIN_FAILURE_MSG', $message);
154 } else {
155         // No problems, no output
156         define('LOGIN_FAILURE_MSG', '');
157 }
158
159 // Display login form with resend-password form
160 if (EXT_IS_ACTIVE('nickname')) {
161         LOAD_TEMPLATE('guest_nickname_login');
162 } else {
163         LOAD_TEMPLATE('guest_login');
164 }
165
166 // Was an URL constructed?
167 if (!empty($URL)) {
168         // URL was constructed
169         if (getTotalFatalErrors()) {
170                 // Fatal errors!
171                 loadIncludeOnce('inc/fatal_errors.php');
172         } else {
173                 // Load URL
174                 redirectToUrl($URL);
175         }
176 } // END - if
177
178 //
179 ?>