b8bc4b148bec3b39d90ddf3945674250ef30ff7a
[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 - 2009 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         die();
43 }
44
45 // Add description as navigation point
46 addMenuDescription('guest', __FILE__);
47
48 if ((!isExtensionActive('user')) && (!isAdmin())) {
49         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('user'));
50         return;
51 } // END - if
52
53 // Initialize variables
54 $errorCode = 0;
55 $userid = false;
56 $hash = '';
57 $URL = '';
58 $add = '';
59
60 // Already logged in?
61 if ((isUserIdSet()) && (isSessionVariableSet('u_hash'))) {
62         // Maybe, then continue with it
63         $userid = getUserId();
64 } elseif ((isPostRequestElementSet('id')) && (isPostRequestElementSet('password')) && (isFormSent())) {
65         // Set userid and crypt password when login data was submitted
66         if ((isExtensionActive('nickname')) && (isNicknameOrUserid(postRequestElement('id')))) {
67                 // Nickname entered
68                 $userid = SQL_ESCAPE(postRequestElement('id'));
69         } else {
70                 // Direct userid entered
71                 $userid  = bigintval(postRequestElement('id'));
72         }
73 } elseif (isPostRequestElementSet('new_pass')) {
74         // New password requested
75         $userid = 0;
76         if (isPostRequestElementSet('id')) $userid = bigintval(postRequestElement('id'));
77 } else {
78         // Not logged in
79         $userid = 0; $hash = '';
80 }
81
82 if (isMember()) {
83         // Login immidiately...
84         $URL = 'modules.php?module=login';
85 } elseif ((isFormSent()) && ('' . $userid . '' != '' . postRequestElement('id') . '')) {
86         // Invalid input (no nickname extension installed but nickname entered)
87         $errorCode = getCode('EXTENSION_PROBLEM');
88 } elseif (isFormSent()) {
89         // Try the login (see inc/libs/user_functions.php)
90         $URL = doUserLogin(postRequestElement('id'), postRequestElement('password'));
91 } elseif ((isPostRequestElementSet('new_pass')) && (isset($userid))) {
92         // Try the userid/email lookup (see inc/libs/user_functions.php)
93         $errorCode = doNewUserPassword(postRequestElement('email'), $userid);
94 }
95
96 // Login problems?
97 if (isGetRequestElementSet('login')) {
98         // Use code from URL
99         $errorCode = getRequestElement('login');
100 } // END  - if
101
102 // No problems, no output by detault
103 $content['message'] = '';
104
105 // Login problems?
106 if (!empty($errorCode)) {
107         // @TODO Move this HTML code into a template
108         $message = "<tr>
109   <td width=\"10\" class=\"seperator\">&nbsp;</td>
110   <td colspan=\"7\" align=\"center\">
111     <span class=\"guest_failed\">";
112
113         // Convert the code to message
114         $message .= getMessageFromErrorCode($errorCode);
115
116         // Continue with HTML
117         $message .= "</span>
118   </td>
119   <td width=\"10\" class=\"seperator\">&nbsp;</td>
120 </tr>\n";
121         $content['message'] = $message;
122 } // END - if
123
124 // Display login form with resend-password form
125 if (isExtensionActive('nickname')) {
126         loadTemplate('guest_nickname_login', false, $content);
127 } else {
128         loadTemplate('guest_login', false, $content);
129 }
130
131 // Was an URL constructed?
132 if (!empty($URL)) {
133         // URL was constructed
134         if (getTotalFatalErrors() > 0) {
135                 // Handle fatal errors
136                 runFilterChain('handle_fatal_errors');
137         } else {
138                 // Load URL
139                 redirectToUrl($URL);
140         }
141 } // END - if
142
143 // [EOF]
144 ?>