Skip to content

Commit

Permalink
Merge pull request #28 from OnePlc/1.0.24-dev
Browse files Browse the repository at this point in the history
1.0.24 dev
  • Loading branch information
Praesidiarius authored Mar 27, 2021
2 parents 771b799 + b95ceb0 commit 970a553
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 74 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "onePlace User Module",
"type": "oneplace-module",
"license": "BSD-3-Clause",
"version": "1.0.23",
"version": "1.0.24",
"keywords": [
"laminas",
"mvc",
Expand All @@ -15,7 +15,7 @@
"phpunit/phpunit": "^8",
"laminas/laminas-test": "^3.3.0",
"laminas/laminas-coding-standard": "^1.0",
"oneplace/oneplace-core": "^1.0.21",
"oneplace/oneplace-core": "^1.0.33",
"ext-json": "*"
},
"require": {
Expand Down
4 changes: 3 additions & 1 deletion data/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ INSERT INTO `core_form_field` (`Field_ID`, `type`, `label`, `fieldkey`, `tab`, `
(NULL, 'text', 'Username', 'username', 'usercopy-base', 'user-copy', 'col-md-3', '/user/view/##ID##', '', 0, 1, 0, '', '', ''),
(NULL, 'text', 'Full Name', 'full_name', 'usercopy-base', 'user-copy', 'col-md-3', '', '', 0, 1, 0, '', '', ''),
(NULL, 'email', 'E-Mail', 'email', 'usercopy-base', 'user-copy', 'col-md-3', '/user/view/##ID##', '', 0, 1, 0, '', '', ''),
(NULL, 'password', 'Password', 'password', 'usercopy-base', 'user-copy', 'col-md-3', '', '', 0, 1, 0, '', '', '');
(NULL, 'password', 'Password', 'password', 'usercopy-base', 'user-copy', 'col-md-3', '', '', 0, 1, 0, '', '', ''),
(NULL, 'text', 'Theme', 'theme', 'user-base', 'user-single', 'col-md-3', '', '', 0, 1, 0, '', '', ''),
(NULL, 'text', 'Language', 'lang', 'user-base', 'user-single', 'col-md-3', '', '', 0, 1, 0, '', '', '');

--
-- Core Form Tab
Expand Down
2 changes: 1 addition & 1 deletion src/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function exchangeArray(array $data)
$this->id = ! empty($data['User_ID']) ? $data['User_ID'] : 0;
$this->email = ! empty($data['email']) ? $data['email'] : '';
$this->username = ! empty($data['username']) ? $data['username'] : '';
$this->lang = ! empty($data['lang']) ? $data['lang'] : '';
$this->lang = ! empty($data['lang']) ? $data['lang'] : 'en_US';
$this->full_name = ! empty($data['full_name']) ? $data['full_name'] : '';
$this->password = ! empty($data['password']) ? $data['password'] : '';
$this->password_reset_token = ! empty($data['password_reset_token'])
Expand Down
100 changes: 30 additions & 70 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Module
*
* @since 1.0.0
*/
const VERSION = '1.0.23';
const VERSION = '1.0.24';

/**
* Load module config file
Expand Down Expand Up @@ -74,8 +74,19 @@ function ($e) {

$oDbAdapter = $sm->get(AdapterInterface::class);

$translator = $sm->get(TranslatorInterface::class);
$translator->setLocale('de_DE');
CoreController::$oTranslator = $sm->get(TranslatorInterface::class);
CoreController::$oTranslator->setLocale('en_US');
if(getenv('PLCWEBLANG')) {
if(getenv('PLCWEBLANG') != '') {
switch(getenv('PLCWEBLANG')) {
case 'de':
CoreController::$oTranslator->setLocale('de_DE');
break;
default:
break;
}
}
}

$sTravisBase = '/home/travis/build/OnePlc/PLC_X_User';
if (is_dir($sTravisBase)) {
Expand All @@ -101,82 +112,21 @@ function ($e) {
$container = new Container('plcauth');
$bLoggedIn = false;

if(isset($_REQUEST['lang'])) {
switch($_REQUEST['lang']) {
case 'de':
$container->sLang = 'de_DE';
//$translator->setLocale('de_DE');
break;
case 'en':
$container->sLang = 'en_US';
//$translator->setLocale('en_US');
break;
case 'fr':
$container->sLang = 'de_DE';
//$translator->setLocale('en_US');
break;
default:
break;
}
}

if(isset($container->sLang)) {
if($container->sLang != '') {
$translator->setLocale($container->sLang);
}
}

# Whitelisted routes that need no authentication
if(!isset($container->aWhiteList)) {
$aWhiteListedRoutes = [];
$oWhiteListTbl = new TableGateway('settings', $oDbAdapter);
$oWhiteList = $oWhiteListTbl->select(['settings_key' => 'firewall-whitelist']);
if(count($oWhiteList) > 0) {
$oWhiteList = $oWhiteList->current();

$aListEntries = json_decode($oWhiteList->settings_value);
if(count($aListEntries) > 0) {
foreach($aListEntries as $sEntry) {
$aWhiteListedRoutes[$sEntry] = [];
}
}
}

$container->aWhiteList = $aWhiteListedRoutes;
}


# check if user is logged in
if (isset($container->oUser)) {
$bLoggedIn = true;
# check permissions
/**
if(isset($_REQUEST['lang'])) {
switch($_REQUEST['lang']) {
case 'de':
$container->sLang = 'de_DE';
break;
case 'en':
$container->sLang = 'de_DE';
break;
case 'fr':
$container->sLang = 'de_DE';
break;
default:
break;
}
} elseif(!isset($container->sLang)) {
$container->sLang = $container->oUser->getLang();
}
$translator->setLocale($container->sLang);
* **/
CoreController::$oTranslator->setLocale($container->oUser->getLang());


//echo 'check for '.$aRouteInfo['action'].'-'.$aRouteInfo['controller'];

$container->oUser->setAdapter($oDbAdapter);

$bIsSetupController = stripos($aRouteInfo['controller'], 'InstallController');
if ($bIsSetupController === false) {
if (! $container->oUser->hasPermission($aRouteInfo['action'], $aRouteInfo['controller'])
&& $sRouteName != 'denied' && !array_key_exists($sRouteName,$container->aWhiteList)) {
&& $sRouteName != 'denied') {
$response = $e->getResponse();
$response->getHeaders()->addHeaderLine(
'Location',
Expand Down Expand Up @@ -213,10 +163,20 @@ function ($e) {
}
}

# Whitelisted routes that need no authentication
$aWhiteListedRoutes = [
'tokenlogin' => [],
'setup' => [],
'login' => [],
'reset-pw' => [],
'forgot-pw' => [],
'register' => [],
];

/**
* Redirect to Login Page if not logged in
*/
if (! $bLoggedIn && ! array_key_exists($sRouteName, $container->aWhiteList)) {
if (! $bLoggedIn && ! array_key_exists($sRouteName, $aWhiteListedRoutes)) {
/**
* Setup before First Login
*/
Expand Down

0 comments on commit 970a553

Please sign in to comment.