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