own hosted material icons
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
class participo{
|
||||
private static $db = null;
|
||||
static public function initDbConnection(){}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action element of an MaterializeCss (App-)card
|
||||
*/
|
||||
@@ -126,35 +133,35 @@ function lastLoginTable($jsonFileName="lastLogins.json"){
|
||||
|
||||
/// Eine Fehler/Warnung/Notiz/Erfolgsmeldung als divBox im String zurückgeben
|
||||
function htmlRetMessage($anRetMessage){
|
||||
$retHtmlString = "";
|
||||
if( !empty($anRetMessage) ){
|
||||
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
||||
if( !empty($anRetMessage['error']) ){
|
||||
$retHtmlString = "";
|
||||
if( !empty($anRetMessage) ){
|
||||
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
||||
$retHtmlString .= "ERROR:<br />";
|
||||
$retHtmlString .= $anRetMessage['error'];
|
||||
if( !empty($anRetMessage['error']) ){
|
||||
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
||||
$retHtmlString .= "ERROR:<br />";
|
||||
$retHtmlString .= $anRetMessage['error'];
|
||||
$retHtmlString .= "</div>";
|
||||
}
|
||||
if( !empty($anRetMessage['warning']) ){
|
||||
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
||||
$retHtmlString .= "WARNING:<br />";
|
||||
$retHtmlString .= $anRetMessage['warning'];
|
||||
$retHtmlString .= "</div>";
|
||||
}
|
||||
if( !empty($anRetMessage['notice']) ){
|
||||
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
||||
$retHtmlString .= "Info:<br />";
|
||||
$retHtmlString .= $anRetMessage['notice'];
|
||||
$retHtmlString .= "</div>";
|
||||
}
|
||||
if( !empty($anRetMessage['success']) ){
|
||||
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
||||
$retHtmlString .= "SUCCESS:<br />";
|
||||
$retHtmlString .= $anRetMessage['success'];
|
||||
$retHtmlString .= "</div>";
|
||||
}
|
||||
$retHtmlString .= "</div>";
|
||||
}
|
||||
if( !empty($anRetMessage['warning']) ){
|
||||
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
||||
$retHtmlString .= "WARNING:<br />";
|
||||
$retHtmlString .= $anRetMessage['warning'];
|
||||
$retHtmlString .= "</div>";
|
||||
}
|
||||
if( !empty($anRetMessage['notice']) ){
|
||||
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
||||
$retHtmlString .= "Info:<br />";
|
||||
$retHtmlString .= $anRetMessage['notice'];
|
||||
$retHtmlString .= "</div>";
|
||||
}
|
||||
if( !empty($anRetMessage['success']) ){
|
||||
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
||||
$retHtmlString .= "SUCCESS:<br />";
|
||||
$retHtmlString .= $anRetMessage['success'];
|
||||
$retHtmlString .= "</div>";
|
||||
}
|
||||
$retHtmlString .= "</div>";
|
||||
}
|
||||
return $retHtmlString;
|
||||
}
|
||||
|
||||
@@ -205,4 +212,65 @@ function loadMarkdownFile($fileName){
|
||||
, 'mdText' => $mdText
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function checkCredentials($username, $password, $db_server, $db_user, $db_password, $db_name){
|
||||
sleep(1);
|
||||
$mysqli = @new mysqli($db_server, $db_user, $db_password, $db_name);
|
||||
if ($mysqli->connect_error) {
|
||||
$message['error'] = 'Datenbankverbindung fehlgeschlagen: ' . $mysqli->connect_error;
|
||||
} else {
|
||||
$query = sprintf(
|
||||
"SELECT id, loginName, pwHash, config FROM wkParticipo_Users WHERE loginName = '%s'",
|
||||
$mysqli->real_escape_string($_POST['f']['username'])
|
||||
);
|
||||
$result = $mysqli->query($query);
|
||||
if ($row = $result->fetch_array(MYSQLI_ASSOC)) {
|
||||
if( password_verify( $_POST['f']['password'], $row['pwHash']) ){
|
||||
session_start();
|
||||
$_SESSION = array(
|
||||
'login' => true,
|
||||
'user' => array(
|
||||
'username' => $row['loginName'],
|
||||
'userId' => $row['id'],
|
||||
'userConfig' => json_decode($row['config'], true)
|
||||
),
|
||||
);
|
||||
$message['success'] = 'Anmeldung erfolgreich, <a href="index.php">weiter zum Inhalt</a>.';
|
||||
|
||||
// Logging Logins
|
||||
logLoginsToJsonFile($_SESSION['user']['username']);
|
||||
|
||||
header('Location: http://' . $_SERVER['HTTP_HOST'] . '/participo?user=' . $_POST['f']['username']);
|
||||
} else {
|
||||
sleep(5);
|
||||
$message['error'] = 'Das Kennwort ist nicht korrekt.';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the Login of an user into a logFile
|
||||
*
|
||||
* @param string $userName name of the user
|
||||
* @param string $fileName filename to log to
|
||||
* @return void
|
||||
*/
|
||||
function logLoginsToJsonFile($userName, $fileName="lastLogins.json"){
|
||||
try{
|
||||
$lastLogins = json_decode(file_get_contents($fileName), true);
|
||||
if(!array_key_exists($userName, $lastLogins))
|
||||
$lastLogins[$userName] = [];
|
||||
if(!array_key_exists('lastLogins', $lastLogins[$userName]))
|
||||
$lastLogins[$userName]['lastLogins'] = [];
|
||||
$lastLogins[$userName]['lastLogins'] = array_merge( array( date('Y-m-d H:i:s') ), $lastLogins[$userName]['lastLogins'] );
|
||||
file_put_contents($fileName, json_encode($lastLogins));
|
||||
}
|
||||
catch (Exception $e){
|
||||
// silently ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user