self opening modals, loginredirects keep fragment data

This commit is contained in:
marko
2022-06-12 19:54:29 +02:00
parent 56fe127c81
commit 8329a6b2df
8 changed files with 72 additions and 57 deletions

View File

@@ -1,14 +1,17 @@
<?php
setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
require_once("config/participo.php");
set_include_path(get_include_path() . PATH_SEPARATOR . "./lib/");
require_once("participoLib/participo.php");
require_once("participoLib/planer.php");
require_once("config/participo.php");
require_once("./local/dbConf.php");
require_once("./local/cwsvJudo.php");
require_once("./lib/db.php");
require_once("./lib/api.php");
require_once("./lib/participoLib/participo.php");
require_once("./lib/participoLib/planer.php");
require_once($config['basePath']."/config/cwsvJudo.config.php");

View File

@@ -1,6 +1,4 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "./lib/");
include_once("events.inc.php");
?>
@@ -21,6 +19,21 @@ include_once("events.inc.php");
// specify options here
});
});
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.modal');
var instances = M.Modal.init(elems, {
// specify options here
});
});
// Open the given modal
document.addEventListener('DOMContentLoaded', function () {
// So far we assume the first given fragment (the stuff behind the #) is the modalId
var eventId = window.location.hash.substr(1);
var Modalelem = document.querySelector('#event-modal-'+eventId);
var instance = M.Modal.init(Modalelem);
instance.open();
});
</script>
@@ -70,6 +83,7 @@ include_once("events.inc.php");
<?php if($_SESSION['login']){ ?>
<main>
<h1 id="eventList">Übersicht anstehender Events</h1>
<!-- Table with events-->
<?php echo( eventPlaner::getHtmlEventTable(eventPlaner::getCommingWkEvents()) );?>
<h1 id="detailedEventList">Detailansicht kommender Wettkämpfe</h1>

View File

@@ -1,5 +1,8 @@
<?php
setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
set_include_path(get_include_path() . PATH_SEPARATOR . "./lib/");
require_once("participoLib/participo.php");
require_once("config/participo.php");
require_once("./local/dbConf.php");
@@ -7,8 +10,7 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
require_once("./lib/db.php");
require_once("./lib/api.php");
require_once("./lib/participoLib/participo.php");
require_once("./auth.php");
$basePath = $config['basePath'];
@@ -81,9 +83,6 @@ foreach($years as $year){?>
</ul>
</header>
<?php
if($_SESSION['login']){
?>
<main>
<!-- List of Infos -->
<div class="row" id="infoList">

View File

@@ -37,7 +37,7 @@ class participo{
static public function authentificate(){
session_start();
if ( !self::isLoginValid() ) {
header("Location: login?returnToUrl=".urlencode($_SERVER['REQUEST_URI']), TRUE, 301);
header("Location: login?returnToUrl=".urlencode($_SERVER['REQUEST_URI'].($_POST['fragment'] ?? "")), TRUE, 301);
exit(); // should'nt matter
}
}
@@ -45,6 +45,15 @@ class participo{
static public function getMessages(){return self::$message;}
static public function addMessage($type, $message){self::$message[$type] = (self::$message[$type] ?? "").$message;}
/**
* check password for user
*
* @param string $loginName user who wants to get in
* @param string $password passwor for the user
*
* @retval true $password belongs to $loginName
* @retval false otherwise
*/
static public function checkCredentials($loginName, $password){
sleep(1); // just to discurrage brute force attacks
// Check for dbConnection
@@ -291,44 +300,6 @@ function loadMarkdownFile($fileName){
);
}
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
*

View File

@@ -88,10 +88,23 @@ class event{
public function htmlTableRow(){
return
"<tr>".
"<td>".$this->date->format("Y-m-d")."</td>".
"<td>Datum ".$this->date->format("Y-m-d")."</td>".
"<td><a href=\"/pages/desktop/wkParticipo/showWkEvent.php?eventId=".$this->id."\" >".$this->shiai->getName()."</a></td>".
"<td><a class=\"waves-effect waves-light btn-floating modal-trigger\" href=\"#event-modal-".$this->id."\"><i class=\"material-icons\">add</i></a></td>".
"</tr>";
}
public function htmlModal(){
return
"<div id=\"event-modal-".$this->id."\" class=\"modal\">".
"<div class=\"modal-content\">".
"<h4>".$this->shiai->getName()."</h4>".
"<p>A bunch of text</p>".
"</div>". // end modal-content
"<div class=\"modal-footer\">".
"<a href=\"#!\" class=\"modal-close waves-effect waves-green btn-flat\">Agree</a>".
"</div>".
"</div>";
}
static public function fromArray($member){
$shiai = json_decode($member['bemerkungen'], true);
@@ -157,10 +170,14 @@ class eventPlaner{
static public function getHtmlEventTable($eventList){
$ret = "<table>";
$ret .= "<!-- And now the table -->";
foreach($eventList as $event){
$ret .= $event->htmlTableRow();
}
$ret .= "</table>";
foreach($eventList as $event){
$ret .= $event->htmlModal();
}
return $ret;
}
}

View File

@@ -1,7 +1,8 @@
<?php
setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
set_include_path(get_include_path() . PATH_SEPARATOR . "./lib/");
require_once("lib/participoLib/participo.php");
require_once("participoLib/participo.php");
require_once("config/participo.php");
require_once("./local/dbConf.php");
@@ -28,10 +29,10 @@ else{
$message = ['error' => "Es wurden nicht alle Felder ausgefüllt."];
} else {
if( participo::checkCredentials( $_POST['f']['username'], $_POST['f']['password']) ){
$returnToUrl = $_POST['returnToUrl'] ?? ".";
$returnToUrl = ($_POST['returnToUrl'] ?? ".").($_POST['fragment'] ?? "");
participo::addMessage('success', "<div><a href=\"".$returnToUrl."\">weiter zum Inhalt</a>.</div>");
participo::addMessage('notice', "OnlineApps - cwsvJudo");
header("Location: " . $returnToUrl );
header("Location: " . $returnToUrl, TRUE, 301 );
}
}
}
@@ -66,6 +67,14 @@ else{
</div>
<?php if( isset( $_GET['returnToUrl']) ) echo("<input type=\"hidden\" name=\"returnToUrl\" value=\"".htmlspecialchars( $_GET['returnToUrl'])."\" />"); ?>
<?php if( isset($_POST['returnToUrl']) ) echo("<input type=\"hidden\" name=\"returnToUrl\" value=\"".htmlspecialchars($_POST['returnToUrl'])."\" />"); ?>
<input id="fragment" type="hidden" name="fragment" />
<!-- add the fragment to the post data-->
<script>
if(window.location.hash){
document.getElementById("fragment").value=window.location.hash;
}
</script>
</fieldset>
<fieldset>
<div>