Fixed wrong handling of nickname in member login
[mailer.git] / inc / modules / guest / what-login.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 - 2009 by Roland Haeder                           *
22  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
23  * For more information visit: http://www.mxchange.org                  *
24  *                                                                      *
25  * This program is free software; you can redistribute it and/or modify *
26  * it under the terms of the GNU General Public License as published by *
27  * the Free Software Foundation; either version 2 of the License, or    *
28  * (at your option) any later version.                                  *
29  *                                                                      *
30  * This program is distributed in the hope that it will be useful,      *
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
33  * GNU General Public License for more details.                         *
34  *                                                                      *
35  * You should have received a copy of the GNU General Public License    *
36  * along with this program; if not, write to the Free Software          *
37  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
38  * MA  02110-1301  USA                                                  *
39  ************************************************************************/
40
41 // Some security stuff...
42 if (!defined('__SECURITY')) {
43         die();
44 }
45
46 // Add description as navigation point
47 addMenuDescription('guest', __FILE__);
48
49 if ((!isExtensionActive('user')) && (!isAdmin())) {
50         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('user'));
51         return;
52 } // END - if
53
54 // Initialize variables
55 $errorCode = '0';
56 $userid = false;
57 $hash = '';
58 $url = '';
59 $add = '';
60
61 // Already logged in?
62 if ((isMemberIdSet()) && (isSessionVariableSet('u_hash'))) {
63         // Maybe, then continue with it
64         $userid = getMemberId();
65 } elseif ((isPostRequestParameterSet('id')) && (isPostRequestParameterSet('password')) && (isFormSent())) {
66         // Set userid and crypt password when login data was submitted
67         if (isExtensionActive('nickname')) {
68                 // Nickname entered
69                 $userid = SQL_ESCAPE(postRequestParameter('id'));
70         } else {
71                 // Direct userid entered
72                 $userid  = bigintval(postRequestParameter('id'));
73         }
74 } elseif (isPostRequestParameterSet('new_pass')) {
75         // New password requested
76         $userid = '0';
77         if (isPostRequestParameterSet('id')) {
78                 // Do we have nickname or userid?
79                 if ((isExtensionActive('nickname')) && (isNicknameUsed(postRequestParameter('id')))) {
80                         // Nickname entered
81                         $userid = SQL_ESCAPE(postRequestParameter('id'));
82                 } else {
83                         // Direct userid entered
84                         $userid  = bigintval(postRequestParameter('id'));
85                 }
86         } // END - if
87 } else {
88         // Not logged in
89         $userid = '0'; $hash = '';
90 }
91
92 if (isMember()) {
93         // Login immidiately...
94         $url = 'modules.php?module=login';
95 } elseif ((isFormSent()) && ('' . $userid . '' != '' . postRequestParameter('id') . '')) {
96         // Invalid input (no nickname extension installed but nickname entered)
97         $errorCode = getCode('EXTENSION_PROBLEM');
98 } elseif (isFormSent()) {
99         // Try the login (see inc/libs/user_functions.php)
100         $url = doUserLogin(postRequestParameter('id'), postRequestParameter('password'));
101 } elseif ((isPostRequestParameterSet('new_pass')) && (isset($userid))) {
102         // Try the userid/email lookup (see inc/libs/user_functions.php)
103         $errorCode = doNewUserPassword(postRequestParameter('email'), $userid);
104 }
105
106 // Login problems?
107 if (isGetRequestParameterSet('login')) {
108         // Use code from URL
109         $errorCode = getRequestParameter('login');
110 } // END  - if
111
112 // No problems, no output by detault
113 $content['message'] = '';
114
115 // Login problems?
116 if (!empty($errorCode)) {
117         // Do we have a userid set?
118         if (isSessionVariableSet('current_userid')) {
119                 // Then prefetch data for this account
120                 fetchUserData(getSession('current_userid'));
121         } // END - if
122
123         // @TODO Move this HTML code into a template
124         $content['message'] = '<tr>
125   <td colspan="4" align="center">
126     <span class="guest_failed">' . getMessageFromErrorCode($errorCode) . '</span>
127   </td>
128 </tr>';
129 } // END - if
130
131 // Display login form with resend-password form
132 if (isExtensionActive('nickname')) {
133         loadTemplate('guest_nickname_login', false, $content);
134 } else {
135         loadTemplate('guest_login', false, $content);
136 }
137
138 // Was an URL constructed?
139 if (!empty($url)) {
140         // URL was constructed
141         if (ifFatalErrorsDetected()) {
142                 // Handle fatal errors
143                 runFilterChain('handle_fatal_errors');
144         } else {
145                 // Load URL
146                 redirectToUrl($url);
147         }
148 } // END - if
149
150 // [EOF]
151 ?>