1
0
Fork 0

Actually merge profile and password change pages

master
Anonymous Contributor 2023-08-23 18:16:35 +02:00
parent 4d20b7e2f3
commit c3106f4787
3 changed files with 41 additions and 116 deletions

View File

@ -1,66 +0,0 @@
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(!isset($_SESSION['LOGIN']) || !isset($_SESSION['UUID'])) {
header('Location: index.php');
die();
}
include 'app/FormValidator.php';
$validator = new FormValidator(array(
'oldPassword' => array('required' => true, 'regex' => '/.{1,1000}/'),
'newPassword' => array('required' => true, 'regex' => '/.{1,1000}/'),
'newPasswordRepeat' => array('required' => true, 'regex' => '/.{1,1000}/')
));
if($validator->isValid($_POST)) {
if($_POST['newPasswordRepeat'] == $_POST['newPassword']) {
if(password_verify($_POST['oldPassword'], $_SESSION['PASSWORD'])) {
$hash = password_hash($NewPassword, PASSWORD_ARGON2ID);
$statement = $RUNTIME['PDO']->prepare('UPDATE auth SET passwordHash = :PasswordHash WHERE UUID = :PrincipalID');
$statement->execute(['PasswordHash' => $hash, 'PrincipalID' => $_SESSION['UUID']]);
$_SESSION['PASSWORD'] = $hash;
$_SESSION['pw_info'] = 'Neues Passwort gespeichert.';
}
else {
$_SESION['pw_info'] = 'Das alte Passwort ist nicht richtig!';
}
}
else {
$_SESSION['pw_info'] = 'Die neuen Passwörter stimmen nicht überein!';
}
}
else {
$_SESSION['pw_info'] = 'Bitte fülle das Formular vollständig aus.';
}
header('Location: index.php?page=password');
die();
}
$HTML->setHTMLTitle("Passwort ändern");
$HTML->importSeitenInhalt("profile.html");
include 'app/OpenSim.php';
$opensim = new OpenSim();
$PartnerName = "";
$PartnerUUID = $opensim->getPartner($_SESSION['UUID']);
if($PartnerUUID != null)$PartnerName = $opensim->getUserName($PartnerUUID);
$HTML->ReplaceSeitenInhalt("%%offlineIMSTATE%%", ' ');
$HTML->ReplaceSeitenInhalt("%%firstname%%", htmlspecialchars($_SESSION['FIRSTNAME']));
$HTML->ReplaceSeitenInhalt("%%lastname%%", htmlspecialchars($_SESSION['LASTNAME']));
$HTML->ReplaceSeitenInhalt("%%partner%%", htmlspecialchars($PartnerName));
$HTML->ReplaceSeitenInhalt("%%email%%", htmlspecialchars($opensim->getUserMail($_SESSION['UUID'])));
$HTML->ReplaceSeitenInhalt("%%listAllResidentsAsJSArray%%", "");
$pwInfo = '';
if(isset($_SESSION['pw_info'])) {
$pwInfo = $_SESSION['pw_info'];
unset($_SESSION['pw_info']);
}
$HTML->ReplaceSeitenInhalt("%%INFOMESSAGE%%", $pwInfo);
$HTML->build();
echo $HTML->ausgabe();
?>

View File

@ -28,7 +28,7 @@
'formInputFeldVorname' => array('regex' => '/[^\\/<>\s]{1,64}/'), 'formInputFeldVorname' => array('regex' => '/[^\\/<>\s]{1,64}/'),
'formInputFeldNachname' => array('regex' => '/[^\\/<>\s]{1,64}/'), 'formInputFeldNachname' => array('regex' => '/[^\\/<>\s]{1,64}/'),
'formInputFeldEMail' => array('regex' => '/\S{1,64}@\S{1,250}.\S{2,64}/'), 'formInputFeldEMail' => array('regex' => '/\S{1,64}@\S{1,250}.\S{2,64}/'),
'formInputFeldOfflineIM' => array('regex' => '(|on)'), 'formInputFeldOfflineIM' => array('regex' => '/(|on)/'),
'formInputFeldPartnerName' => array('regex' => '/[^\\/<>\s]{1,64} [^\\/<>\s]{1,64}/') 'formInputFeldPartnerName' => array('regex' => '/[^\\/<>\s]{1,64} [^\\/<>\s]{1,64}/')
)); ));
@ -79,14 +79,12 @@
$statement->execute(['IMState' => 'false', 'PrincipalID' => $_SESSION['UUID']]); $statement->execute(['IMState' => 'false', 'PrincipalID' => $_SESSION['UUID']]);
} }
include 'app/OpenSim.php';
$opensim = new OpenSim();
if(isset($_POST['formInputFeldPartnerName']) && $_POST['formInputFeldPartnerName'] != "") { if(isset($_POST['formInputFeldPartnerName']) && $_POST['formInputFeldPartnerName'] != "") {
$NewPartner = trim($_POST['formInputFeldPartnerName']); $NewPartner = trim($_POST['formInputFeldPartnerName']);
$CurrentPartner = $opensim->getPartner($_SESSION['UUID']); $CurrentPartner = $opensim->getPartner($_SESSION['UUID']);
if($CurrentPartner != "")$CurrentPartner = $opensim->getUserName($CurrentPartner); include_once 'app/OpenSim.php';
if($CurrentPartner != "")$CurrentPartner = (new OpenSim())->getUserName($CurrentPartner);
if($NewPartner != "" && $CurrentPartner != $NewPartner) { if($NewPartner != "" && $CurrentPartner != $NewPartner) {
$newPartnerUUID = $opensim->getUserUUID($NewPartner); $newPartnerUUID = $opensim->getUserUUID($NewPartner);
@ -103,7 +101,32 @@
} }
} }
else if(isset($_POST['savePassword'])) { else if(isset($_POST['savePassword'])) {
$validator = new FormValidator(array(
'oldPassword' => array('required' => true, 'regex' => '/.{1,1000}/'),
'newPassword' => array('required' => true, 'regex' => '/.{1,1000}/'),
'newPasswordRepeat' => array('required' => true, 'regex' => '/.{1,1000}/')
));
if($validator->isValid($_POST)) {
if($_POST['newPasswordRepeat'] == $_POST['newPassword']) {
if(password_verify($_POST['oldPassword'], $_SESSION['PASSWORD'])) {
$hash = password_hash($NewPassword, PASSWORD_ARGON2ID);
$statement = $RUNTIME['PDO']->prepare('UPDATE auth SET passwordHash = :PasswordHash WHERE UUID = :PrincipalID');
$statement->execute(['PasswordHash' => $hash, 'PrincipalID' => $_SESSION['UUID']]);
$_SESSION['PASSWORD'] = $hash;
$_SESSION['profile_info'] = 'Neues Passwort gespeichert.';
}
else {
$_SESSION['profile_info'] = 'Das alte Passwort ist nicht richtig!';
}
}
else {
$_SESSION['profile_info'] = 'Die neuen Passwörter stimmen nicht überein!';
}
}
else {
$_SESSION['profile_info'] = 'Bitte fülle das Formular vollständig aus.';
}
} }
header('Location: index.php?page=profile'); header('Location: index.php?page=profile');
@ -137,6 +160,9 @@
$allUsers .= '," "'; $allUsers .= '," "';
include_once 'app/OpenSim.php';
$opensim = new OpenSim();
$PartnerUUID = $opensim->getPartner($_SESSION['UUID']); $PartnerUUID = $opensim->getPartner($_SESSION['UUID']);
$PartnerName = ""; $PartnerName = "";
@ -150,7 +176,14 @@
$HTML->ReplaceSeitenInhalt("%%partner%%", htmlspecialchars($PartnerName)); $HTML->ReplaceSeitenInhalt("%%partner%%", htmlspecialchars($PartnerName));
$HTML->ReplaceSeitenInhalt("%%email%%", htmlspecialchars($opensim->getUserMail($_SESSION['UUID']))); $HTML->ReplaceSeitenInhalt("%%email%%", htmlspecialchars($opensim->getUserMail($_SESSION['UUID'])));
$HTML->ReplaceSeitenInhalt("%%listAllResidentsAsJSArray%%", ""); $HTML->ReplaceSeitenInhalt("%%listAllResidentsAsJSArray%%", "");
$HTML->ReplaceSeitenInhalt("%%INFOMESSAGE%%", ' ');
$profileInfo = '';
if(isset($_SESSION['profile_info'])) {
$profileInfo = $_SESSION['profile_info'];
unset($_SESSION['profile_info']);
}
$HTML->ReplaceSeitenInhalt("%%INFOMESSAGE%%", $profileInfo);
$HTML->ReplaceSeitenInhalt("%%IARINFOMESSAGE%%", ' '); $HTML->ReplaceSeitenInhalt("%%IARINFOMESSAGE%%", ' ');
$HTML->ReplaceSeitenInhalt("%%IARBUTTONSTATE%%", ''); $HTML->ReplaceSeitenInhalt("%%IARBUTTONSTATE%%", '');

View File

@ -1,42 +0,0 @@
<center>%%INFOMESSAGE%%</center>
<div style="width: 400px; margin: auto; left: 50%;">
<form action="index.php?page=password" method="post">
<div class="row" style="margin-top: 15px;">
<div class="col">
<label for="oldPassword">Altes Passwort</label>
<input type="text" class="form-control" id="oldPassword" name="oldPassword">
</div>
</div>
<div class="row" style="margin-top: 15px;">
<div class="col">
<label for="newPassword">Neues Passwort</label>
<input type="text" class="form-control" id="PasswordNew" name="newPassword">
</div>
</div>
<div class="row" style="margin-top: 15px;">
<div class="col">
<label for="newPasswordRepeate">Neues Passwort wiederholen</label>
<input type="text" class="form-control" id="PasswordNewRepeat" name="newPasswordRepeat">
</div>
</div>
<div class="row" style="margin-top: 15px;">
<div class="col">
<hr>
</div>
</div>
<div class="row" style="margin-top: 15px;">
<div class="col">
%%CSRF%%
<button type="submit" name="savePassword" class="btn btn-primary btn-lg">Speichern</button>
</div>
</div>
</form>
</div>