2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 06/10/2005 *
4 * =================== Last change: 05/18/2008 *
6 * -------------------------------------------------------------------- *
7 * File : what-sponsor_login.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Login form and password resending for sponsor *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Loginformular und Neues Passwort fuer Sponsor *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Add description as navigation point
44 addYouAreHereLink('guest', __FILE__);
46 if ((!isExtensionActive('sponsor'))) {
47 displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=sponsor%}');
49 } elseif (isSponsor()) {
50 // Is already a logged-in sponsor
51 redirectToUrl('modules.php?module=sponsor');
55 if (isGetRequestParameterSet('mode')) {
56 // A "special" mode of the login system was requested
57 switch (getRequestParameter('mode')) {
58 case 'activate' : $mode = 'activate'; break; // Activation link requested
59 case 'lost_pass': $mode = 'lost_pass'; break; // Request new password
63 // Check if hash for confirmation of email address is given...
64 if (isGetRequestParameterSet('hash')) {
66 $result = SQL_QUERY_ESC("SELECT
67 `id`, `status`, `gender`, `surname`, `family`,
68 `company`, `position`, `tax_ident`,
69 `street_nr1`, `street_nr2`, `country`, `zip`, `city`, `email`, `phone`, `fax`, `cell`,
70 `points_amount` AS `points`, `last_payment`, `last_currency`
72 `{?_MYSQL_PREFIX?}_sponsor_data`
75 `status`='UNCONFIRMED' OR
78 LIMIT 1", array(getRequestParameter('hash')), __FILE__, __LINE__);
79 if (SQL_NUMROWS($result) == 1) {
80 // Sponsor found, load his data...
81 $data = SQL_FETCHARRAY($result);
83 // Unconfirmed account or changed email address?
84 if ($data['status'] == 'UNCONFIRMED') {
85 // Set account to pending
87 `{?_MYSQL_PREFIX?}_sponsor_data`
94 `status`='UNCONFIRMED'
97 bigintval($data['id']),
98 getRequestParameter('hash')
99 ), __FILE__, __LINE__);
102 if (!SQL_HASZEROAFFECTED()) {
103 // Prepare mail and send it to the sponsor
104 $message = loadEmailTemplate('sponsor_pending', $data);
105 sendEmail($data['email'], '{--SPONSOR_ACCOUNT_PENDING_SUBJECT--}', $message);
107 // Send email to admin
108 sendAdminNotification('{--ADMIN_NEW_SPONSOR--}', 'admin_sponsor_pending', $data);
110 // Sponsor account set to pending
111 displayMessage('{--SPONSOR_ACCOUNT_IS_PENDING--}');
113 // Could not unlock account!
114 displayMessage('{--SPONSOR_ACCOUNT_PENDING_FAILED--}');
116 } elseif ($data['status'] == 'EMAIL') {
117 // Changed email adress need to be confirmed
118 SQL_QUERY_ESC("UPDATE
119 `{?_MYSQL_PREFIX?}_sponsor_data`
121 `status`='CONFIRMED',
128 array(bigintval($data['id']), getRequestParameter('hash')), __FILE__, __LINE__);
131 if (!SQL_HASZEROAFFECTED()) {
132 // Sponsor account is unlocked again
133 displayMessage('{--SPONSOR_ACCOUNT_IS_CONFIRMED_AGAIN--}');
135 // Could not unlock account!
136 displayMessage('{--SPONSOR_ACCOUNT_EMAIL_FAILED--}');
140 displayMessage('{--SPONSOR_ACCOUNT_STATUS_FAILED--}');
144 displayMessage('{%message,SPONSOR_ACCOUNT_404=' . getRequestParameter('hash') . '%}');
148 SQL_FREERESULT($result);
149 } elseif ($mode == 'activate') {
150 // Send activation link again
152 // Check submitted data
153 if (!isPostRequestParameterSet('email')) unsetPostRequestParameter('ok');
158 $result = SQL_QUERY_ESC("SELECT
159 `id`, `hash`, `status`, `remote_addr`, `gender`, `surname`, `family`,
160 UNIX_TIMESTAMP(`sponsor_created`) AS `sponsor_created`
162 `{?_MYSQL_PREFIX?}_sponsor_data`
165 (`status`='UNCONFIRMED' OR `status`='EMAIL')
167 array(postRequestParameter('email')), __FILE__, __LINE__);
170 if (SQL_NUMROWS($result) == 1) {
171 // Unconfirmed sponsor account found so let's load the requested data
172 $data = SQL_FETCHARRAY($result);
174 // Translate some data
175 $data['sponsor_created'] = generateDateTime($data['sponsor_created']);
177 // Prepare email and send it to the sponsor
178 if ($data['status'] == 'UNCONFIRMED') {
179 // Unconfirmed accounts
180 $message_sponsor = loadEmailTemplate('sponsor_activate', $data);
182 // Confirmed email address
183 $message_sponsor = loadEmailTemplate('sponsor_email', $data);
185 sendEmail(postRequestParameter('email'), '{--SPONSOR_ACTIVATION_LINK_SUBJECT--}', $message_sponsor);
188 displayMessage('{--SPONSOR_ACTIVATION_LINK_SENT--}');
190 // No account found or not UNCONFIRMED
191 displayMessage('{--SPONSOR_ACTIVATION_LINK_404--}');
195 SQL_FREERESULT($result);
198 loadTemplate('guest_sponsor_activate');
200 } elseif ($mode == 'lost_pass') {
203 // Check submitted data
204 if (!isPostRequestParameterSet('email')) unsetPostRequestParameter('ok');
209 $result = SQL_QUERY_ESC("SELECT
210 `id`, `hash`, `remote_addr`, `gender`, `surname`, `family`,
211 UNIX_TIMESTAMP(`sponsor_created`) AS `sponsor_created`
213 `{?_MYSQL_PREFIX?}_sponsor_data`
219 array(postRequestParameter('email'), bigintval(postRequestParameter('id'))), __FILE__, __LINE__);
222 if (SQL_NUMROWS($result) == 1) {
223 // Unconfirmed sponsor account found so let's load the requested data
224 $DATA = SQL_FETCHARRAY($result);
226 // Generate password/translate some data
227 $DATA['password'] = generatePassword();
228 $DATA['sponsor_created'] = generateDateTime($DATA['sponsor_created']);
230 // Prepare email and send it to the sponsor
231 $message_sponsor = loadEmailTemplate('sponsor_lost', $DATA);
232 sendEmail(postRequestParameter('email'), '{--SPONSOR_LOST_PASSWORD_SUBJECT--}', $message_sponsor);
235 SQL_QUERY_ESC("UPDATE
236 `{?_MYSQL_PREFIX?}_sponsor_data`
242 array(md5($DATA['password']), bigintval($DATA['id'])), __FILE__, __LINE__);
245 displayMessage('{--SPONSOR_LOST_PASSWORD_SENT--}');
247 // No account found or not UNCONFIRMED
248 displayMessage('{--SPONSOR_LOST_PASSWORD_404--}');
252 SQL_FREERESULT($result);
255 loadTemplate('guest_sponsor_lost');
257 } elseif (isFormSent()) {
258 // Check status and login data ...
259 $result = SQL_QUERY_ESC("SELECT
262 `{?_MYSQL_PREFIX?}_sponsor_data`
268 bigintval(postRequestParameter('sponsor_id')),
269 md5(postRequestParameter('password'))
270 ), __FILE__, __LINE__);
272 if (SQL_NUMROWS($result) == 1) {
273 // Okay, first login data check passed, now has he/she an approved (CONFIRMED) account?
274 list($status) = SQL_FETCHROW($result);
275 if ($status == 'CONFIRMED') {
276 // Is confirmed so both is fine and we can continue with login procedure
277 $login = ((setSession('sponsor_id' , bigintval(postRequestParameter('sponsor_id')))) &&
278 (setSession('sponsor_pass', md5(postRequestParameter('password')) ))
281 if ($login === true) {
282 // Cookie setup successfull so we can forward to sponsor area
283 redirectToUrl('modules.php?module=sponsor');
285 // Cookie setup failed!
286 displayMessage('{--SPONSOR_COOKIE_SETUP_FAILED--}');
288 // Login formular and other links
289 loadTemplate('guest_sponsor_login');
292 // Status is not fine
293 displayMessage('{--SPONSOR_LOGIN_FAILED_' . strtoupper($status) . '--}');
295 // Login formular and other links
296 loadTemplate('guest_sponsor_login');
299 // Account missing or wrong pass! We shall not find this out for the "cracker folks"...
300 displayMessage('{--SPONSOR_LOGIN_FAILED_404_WRONG_PASS--}');
302 // Login formular and other links
303 loadTemplate('guest_sponsor_login');
307 SQL_FREERESULT($result);
309 // Login formular and other links
310 loadTemplate('guest_sponsor_login');