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