]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Employees/WapAuthenticate.php
Release 6.2.0
[Github/sugarcrm.git] / modules / Employees / WapAuthenticate.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46
47
48 global $mod_strings;
49
50
51
52 $focus = new User();
53
54 // Add in defensive code here.
55 $focus->user_name = $_REQUEST['user_name'];
56 $user_password = $_REQUEST['user_password'];
57
58 $focus->load_user($user_password);
59
60 if($focus->is_authenticated())
61 {
62         // save the user information into the session
63         // go to the home screen
64         if (!empty($_POST['login_record'])) {
65                 $login_direction = "module={$_POST['login_module']}&action={$_POST['login_action']}&record={$_POST['login_record']}";
66         }
67         else {
68                 $login_direction = "action=index&module=Home";
69         }
70
71         header("Location: index.php?{$login_direction}");
72         unset($_SESSION['login_password']);
73         unset($_SESSION['login_error']);
74         unset($_SESSION['login_user_name']);
75
76         $_SESSION['authenticated_user_id'] = $focus->id;
77
78         // store the user's theme in the session
79         if (isset($_REQUEST['login_theme'])) {
80                 $authenticated_user_theme = $_REQUEST['login_theme'];
81         }
82         elseif (isset($_REQUEST['ck_login_theme_20']))  {
83                 $authenticated_user_theme = $_REQUEST['ck_login_theme_20'];
84         }
85         else {
86                 $authenticated_user_theme = $sugar_config['default_theme'];
87         }
88
89         // store the user's language in the session
90         if (isset($_REQUEST['login_language'])) {
91                 $authenticated_user_language = $_REQUEST['login_language'];
92         }
93         elseif (isset($_REQUEST['ck_login_language_20']))  {
94                 $authenticated_user_language = $_REQUEST['ck_login_language_20'];
95         }
96         else {
97                 $authenticated_user_language = $sugar_config['default_language'];
98         }
99
100         // If this is the default user and the default user theme is set to reset, reset it to the default theme value on each login
101         if($reset_theme_on_default_user && $focus->user_name == $sugar_config['default_user_name'])
102         {
103                 $authenticated_user_theme = $sugar_config['default_theme'];
104         }
105         if(isset($reset_language_on_default_user) && $reset_language_on_default_user && $focus->user_name == $sugar_config['default_user_name'])
106         {
107                 $authenticated_user_language = $sugar_config['default_language'];
108         }
109
110         $_SESSION['authenticated_user_theme'] = $authenticated_user_theme;
111         $_SESSION['authenticated_user_language'] = $authenticated_user_language;
112
113         $GLOBALS['log']->debug("authenticated_user_theme is $authenticated_user_theme");
114         $GLOBALS['log']->debug("authenticated_user_language is $authenticated_user_language");
115
116 // Clear all uploaded import files for this user if it exists
117
118         $tmp_file_name = $sugar_config['import_dir']. "IMPORT_".$focus->id;
119
120         if (file_exists($tmp_file_name))
121         {
122                 unlink($tmp_file_name);
123         }
124
125 }
126 else
127 {
128         $_SESSION['login_user_name'] = $focus->user_name;
129         $_SESSION['login_password'] = $user_password;
130         $_SESSION['login_error'] = $mod_strings['ERR_INVALID_PASSWORD'];
131
132         // go back to the login screen.
133         // create an error message for the user.
134         header("Location: index.php");
135 }
136
137 ?>