87d743e3f196b2526b81d0507f3389d62056e090
[mailer.git] / inc / modules / chk_login.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 11/26/2003 *
4  * ===================                          Last change: 02/27/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : chk_login.php                                    *
8  * -------------------------------------------------------------------- *
9  * Short description : Check if user has logged in (delay)              *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Pruefen ob die Login-Cookies gesetzt sind        *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } // END - if
43
44 // Initial message part
45 $message = "<strong>{--VALIDATING_LOGIN--}</strong>";
46
47 // Is the member id and u_hash set?
48 if (isMemberIdSet() && (isSessionVariableSet('u_hash'))) {
49         // Is 'theme' installed and activated?
50         if (isExtensionActive('theme')) {
51                 // Get theme from profile
52                 if (!fetchUserData(getMemberId())) {
53                         // Userid is not valid
54                         debug_report_bug('User id '.getMemberId() . ' is invalid.');
55                 } // END - if
56
57                 // Load data
58                 $data = getUserDataArray();
59
60                 // Change to new theme
61                 setTheme($data['curr_theme']);
62
63                 // Remmeber login failures if available
64                 if (getExtensionVersion('sql_patches') >= '0.6.1') {
65                         // Reset login failures
66                         SQL_QUERY_ESC("UPDATE
67         `{?_MYSQL_PREFIX?}_user_data`
68 SET
69         `login_failures`=0,
70         `last_failure`='0000-00-00 00:00:00'
71 WHERE
72         `userid`=%s
73 LIMIT 1",
74                                 array(getMemberId()), __FILE__, __LINE__);
75
76                         // Store it in session
77                         setSession('mxchange_member_failures', $data['login_failures']);
78                         setSession('mxchange_member_last_fail', $data['last_failure']);
79                 } // END - if
80         } // END - if
81
82         // Bonus is not given by default ;-)
83         $bonus = false;
84         if ((getExtensionVersion('sql_patches') >= '0.2.8') && (getExtensionVersion('bonus') >= '0.2.1') && (getConfig('bonus_login_yn') == 'Y')) {
85                 // Update last login if far enougth away
86                 SQL_QUERY_ESC("UPDATE
87         `{?_MYSQL_PREFIX?}_user_data`
88 SET
89         `last_login`=UNIX_TIMESTAMP()
90 WHERE
91         `userid`=%s AND
92         `last_login` < (UNIX_TIMESTAMP() - %s)
93 LIMIT 1",
94                         array(
95                                 getMemberId(),
96                                 getConfig('login_timeout')
97                         ), __FILE__, __LINE__
98                 );
99                 if (SQL_AFFECTEDROWS() == 1) $bonus = true;
100         } // END - if
101
102         if (($bonus === true) && (getRequestElement('mode') == 'bonus') && (isExtensionActive('bonus'))) {
103                 // Output message with added points
104                 $message .= "<div class=\"tiny\">
105   ".sprintf(getMessage('BONUS_LOGIN_BONUS_ADDED'), translateComma(getConfig('login_bonus')))."
106 </div>";
107         } elseif (isExtensionActive('bonus')) {
108                 // No login bonus added!
109                 $message .= "<div class=\"member_failed\">{--BONUS_LOGIN_BONUS_NOT_ADDED--}</div>";
110         }
111
112         // Redirect to member area
113         $message .= loadTemplate('member_login_js', true);
114 } else {
115         // Login failed!
116         $message .= loadTemplate('login_failed_js', true);
117 }
118
119 // Output final message
120 loadTemplate('admin_settings_saved', false, $message);
121
122 // [EOF]
123 ?>