6b108994f6918487ef27986af1ab8e2de9ecd362
[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  *                                                                      *
15  * -------------------------------------------------------------------- *
16  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
17  * For more information visit: http://www.mxchange.org                  *
18  *                                                                      *
19  * This program is free software; you can redistribute it and/or modify *
20  * it under the terms of the GNU General Public License as published by *
21  * the Free Software Foundation; either version 2 of the License, or    *
22  * (at your option) any later version.                                  *
23  *                                                                      *
24  * This program is distributed in the hope that it will be useful,      *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
27  * GNU General Public License for more details.                         *
28  *                                                                      *
29  * You should have received a copy of the GNU General Public License    *
30  * along with this program; if not, write to the Free Software          *
31  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
32  * MA  02110-1301  USA                                                  *
33  ************************************************************************/
34
35 // Some security stuff...
36 if (!defined('__SECURITY')) {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 } elseif ((!EXT_IS_ACTIVE("user")) && (!IS_ADMIN())) {
40         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "user");
41         return;
42 }
43
44 // Add description as navigation point
45 ADD_DESCR("guest", __FILE__);
46
47 global $DATA, $ERROR;
48
49 // Initialize variables
50 $ERROR = 0;
51 $probe_nickname = false;
52 $uid = false;
53 $hash = "";
54 $URL = "";
55 $ADD = "";
56
57 // Already logged in?
58 if ((!empty($GLOBALS['userid'])) && (isSessionVariableSet('u_hash'))) {
59         // Maybe, then continue with it
60         $uid = $GLOBALS['userid'];
61 } elseif ((!empty($_POST['id'])) && (!empty($_POST['password'])) && (isset($_POST['ok']))) {
62         // Set userid and crypt password when login data was submitted
63         if ((EXT_IS_ACTIVE("nickname")) && (NICKNAME_PROBE_ON_USERID($_POST['id']))) {
64                 // Nickname entered
65                 $uid = SQL_ESCAPE($_POST['id']);
66         } else {
67                 // Direct userid entered
68                 $uid  = bigintval($_POST['id']);
69         }
70 } elseif (!empty($_POST['new_pass'])) {
71         // New password requested
72         $uid = 0;
73         if (!empty($_POST['id'])) $uid = $_POST['id'];
74 } else {
75         // Not logged in
76         $uid = 0; $hash = "";
77 }
78
79 // Set unset variables
80 if (empty($_POST['new_pass'])) $_POST['new_pass'] = "";
81 if (empty($_GET['login']))     $_GET['login']     = "";
82
83 if (IS_MEMBER()) {
84         // Login immidiately...
85         $URL = "modules.php?module=login";
86 } elseif ((isset($_POST['ok'])) && ("".$uid."" != "".$_POST['id']."")) {
87         // Invalid input (no nickname extension installed but nickname entered)
88         $ERROR = CODE_EXTENSION_PROBLEM;
89 } elseif (isset($_POST['ok'])) {
90         // Try the login (see inc/libs/user_functions.php)
91         $URL = USER_DO_LOGIN($_POST['id'], $_POST['password']);
92 } elseif ((!empty($_POST['new_pass'])) && (isset($uid))) {
93         // Try the userid/email lookup (see inc/libs/user_functions.php)
94         $ERROR = USER_DO_NEW_PASSWORD($_POST['email'], $uid);
95 }
96
97 // Login problems?
98 if (!empty($_GET['login'])) {
99         // Use code from URL
100         $ERROR = SQL_ESCAPE($_GET['login']);
101 } // END  - if
102
103 // Login problems?
104 if (!empty($ERROR)) {
105         // Ok, which one now?
106         $MSG = "<tr>
107   <td width=\"10\" class=\"seperator\">&nbsp;</td>
108   <td colspan=\"7\" align=\"center\">
109     <span class=\"guest_failed\">";
110
111         switch ($ERROR) {
112                 case CODE_WRONG_PASS:
113                         $MSG .= LOGIN_WRONG_PASS;
114                         break;
115
116                 case CODE_WRONG_ID:
117                         $MSG .= LOGIN_WRONG_ID;
118                         break;
119
120                 case CODE_ID_LOCKED:
121                         $MSG .= LOGIN_ID_LOCKED;
122                         break;
123
124                 case CODE_ID_UNCONFIRMED:
125                         $MSG .= LOGIN_ID_UNCONFIRMED;
126                         break;
127
128                 case CODE_NO_COOKIES:
129                         $MSG .= LOGIN_NO_COOKIES;
130                         break;
131
132                 case CODE_EXTENSION_PROBLEM:
133                         if (IS_ADMIN()) {
134                                 $MSG .= sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "nickname");
135                         } else {
136                                 $MSG .= LOGIN_WRONG_ID;
137                         }
138                         break;
139
140                 default:
141                         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unhandled error code %s detected.", $ERROR));
142                         $MSG .= LOGIN_WRONG_ID;
143                         break;
144                 }
145                 $MSG .= "</span>
146   </td>
147   <td width=\"10\" class=\"seperator\">&nbsp;</td>
148 </tr>\n";
149                 define('LOGIN_FAILURE_MSG', $MSG);
150 } else {
151         // No problems, no output
152         define('LOGIN_FAILURE_MSG', "");
153 }
154
155 // Display login form with resend-password form
156 if (EXT_IS_ACTIVE("nickname")) {
157         LOAD_TEMPLATE("guest_nickname_login");
158 } else {
159         LOAD_TEMPLATE("guest_login");
160 }
161
162 // Was an URL constructed?
163 if (!empty($URL)) {
164         // URL was constructed
165         global $FATAL;
166         if (!empty($FATAL[0])) {
167                 // Fatal errors!
168                 require_once(PATH."inc/fatal_errors.php");
169         } else {
170                 // Load URL
171                 LOAD_URL($URL);
172         }
173 } // END - if
174
175 //
176 ?>