Skip to content

Commit

Permalink
Keeping login language and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoSTIC committed Jan 28, 2025
1 parent 5610c73 commit 4aabd59
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 48 deletions.
71 changes: 24 additions & 47 deletions custom/include/GoogleSignIn/PostGoogleSignInAuthenticate.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php
global $current_user, $sugar_config;

LogicHook::initialize()->call_custom_logic('Users', 'before_login');
$userObj = BeanFactory::newBean('Users');

$userObj = new User();
$userObj->retrieve_by_email_address($_POST['user_email']);

$result = array('code' => 0);

$GLOBALS['log']->fatal(__METHOD__." USER ID: ".print_r($userObj->id, true));

if(empty($userObj->id)) {
$result['message'] = "Sorry, This '".$_POST['user_email']."' user is not exist in CRM. Kindly contact the administrator.";
echo json_encode($result);
Expand All @@ -16,64 +17,40 @@
if (!defined('SUITE_PHPUNIT_RUNNER')) {
session_regenerate_id(false);
}
global $mod_strings, $sugar_config;
$login_vars = $GLOBALS['app']->getLoginVars(false);

$userAuthenticateClass = 'SugarAuthenticateUser';
$authenticateClass = 'SugarAuthenticate';
$authenticationDir = 'SugarAuthenticate';

if (file_exists('custom/modules/Users/authentication/'.$authenticationDir.'/' . $userAuthenticateClass . '.php')) {
require_once('custom/modules/Users/authentication/'.$authenticationDir.'/' . $userAuthenticateClass . '.php');
if (file_exists('custom/modules/Users/authentication/'.$authenticationDir.'/' . $authenticateClass . '.php')) {
require_once('custom/modules/Users/authentication/'.$authenticationDir.'/' . $authenticateClass . '.php');
}
elseif (file_exists('modules/Users/authentication/'.$authenticationDir.'/' . $userAuthenticateClass . '.php')) {
require_once('modules/Users/authentication/'.$authenticationDir.'/' . $userAuthenticateClass . '.php');
elseif (file_exists('modules/Users/authentication/'.$authenticationDir.'/' . $authenticateClass . '.php')) {
require_once('modules/Users/authentication/'.$authenticationDir.'/' . $authenticateClass . '.php');
}

$user_id = '1';

$userAuthenticate = new SugarAuthenticateUser();

$userAuthenticate->loadUserOnSession($userObj->id);

if (isset ($sugar_config['unique_key']))$_SESSION['unique_key'] = $sugar_config['unique_key'];

//set user language
if (isset ($reset_language_on_default_user) && $reset_language_on_default_user && $GLOBALS['current_user']->user_name == $sugar_config['default_user_name']) {
$authenticated_user_language = $sugar_config['default_language'];
} else {
$authenticated_user_language = isset($_REQUEST['login_language']) ? $_REQUEST['login_language'] : (isset ($_REQUEST['ck_login_language_20']) ? $_REQUEST['ck_login_language_20'] : $sugar_config['default_language']);
}

$_SESSION['authenticated_user_language'] = $authenticated_user_language;

$GLOBALS['log']->debug("authenticated_user_language is $authenticated_user_language");
$sugarAuthenticate = new SugarAuthenticate();

// Clear all uploaded import files for this user if it exists
require_once('modules/Import/ImportCacheFiles.php');
$tmp_file_name = ImportCacheFiles::getImportDir()."/IMPORT_" . $GLOBALS['current_user']->id;
$sugarAuthenticate->userAuthenticate->loadUserOnSession($userObj->id);

if (file_exists($tmp_file_name)) {
unlink($tmp_file_name);
}
$sugarAuthenticate->postLoginAuthenticate();

if(isset($GLOBALS['current_user']))
$GLOBALS['current_user']->call_custom_logic('after_login');

global $record;
global $current_user;
global $sugar_config;

if(!empty($GLOBALS['sugar_config']['default_module']) && !empty($GLOBALS['sugar_config']['default_action'])) {
$url = "index.php?module={$GLOBALS['sugar_config']['default_module']}&action={$GLOBALS['sugar_config']['default_action']}";
} else {
$modListHeader = query_module_access_list($current_user);
//try to get the user's tabs
$tempList = $modListHeader;
$idx = array_shift($tempList);
if(!empty($modListHeader[$idx])){
$url = "index.php?module={$modListHeader[$idx]}&action=index";
}
}

if (!empty($GLOBALS['sugar_config']['default_module']) && !empty($GLOBALS['sugar_config']['default_action'])) {
$url = "index.php?module={$GLOBALS['sugar_config']['default_module']}&action={$GLOBALS['sugar_config']['default_action']}";
} else {
$modListHeader = query_module_access_list($current_user);
//try to get the user's tabs
$tempList = $modListHeader;
$idx = array_shift($tempList);
if (!empty($modListHeader[$idx])) {
$url = "index.php?module={$modListHeader[$idx]}&action=index";
}
}
$result['code'] = 1;
$result['message'] = $url;
echo json_encode($result);
5 changes: 4 additions & 1 deletion custom/modules/Users/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ function handleCredentialResponse(response) {
$.ajax({
type: "POST",
url: "index.php?entryPoint=PostGoogleSignIn",
data: { "user_email": data.email },
data: {
"user_email": data.email,
"login_language": '$display_language',
},
})
.done(function (response) {
var result = JSON.parse(response);
Expand Down

0 comments on commit 4aabd59

Please sign in to comment.