Merge branch 'feature-5128/FHC-IDAM_account_activation'

This commit is contained in:
Andreas Österreicher
2020-02-03 14:53:24 +01:00
11 changed files with 558 additions and 133 deletions
+3 -1
View File
@@ -64,7 +64,9 @@ define('LDAP_TOO_MANY_USER_DN', 11);
|--------------------------------------------------------------------------
*/
define('LANG_SESSION_NAME', 'LANGUAGE');
define('LANG_SESSION_INDEXES', 'LANGUAGE_INDEXES');
define('LANG_SESSION_INDEXES', 'INDEXES');
define('LANG_SESSION_ACTIVE_LANGUAGES', 'ACTIVE_LANGUAGES');
define('LANG_SESSION_CURRENT_LANGUAGE', 'sprache'); // NOTE: it is not under LANG_SESSION_NAME
/*
|--------------------------------------------------------------------------
@@ -0,0 +1,31 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* This controller is used to set the current language for a user
* It is part of the Language Switcher Widget
*/
class Language extends FHC_Controller
{
/**
* Calls the parent's constructor
*/
public function __construct()
{
parent::__construct();
}
//------------------------------------------------------------------------------------------------------------------
// Public methods
/**
*
*/
public function setSessionLanguage()
{
$language = $this->input->post('language');
$this->outputJson(setUserLanguage($language));
}
}
+19
View File
@@ -21,6 +21,9 @@ abstract class FHC_Controller extends CI_Controller
{
parent::__construct();
// NOTE: placed here before performing anything else!!!
$this->_checkHTTPS();
$this->_controllerId = null; // set _controllerId as null by default
// Loads helper message to manage returning messages
@@ -129,4 +132,20 @@ abstract class FHC_Controller extends CI_Controller
{
$this->output->set_content_type('application/json')->set_output(json_encode($mixed));
}
//------------------------------------------------------------------------------------------------------------------
// Private methods
/**
* Checks if the call is performed via web and if HTTPS is enabled and used
* If NOT then an error is raised and the execution is terminated
*/
private function _checkHTTPS()
{
// If NOT called from command line and if the HTTPS protocol is NOT enabled
if (!$this->input->is_cli_request() && !isset($_SERVER['HTTPS']))
{
show_error('This web site cannot work correctly without the HTTPS protocol enabled');
}
}
}
+111 -26
View File
@@ -18,28 +18,48 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Function to retrieve the language of the logged user
* If is not possible to retrieve it, then the default system language is returnd
* If as parameter is given a valid language the it's returned useful to avoid
* to write the same control structures for the language
* If is not possible to retrieve it, then the default system language is returned
* NOTE: If the given parameter is a valid language then it is returned
* It is useful to avoid to write a lot of "if else" structures
*/
function getUserLanguage($language = null)
{
// If the given parameter is a valid language then return it
if (!isEmptyString($language)) return $language;
$ci =& get_instance(); // get CI instance
// Use the default system language, if it's possible retrieves the language for the logged user
// Use the default system language as fallback
$language = DEFAULT_LANGUAGE;
// Checks if the user is authenticated to retrieve the users's language
// NOTE: this helper could be called when the user is not logged in the system
// so this is why is checked if the function getAuthUID exists
if (function_exists('getAuthUID'))
// If the language is present in the session and it is valid
if (isset($_SESSION[LANG_SESSION_CURRENT_LANGUAGE]) && !isEmptyString($_SESSION[LANG_SESSION_CURRENT_LANGUAGE]))
{
$language = $_SESSION[LANG_SESSION_CURRENT_LANGUAGE]; // then use it
}
// Otherwise checks if the user is authenticated to retrieve the users's language
// NOTE: this helper could be called when the user is NOT logged in the system
// therefore is checked if the user is logged
elseif (isLogged())
{
$ci =& get_instance(); // get CI instance
// NOTE: Stores the loaded model with the alias PersonModelLanguage to avoid to overwrite
// an already loaded PersonModel used somewhere else
$ci->load->model('person/Person_model', 'PersonModelLanguage');
$language = $ci->PersonModelLanguage->getLanguage(getAuthUID());
// Retrieves language/s for the logged user
$languagesDB = $ci->PersonModelLanguage->getLanguage(getAuthUID());
if (hasData($languagesDB))
{
// Looks for the first valid language
foreach (getData($languagesDB) as $languageDB)
{
if (!isEmptyString($languageDB->sprache))
{
$language = $languageDB->sprache;
break;
}
}
}
}
return $language;
@@ -62,31 +82,21 @@ function getPhraseByLanguage($phraseLanguagesArray, $language)
$langArray = getSessionElement(LANG_SESSION_NAME, LANG_SESSION_INDEXES);
if ($langArray == null) // If not already loaded in session
{
// Loads the Sprache_model to retrieve the language settings from the DB
// NOTE: Stores the loaded model with the alias SpracheModelLanguage to avoid to overwrite
// an already loaded SpracheModel used somewhere else
$ci->load->model('system/Sprache_model', 'SpracheModelLanguage');
// Add order clause by index and select only the sprache column
$ci->SpracheModelLanguage->addOrder('index');
$ci->SpracheModelLanguage->addSelect('sprache');
// Retrieves from public.tbl_sprache
$dbLanguages = $ci->SpracheModelLanguage->load();
// Retrieves active languages
$dbLanguages = getDBActiveLanguages();
if (hasData($dbLanguages)) // If everything is ok and contains data
{
$index = 0; // Incremental integer
$languageIndexes = array(); // Array that will contains languages and their indexes
$langArray = array(); // Array that will contains languages and their indexes
// Loops through database results
foreach (getData($dbLanguages) as $dbLanguage)
{
$languageIndexes[$dbLanguage->sprache] = $index++; // set $languageIndexes array elements
$langArray[$dbLanguage->sprache] = $index++; // set $languageIndexes array elements
}
}
$langArray = $languageIndexes; // copy $languageIndexes to $langArray
// Set session element $_SESSION['LANG']['LANG_INDEXES'] with $languageIndexes
// Set session element $_SESSION['LANG']['LANG_INDEXES'] with $langArray
setSessionElement(LANG_SESSION_NAME, LANG_SESSION_INDEXES, $langArray);
}
@@ -100,3 +110,78 @@ function getPhraseByLanguage($phraseLanguagesArray, $language)
return $phrase;
}
/**
* Tries to load active languages from session, if not present then loads them from database and stores them in session
*/
function getActiveLanguages()
{
$languagesArray = getSessionElement(LANG_SESSION_NAME, LANG_SESSION_ACTIVE_LANGUAGES);
if ($languagesArray == null)
{
$languagesArray = array();
// Retrieves from public.tbl_sprache
$dbLanguages = getDBActiveLanguages();
if (hasData($dbLanguages))
{
// Loops through database results
foreach (getData($dbLanguages) as $dbLanguage)
{
$languagesArray[$dbLanguage->sprache] = $dbLanguage->bezeichnung; // set $languageIndexes array elements
}
}
// Set session element $_SESSION['LANG']['LANG_SESSION_ACTIVE_LANGUAGES'] with $languagesArray
setSessionElement(LANG_SESSION_NAME, LANG_SESSION_ACTIVE_LANGUAGES, $languagesArray);
}
return $languagesArray;
}
/**
* Loads active languages from database
*/
function getDBActiveLanguages()
{
$ci =& get_instance(); // get CI instance
// Loads the Sprache_model to retrieve the language settings from the DB
// NOTE: Stores the loaded model with the alias SpracheModelLanguage to avoid to overwrite
// an already loaded SpracheModel used somewhere else
$ci->load->model('system/Sprache_model', 'SpracheModelLanguage');
// Add order clause by index and select only the sprache column
$ci->SpracheModelLanguage->addOrder('index');
$ci->SpracheModelLanguage->addSelect('sprache, bezeichnung');
// Retrieves from public.tbl_sprache
return $ci->SpracheModelLanguage->loadWhere(array('content' => true));
}
/**
* Sets the current language to render the GUI in session
*/
function setUserLanguage($language)
{
$languageValid = false;
// Checks if the given language is valid (present between active languages)
foreach (getActiveLanguages() as $languageName => $languageTranslation)
{
if ($language == $languageName)
{
$languageValid = true;
break;
}
}
if ($languageValid) // if the provided language is valid
{
$_SESSION[LANG_SESSION_CURRENT_LANGUAGE] = $language; // stores it in session
return success('Language successfully changed'); // return success!!
}
return error('The given language is not valid'); // return an error
}
+28
View File
@@ -0,0 +1,28 @@
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
use phpseclib\Crypt\Rijndael;
/**
* Collection of different encryption/hashing algorithms
*/
class CryptLib
{
/**
* Encrypt using the Rijndael algorithm with a key length of 256 bits and the ECB mode
* It is possible to disable the padding, enabled by default
*/
public static function RIJNDAEL_256_ECB($value, $key, $paddingDisabled = false)
{
if (isEmptyString($key) || strlen($value) % 32 != 0) return null;
$cipher = new Rijndael(Rijndael::MODE_ECB);
$cipher->setBlockLength(256);
$cipher->setKey($key);
if ($paddingDisabled === true) $cipher->disablePadding();
return $cipher->encrypt($value);
}
}
+3 -19
View File
@@ -205,28 +205,12 @@ class Person_model extends DB_Model
*/
public function getLanguage($uid)
{
$language = DEFAULT_LANGUAGE;
$this->addSelect('public.tbl_person.sprache');
$this->addJoin('public.tbl_benutzer', 'person_id');
$this->addJoin('public.tbl_sprache', 'sprache');
$this->addOrder('public.tbl_person.updateamum', 'DESC');
$this->addOrder('public.tbl_person.insertvon', 'DESC');
$persons = $this->loadWhere(array('uid' => $uid));
if (hasData($persons))
{
for ($i = 0; $i < count($persons->retval); $i++)
{
$person = $persons->retval[$i];
if (!isEmptyString($person->sprache))
{
$language = $person->sprache;
break;
}
}
}
return $language;
return $this->loadWhere(array('uid' => $uid, 'content' => true));
}
}
+31 -20
View File
@@ -18,6 +18,7 @@
$addons = isset($addons) ? $addons : false;
$ajaxlib = isset($ajaxlib) ? $ajaxlib : false;
$bootstrap = isset($bootstrap) ? $bootstrap : false;
$captcha = isset($captcha) ? $captcha : false;
$dialoglib = isset($dialoglib) ? $dialoglib : false;
$filterwidget = isset($filterwidget) ? $filterwidget : false;
$fontawesome = isset($fontawesome) ? $fontawesome : false;
@@ -62,12 +63,6 @@
// Font Awesome CSS
if ($fontawesome === true) generateCSSsInclude('vendor/components/font-awesome/css/font-awesome.min.css');
// PivotUI CSS
if ($pivotui === true)
{
generateCSSsInclude('vendor/nicolaskruchten/pivottable/dist/pivot.min.css');
}
// SB Admin 2 template CSS
if ($sbadmintemplate === true)
{
@@ -75,6 +70,15 @@
generateCSSsInclude('vendor/BlackrockDigital/startbootstrap-sb-admin-2/dist/css/sb-admin-2.min.css');
}
// Securimage CSS
if ($captcha === true) generateCSSsInclude('vendor/dapphp/securimage/securimage.css');
// PivotUI CSS
if ($pivotui === true)
{
generateCSSsInclude('vendor/nicolaskruchten/pivottable/dist/pivot.min.css');
}
// Table sorter CSS
if ($tablesorter === true)
{
@@ -107,6 +111,9 @@
// Eventually required CSS
generateCSSsInclude($customCSSs); // Eventually required CSS
// CSS End
// --------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------
// Javascripts
@@ -132,19 +139,32 @@
}
// jQuery checkboxes
// NOTE: keep it after jQuery includes
if ($jquerycheckboxes === true)
{
generateJSsInclude('vendor/rmariuzzo/jquery-checkboxes/dist/jquery.checkboxes-1.0.7.min.js');
}
// Bootstrap JS
if ($bootstrap === true) generateJSsInclude('vendor/twbs/bootstrap/dist/js/bootstrap.min.js');
// jQuery treetable
// NOTE: keep it after jQuery includes
if ($jquerytreetable === true) generateJSsInclude('vendor/ludo/jquery-treetable/jquery.treetable.js');
// MomentJS
// Bootstrap JS
if ($bootstrap === true) generateJSsInclude('vendor/twbs/bootstrap/dist/js/bootstrap.min.js');
// SB Admin 2 template JS
if ($sbadmintemplate === true)
{
generateJSsInclude('vendor/BlackrockDigital/startbootstrap-sb-admin-2/vendor/metisMenu/metisMenu.min.js');
generateJSsInclude('vendor/BlackrockDigital/startbootstrap-sb-admin-2/dist/js/sb-admin-2.min.js');
generateBackwardCompatibleJSMsIe('vendor/afarkas/html5shiv/dist/html5shiv.min.js');
generateBackwardCompatibleJSMsIe('vendor/scottjehl/Respond/dest/respond.min.js');
}
// Securimage JS
if ($captcha === true) generateJSsInclude('vendor/dapphp/securimage/securimage.js');
// Moment JS
if ($momentjs === true)
{
generateJSsInclude('vendor/moment/momentjs/min/moment.min.js');
@@ -152,7 +172,7 @@
generateJSsInclude('vendor/moment/momentjs/locale/en-ie.js');
}
// PivotUI CSS
// PivotUI JS
if ($pivotui === true)
{
generateJSsInclude('vendor/nicolaskruchten/pivottable/dist/pivot.min.js');
@@ -176,15 +196,6 @@
// Tinymce JS
if ($tinymce === true) generateJSsInclude('vendor/tinymce/tinymce/tinymce.min.js');
// SB Admin 2 template JS
if ($sbadmintemplate === true)
{
generateJSsInclude('vendor/BlackrockDigital/startbootstrap-sb-admin-2/vendor/metisMenu/metisMenu.min.js');
generateJSsInclude('vendor/BlackrockDigital/startbootstrap-sb-admin-2/dist/js/sb-admin-2.min.js');
generateBackwardCompatibleJSMsIe('vendor/afarkas/html5shiv/dist/html5shiv.min.js');
generateBackwardCompatibleJSMsIe('vendor/scottjehl/Respond/dest/respond.min.js');
}
// --------------------------------------------------------------------------------------------------------
// From public folder