1
0
Fork 0

Enforce POST and validate input for profile forms

master
Anonymous Contributor 2023-08-23 18:16:35 +02:00
parent f073fb621d
commit 841f1707eb
1 changed files with 110 additions and 120 deletions

View File

@ -2,25 +2,18 @@
$statement = $RUNTIME['PDO']->prepare("CREATE TABLE IF NOT EXISTS `iarstates` (`userID` VARCHAR(36) NOT NULL COLLATE 'utf8_unicode_ci', `filesize` BIGINT(20) NOT NULL DEFAULT '0', `iarfilename` VARCHAR(64) NOT NULL COLLATE 'utf8_unicode_ci', `running` INT(1) NOT NULL DEFAULT '0', PRIMARY KEY (`userID`) USING BTREE) COLLATE='utf8_unicode_ci' ENGINE=InnoDB;"); $statement = $RUNTIME['PDO']->prepare("CREATE TABLE IF NOT EXISTS `iarstates` (`userID` VARCHAR(36) NOT NULL COLLATE 'utf8_unicode_ci', `filesize` BIGINT(20) NOT NULL DEFAULT '0', `iarfilename` VARCHAR(64) NOT NULL COLLATE 'utf8_unicode_ci', `running` INT(1) NOT NULL DEFAULT '0', PRIMARY KEY (`userID`) USING BTREE) COLLATE='utf8_unicode_ci' ENGINE=InnoDB;");
$statement->execute(); $statement->execute();
$HTML->setHTMLTitle("Dein Profile");
$HTML->importSeitenInhalt("profile.html");
//Prüfe ob IAR grade erstellt wird. //Prüfe ob IAR grade erstellt wird.
$IARRUNNING = FALSE;
$statementIARCheck = $RUNTIME['PDO']->prepare('SELECT 1 FROM iarstates WHERE userID =:userID'); $statementIARCheck = $RUNTIME['PDO']->prepare('SELECT 1 FROM iarstates WHERE userID =:userID');
$statementIARCheck->execute(['userID' => $_SESSION['UUID']]); $statementIARCheck->execute(['userID' => $_SESSION['UUID']]);
if($statementIARCheck->rowCount() != 0) $IARRUNNING = $statementIARCheck->rowCount() != 0;
{ $statementIARCheck->closeCursor();
$HTML->ReplaceSeitenInhalt("%%IARINFOMESSAGE%%", '<div class="alert alert-danger" role="alert">Aktuell wird eine IAR erstellt.<br>Warte bitte bis du eine PM bekommst.</div>');
$HTML->ReplaceSeitenInhalt("%%IARBUTTONSTATE%%", 'disabled');
$IARRUNNING = TRUE;
}
if(isset($_REQUEST['createIAR'])) if($_SERVER['REQUEST_METHOD'] == 'POST') {
{ include 'app/FormValidator.php';
if($IARRUNNING == FALSE)
{ if(isset($_POST['createIAR'])) {
$validator = new FormValidator(array()); // CSRF validation only
if($validator->isValid($_POST) && $IARRUNNING == FALSE) {
$iarname = md5(time().$_SESSION['UUID'] . rand()).".iar"; $iarname = md5(time().$_SESSION['UUID'] . rand()).".iar";
$HTML->ReplaceSeitenInhalt("%%IARINFOMESSAGE%%", '<div class="alert alert-danger" role="alert">Deine IAR wird jetzt erstellt und der Download Link wird dir per PM zugesendet. '.$APIResult.'</div>'); $HTML->ReplaceSeitenInhalt("%%IARINFOMESSAGE%%", '<div class="alert alert-danger" role="alert">Deine IAR wird jetzt erstellt und der Download Link wird dir per PM zugesendet. '.$APIResult.'</div>');
@ -30,15 +23,20 @@
$statementIARSTART->execute(['userID' => $_SESSION['UUID'], 'filesize' => 0, 'iarfilename' => $iarname]); $statementIARSTART->execute(['userID' => $_SESSION['UUID'], 'filesize' => 0, 'iarfilename' => $iarname]);
} }
} }
else if(isset($_POST['saveProfileData'])) {
$validator = new FormValidator(array(
'formInputFeldVorname' => array('regex' => '/[^\\/<>\s]{1,64}/'),
'formInputFeldNachname' => array('regex' => '/[^\\/<>\s]{1,64}/'),
'formInputFeldEMail' => array('regex' => '/\S{1,64}@\S{1,250}.\S{2,64}/'),
'formInputFeldOfflineIM' => array('regex' => '(|on)'),
'formInputFeldPartnerName' => array('regex' => '/[^\\/<>\s]{1,64} [^\\/<>\s]{1,64}/')
));
if(isset($_REQUEST['formInputFeldVorname']) && $_REQUEST['formInputFeldVorname'] != "") if($validator->isValid($_POST)) {
{ if(isset($_POST['formInputFeldVorname']) && $_POST['formInputFeldVorname'] != "") {
$NewFirstName = trim($_REQUEST['formInputFeldVorname']); $NewFirstName = trim($_POST['formInputFeldVorname']);
if($NewFirstName != "") if($NewFirstName != "" && $_SESSION['FIRSTNAME'] != $NewFirstName) {
{
if($_SESSION['FIRSTNAME'] != $NewFirstName)
{
$statement = $RUNTIME['PDO']->prepare('UPDATE UserAccounts SET FirstName = :FirstName WHERE PrincipalID = :PrincipalID'); $statement = $RUNTIME['PDO']->prepare('UPDATE UserAccounts SET FirstName = :FirstName WHERE PrincipalID = :PrincipalID');
$statement->execute(['FirstName' => $NewFirstName, 'PrincipalID' => $_SESSION['UUID']]); $statement->execute(['FirstName' => $NewFirstName, 'PrincipalID' => $_SESSION['UUID']]);
$_SESSION['FIRSTNAME'] = $NewFirstName; $_SESSION['FIRSTNAME'] = $NewFirstName;
@ -46,16 +44,11 @@
$_SESSION['DISPLAYNAME'] = strtoupper($_SESSION['USERNAME']); $_SESSION['DISPLAYNAME'] = strtoupper($_SESSION['USERNAME']);
} }
} }
}
if(isset($_REQUEST['formInputFeldNachname']) && $_REQUEST['formInputFeldNachname'] != "") if(isset($_POST['formInputFeldNachname']) && $_POST['formInputFeldNachname'] != "") {
{ $NewLastName = trim($_POST['formInputFeldNachname']);
$NewLastName = trim($_REQUEST['formInputFeldNachname']);
if($NewLastName != "") if($NewLastName != "" && $_SESSION['LASTNAME'] != $NewLastName) {
{
if($_SESSION['LASTNAME'] != $NewLastName)
{
$statement = $RUNTIME['PDO']->prepare('UPDATE UserAccounts SET LastName = :LastName WHERE PrincipalID = :PrincipalID'); $statement = $RUNTIME['PDO']->prepare('UPDATE UserAccounts SET LastName = :LastName WHERE PrincipalID = :PrincipalID');
$statement->execute(['LastName' => $NewLastName, 'PrincipalID' => $_SESSION['UUID']]); $statement->execute(['LastName' => $NewLastName, 'PrincipalID' => $_SESSION['UUID']]);
$_SESSION['LASTNAME'] = $NewLastName; $_SESSION['LASTNAME'] = $NewLastName;
@ -63,16 +56,11 @@
$_SESSION['DISPLAYNAME'] = strtoupper($_SESSION['USERNAME']); $_SESSION['DISPLAYNAME'] = strtoupper($_SESSION['USERNAME']);
} }
} }
}
if(isset($_REQUEST['formInputFeldEMail']) && $_REQUEST['formInputFeldEMail'] != "") if(isset($_POST['formInputFeldEMail']) && $_POST['formInputFeldEMail'] != "") {
{ $NewEMail = trim($_POST['formInputFeldEMail']);
$NewEMail = trim($_REQUEST['formInputFeldEMail']);
if($NewEMail != "") if($NewEMail != "" && $_SESSION['EMAIL'] != $NewEMail) {
{
if($_SESSION['EMAIL'] != $NewEMail)
{
$statement = $RUNTIME['PDO']->prepare('UPDATE UserAccounts SET Email = :Email WHERE PrincipalID = :PrincipalID'); $statement = $RUNTIME['PDO']->prepare('UPDATE UserAccounts SET Email = :Email WHERE PrincipalID = :PrincipalID');
$statement->execute(['Email' => $NewEMail, 'PrincipalID' => $_SESSION['UUID']]); $statement->execute(['Email' => $NewEMail, 'PrincipalID' => $_SESSION['UUID']]);
@ -82,21 +70,11 @@
$_SESSION['EMAIL'] = $NewEMail; $_SESSION['EMAIL'] = $NewEMail;
} }
} }
}
if(isset($_REQUEST['formInputFeldOfflineIM']) && $_REQUEST['formInputFeldOfflineIM'] != "") if(isset($_POST['formInputFeldOfflineIM']) && $_POST['formInputFeldOfflineIM'] == "on") {
{
$NewOfflineIM = trim($_REQUEST['formInputFeldOfflineIM']);
if($NewOfflineIM != "")
{
if($NewOfflineIM == "on" || $NewOfflineIM == "true")
{
$statement = $RUNTIME['PDO']->prepare('UPDATE usersettings SET imviaemail = :IMState WHERE useruuid = :PrincipalID'); $statement = $RUNTIME['PDO']->prepare('UPDATE usersettings SET imviaemail = :IMState WHERE useruuid = :PrincipalID');
$statement->execute(['IMState' => 'true', 'PrincipalID' => $_SESSION['UUID']]); $statement->execute(['IMState' => 'true', 'PrincipalID' => $_SESSION['UUID']]);
} } else {
}
}else if(!isset($_REQUEST['formInputFeldOfflineIM']) && isset($_REQUEST['saveProfileData'])){
$statement = $RUNTIME['PDO']->prepare('UPDATE usersettings SET imviaemail = :IMState WHERE useruuid = :PrincipalID'); $statement = $RUNTIME['PDO']->prepare('UPDATE usersettings SET imviaemail = :IMState WHERE useruuid = :PrincipalID');
$statement->execute(['IMState' => 'false', 'PrincipalID' => $_SESSION['UUID']]); $statement->execute(['IMState' => 'false', 'PrincipalID' => $_SESSION['UUID']]);
} }
@ -104,30 +82,42 @@
include 'app/OpenSim.php'; include 'app/OpenSim.php';
$opensim = new OpenSim(); $opensim = new OpenSim();
if(isset($_REQUEST['formInputFeldPartnerName']) && $_REQUEST['formInputFeldPartnerName'] != "") if(isset($_POST['formInputFeldPartnerName']) && $_POST['formInputFeldPartnerName'] != "") {
{ $NewPartner = trim($_POST['formInputFeldPartnerName']);
$NewPartner = trim($_REQUEST['formInputFeldPartnerName']);
$CurrentPartner = $opensim->getPartner($_SESSION['UUID']); $CurrentPartner = $opensim->getPartner($_SESSION['UUID']);
if($CurrentPartner != "")$CurrentPartner = $opensim->getUserName($CurrentPartner); if($CurrentPartner != "")$CurrentPartner = $opensim->getUserName($CurrentPartner);
if($NewPartner != "") if($NewPartner != "" && $CurrentPartner != $NewPartner) {
{
if($CurrentPartner != $NewPartner)
{
$newPartnerUUID = $opensim->getUserUUID($NewPartner); $newPartnerUUID = $opensim->getUserUUID($NewPartner);
if($newPartnerUUID != null) if($newPartnerUUID != null) {
{
$statement = $RUNTIME['PDO']->prepare('UPDATE userprofile SET profilePartner = :profilePartner WHERE useruuid = :PrincipalID'); $statement = $RUNTIME['PDO']->prepare('UPDATE userprofile SET profilePartner = :profilePartner WHERE useruuid = :PrincipalID');
$statement->execute(['profilePartner' => $newPartnerUUID, 'PrincipalID' => $_SESSION['UUID']]); $statement->execute(['profilePartner' => $newPartnerUUID, 'PrincipalID' => $_SESSION['UUID']]);
} }
}
}else{ }else{
$statement = $RUNTIME['PDO']->prepare('UPDATE userprofile SET profilePartner = :profilePartner WHERE useruuid = :PrincipalID'); $statement = $RUNTIME['PDO']->prepare('UPDATE userprofile SET profilePartner = :profilePartner WHERE useruuid = :PrincipalID');
$statement->execute(['profilePartner' => '00000000-0000-0000-0000-000000000000', 'PrincipalID' => $_SESSION['UUID']]); $statement->execute(['profilePartner' => '00000000-0000-0000-0000-000000000000', 'PrincipalID' => $_SESSION['UUID']]);
} }
} }
}
}
else if(isset($_POST['savePassword'])) {
}
header('Location: index.php?page=profile');
die();
}
$HTML->setHTMLTitle("Dein Profile");
$HTML->importSeitenInhalt("profile.html");
if(!$IARRUNNING)
{
$HTML->ReplaceSeitenInhalt("%%IARINFOMESSAGE%%", '<div class="alert alert-danger" role="alert">Aktuell wird eine IAR erstellt.<br>Warte bitte bis du eine PM bekommst.</div>');
$HTML->ReplaceSeitenInhalt("%%IARBUTTONSTATE%%", 'disabled');
}
$statementLocalUsers = $RUNTIME['PDO']->prepare("SELECT FirstName,LastName FROM UserAccounts ORDER BY PrincipalID ASC"); $statementLocalUsers = $RUNTIME['PDO']->prepare("SELECT FirstName,LastName FROM UserAccounts ORDER BY PrincipalID ASC");
$statementLocalUsers->execute(); $statementLocalUsers->execute();