Compare commits

...

1 Commits

Author SHA1 Message Date
Clemens Schwaighofer
7e34c5321d Fix libs Login, Basic and DB
- Login ads auto return error for AJAX based calls (so the script
doesn't loop hang)
- Basic gets remove line break call
- DB gets minor updates with arrays set and fixes in old internal method calls
2018-11-28 15:28:27 +09:00
4 changed files with 80 additions and 56 deletions

View File

@@ -845,63 +845,77 @@ class Login extends \CoreLibs\DB\IO
private function loginPrintLogin() private function loginPrintLogin()
{ {
if (!$this->permission_okay) { if (!$this->permission_okay) {
// set the templates now // get global AJAX page trigger
$this->loginSetTemplates(); // if true, return error ajax
// if there is a global logout target ... global $AJAX_PAGE;
if (file_exists($this->logout_target) && $this->logout_target) { if ($AJAX_PAGE === true) {
$LOGOUT_TARGET = $this->logout_target; $data = array (
'status' => 'error',
'error_code' => $this->loging_error,
'msg' => array (
'level' => 'error',
'str' => $this->l->__('Login necessary')
)
);
$html_string = json_encode($data);
} else { } else {
$LOGOUT_TARGET = ""; // set the templates now
} $this->loginSetTemplates();
// if there is a global logout target ...
$html_string = $this->login_template['template']; if (file_exists($this->logout_target) && $this->logout_target) {
$LOGOUT_TARGET = $this->logout_target;
// if password change is okay } else {
if ($this->password_change) { $LOGOUT_TARGET = "";
$html_string_password_change = $this->login_template['password_change'];
// pre change the data in the PASSWORD_CHANGE_DIV first
foreach ($this->login_template['strings'] as $string => $data) {
if ($data) {
$html_string_password_change = str_replace('{'.$string.'}', $data, $html_string_password_change);
}
} }
$html_string = $this->login_template['template'];
// if password change is okay
if ($this->password_change) {
$html_string_password_change = $this->login_template['password_change'];
// pre change the data in the PASSWORD_CHANGE_DIV first
foreach ($this->login_template['strings'] as $string => $data) {
if ($data) {
$html_string_password_change = str_replace('{'.$string.'}', $data, $html_string_password_change);
}
}
// print error messagae
if ($this->login_error) {
$html_string_password_change = str_replace('{ERROR_MSG}', $this->login_error_msg[$this->login_error].'<br>', $html_string_password_change);
} else {
$html_string_password_change = str_replace('{ERROR_MSG}', '<br>', $html_string_password_change);
}
// if pw change action, show the float again
if ($this->change_password && !$this->password_change_ok) {
$html_string_password_change = str_replace('{PASSWORD_CHANGE_SHOW}', '<script language="JavaScript">ShowHideDiv(\'pw_change_div\');</script>', $html_string_password_change);
} else {
$html_string_password_change = str_replace('{PASSWORD_CHANGE_SHOW}', '', $html_string_password_change);
}
$this->login_template['strings']['PASSWORD_CHANGE_DIV'] = $html_string_password_change;
}
// put in the logout redirect string
if ($this->logout && $LOGOUT_TARGET) {
$html_string = str_replace('{LOGOUT_TARGET}', '<meta http-equiv="refresh" content="0; URL='.$LOGOUT_TARGET.'">', $html_string);
} else {
$html_string = str_replace('{LOGOUT_TARGET}', '', $html_string);
}
// print error messagae // print error messagae
if ($this->login_error) { if ($this->login_error) {
$html_string_password_change = str_replace('{ERROR_MSG}', $this->login_error_msg[$this->login_error].'<br>', $html_string_password_change); $html_string = str_replace('{ERROR_MSG}', $this->login_error_msg[$this->login_error].'<br>', $html_string);
} elseif ($this->password_change_ok && $this->password_change) {
$html_string = str_replace('{ERROR_MSG}', $this->login_error_msg[300].'<br>', $html_string);
} else { } else {
$html_string_password_change = str_replace('{ERROR_MSG}', '<br>', $html_string_password_change); $html_string = str_replace('{ERROR_MSG}', '<br>', $html_string);
} }
// if pw change action, show the float again
if ($this->change_password && !$this->password_change_ok) { // create the replace array context
$html_string_password_change = str_replace('{PASSWORD_CHANGE_SHOW}', '<script language="JavaScript">ShowHideDiv(\'pw_change_div\');</script>', $html_string_password_change); foreach ($this->login_template['strings'] as $string => $data) {
} else { $html_string = str_replace('{'.$string.'}', $data, $html_string);
$html_string_password_change = str_replace('{PASSWORD_CHANGE_SHOW}', '', $html_string_password_change);
} }
$this->login_template['strings']['PASSWORD_CHANGE_DIV'] = $html_string_password_change;
} }
// put in the logout redirect string
if ($this->logout && $LOGOUT_TARGET) {
$html_string = str_replace('{LOGOUT_TARGET}', '<meta http-equiv="refresh" content="0; URL='.$LOGOUT_TARGET.'">', $html_string);
} else {
$html_string = str_replace('{LOGOUT_TARGET}', '', $html_string);
}
// print error messagae
if ($this->login_error) {
$html_string = str_replace('{ERROR_MSG}', $this->login_error_msg[$this->login_error].'<br>', $html_string);
} elseif ($this->password_change_ok && $this->password_change) {
$html_string = str_replace('{ERROR_MSG}', $this->login_error_msg[300].'<br>', $html_string);
} else {
$html_string = str_replace('{ERROR_MSG}', '<br>', $html_string);
}
// create the replace array context
foreach ($this->login_template['strings'] as $string => $data) {
$html_string = str_replace('{'.$string.'}', $data, $html_string);
}
// return the created HTML here // return the created HTML here
return $html_string; return $html_string;
} // if permission is 0 then print out login } // if permission is 0 then print out login

View File

@@ -1238,7 +1238,7 @@ class Basic
// DESC : calculates the bytes based on a string with nnG, nnM, etc // DESC : calculates the bytes based on a string with nnG, nnM, etc
public static function stringByteFormat($number) public static function stringByteFormat($number)
{ {
$number = trim($number); $number = (int)trim($number);
$last = strtolower($number[strlen($number) - 1]); $last = strtolower($number[strlen($number) - 1]);
switch ($last) { switch ($last) {
case 't': case 't':
@@ -2266,6 +2266,15 @@ class Basic
} }
} }
// METHOD: removeLB
// PARAMS: string, optional replace character
// RETURN: string with line breaks removed
// DESC : strips out all line breaks or replaced with given string
public function removeLB($string, $replace = ' ')
{
return str_replace(array("\r", "\n"), $replace, $string);
}
// METHOD: setFormToken // METHOD: setFormToken
// PARAMS: session name, if not set then default is form_token // PARAMS: session name, if not set then default is form_token
// RETURN: form token // RETURN: form token

View File

@@ -410,6 +410,7 @@ class ArrayIO extends \CoreLibs\DB\IO
} }
$q_data .= $_value; $q_data .= $_value;
} elseif ($this->table_array[$column]['bool']) { } elseif ($this->table_array[$column]['bool']) {
// boolean storeage (reverse check on ifset)
$q_data .= "'".$this->dbBoolean($this->table_array[$column]["value"], true)."'"; $q_data .= "'".$this->dbBoolean($this->table_array[$column]["value"], true)."'";
} elseif ($this->table_array[$column]["interval"]) { } elseif ($this->table_array[$column]["interval"]) {
// for interval we check if no value, then we set null // for interval we check if no value, then we set null

View File

@@ -124,7 +124,7 @@
* - closes db connection and writes error_msg to global error_msg * - closes db connection and writes error_msg to global error_msg
* db_cursor_pos($query) * db_cursor_pos($query)
* - returns the current position the db_return * - returns the current position the db_return
* $array_of_hashes db_show_table_meta_Data($table_name) * $array_of_hashes db_show_table_meta_data($table_name)
* - returns an hashed array of table column data * - returns an hashed array of table column data
* function db_prepare($stm_name, $query) * function db_prepare($stm_name, $query)
* - prepares a query with the given stm name, returns false on error * - prepares a query with the given stm name, returns false on error
@@ -317,11 +317,11 @@ class IO extends \CoreLibs\Basic
$this->db_user = $db_config['db_user'] ?? ''; $this->db_user = $db_config['db_user'] ?? '';
$this->db_pwd = $db_config['db_pass'] ?? ''; $this->db_pwd = $db_config['db_pass'] ?? '';
$this->db_host = $db_config['db_host'] ?? ''; $this->db_host = $db_config['db_host'] ?? '';
$this->db_port = array_key_exists('db_port', $db_config) ? $db_config['db_port'] : '5432'; $this->db_port = !empty($db_config['db_port']) ? $db_config['db_port'] : '5432';
$this->db_schema = array_key_exists('db_schema', $db_config) ? $db_config['db_schema'] : ''; // do not set to 'public' if not set, because the default is already public $this->db_schema = !empty($db_config['db_schema']) ? $db_config['db_schema'] : ''; // do not set to 'public' if not set, because the default is already public
$this->db_encoding = array_key_exists('db_encoding', $db_config) ? $db_config['db_encoding'] : ''; $this->db_encoding = !empty($db_config['db_encoding']) ? $db_config['db_encoding'] : '';
$this->db_type = $db_config['db_type'] ?? ''; $this->db_type = $db_config['db_type'] ?? '';
$this->db_ssl = array_key_exists('db_ssl', $db_config) ? $db_config['db_ssl'] : 'allow'; $this->db_ssl = !empty($db_config['db_ssl']) ? $db_config['db_ssl'] : 'allow';
// set the target encoding to the DEFAULT_ENCODING if it is one of them: EUC, Shift_JIS, UTF-8 // set the target encoding to the DEFAULT_ENCODING if it is one of them: EUC, Shift_JIS, UTF-8
// @ the moment set only from outside // @ the moment set only from outside
@@ -938,7 +938,7 @@ class IO extends \CoreLibs\Basic
// DESC : returns the current set client encoding from the connected DB // DESC : returns the current set client encoding from the connected DB
public function dbGetEncoding() public function dbGetEncoding()
{ {
return $this->db_return_row('SHOW client_encoding')['client_encoding']; return $this->dbReturnRow('SHOW client_encoding')['client_encoding'];
} }
// METHOD: dbInfo // METHOD: dbInfo