Check if new name is already taken
parent
03f5cd489d
commit
d46835e8eb
|
@ -1,4 +1,17 @@
|
|||
<?php
|
||||
function setNamePart(string $part, string $value, string $otherPart, string $otherValue) {
|
||||
$query = $RUNTIME['PDO']->prepare('SELECT 1 FROM UserAccounts WHERE '.$part.' = ? AND '.$otherPart.' = ?');
|
||||
$query->execute(array($value, $otherValue));
|
||||
|
||||
if($query->rowCount() != 0) {
|
||||
$statement = $RUNTIME['PDO']->prepare('UPDATE UserAccounts SET '.$part.' = ? WHERE PrincipalID = ?');
|
||||
$statement->execute(array($value, $_SESSION['UUID']));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$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();
|
||||
|
||||
|
@ -34,25 +47,31 @@
|
|||
if($validator->isValid($_POST)) {
|
||||
if(isset($_POST['formInputFeldVorname'])) {
|
||||
$NewFirstName = trim($_POST['formInputFeldVorname']);
|
||||
|
||||
|
||||
if($NewFirstName != "" && $_SESSION['FIRSTNAME'] != $NewFirstName) {
|
||||
$statement = $RUNTIME['PDO']->prepare('UPDATE UserAccounts SET FirstName = :FirstName WHERE PrincipalID = :PrincipalID');
|
||||
$statement->execute(['FirstName' => $NewFirstName, 'PrincipalID' => $_SESSION['UUID']]);
|
||||
$_SESSION['FIRSTNAME'] = $NewFirstName;
|
||||
$_SESSION['USERNAME'] = $_SESSION['FIRSTNAME']." ".$_SESSION['LASTNAME'];
|
||||
$_SESSION['DISPLAYNAME'] = strtoupper($_SESSION['USERNAME']);
|
||||
if(setNamePart('FirstName', $NewFirstName, 'LastName', isset($_POST['formInputFeldNachname']) && trim($_POST['formInputFeldNachname']) > 0 ? $_POST['formInputFeldNachname'] : $_SESSION['LASTNAME'])) {
|
||||
$_SESSION['FIRSTNAME'] = $NewFirstName;
|
||||
$_SESSION['USERNAME'] = $_SESSION['FIRSTNAME']." ".$_SESSION['LASTNAME'];
|
||||
$_SESSION['DISPLAYNAME'] = strtoupper($_SESSION['USERNAME']);
|
||||
}
|
||||
else {
|
||||
$_SESSION['profile_info'] = 'Der gewählte Name ist bereits vergeben.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_POST['formInputFeldNachname'])) {
|
||||
$NewLastName = trim($_POST['formInputFeldNachname']);
|
||||
|
||||
|
||||
if($NewLastName != "" && $_SESSION['LASTNAME'] != $NewLastName) {
|
||||
$statement = $RUNTIME['PDO']->prepare('UPDATE UserAccounts SET LastName = :LastName WHERE PrincipalID = :PrincipalID');
|
||||
$statement->execute(['LastName' => $NewLastName, 'PrincipalID' => $_SESSION['UUID']]);
|
||||
$_SESSION['LASTNAME'] = $NewLastName;
|
||||
$_SESSION['USERNAME'] = $_SESSION['FIRSTNAME']." ".$_SESSION['LASTNAME'];
|
||||
$_SESSION['DISPLAYNAME'] = strtoupper($_SESSION['USERNAME']);
|
||||
if(setNamePart('LastName', $NewLastName, 'FirstName', isset($_POST['formInputFeldVorname']) && trim($_POST['formInputFeldVorname']) > 0 ? $_POST['formInputFeldVorname'] : $_SESSION['FIRSTNAME'])) {
|
||||
$_SESSION['LASTNAME'] = $NewLastName;
|
||||
$_SESSION['USERNAME'] = $_SESSION['FIRSTNAME']." ".$_SESSION['LASTNAME'];
|
||||
$_SESSION['DISPLAYNAME'] = strtoupper($_SESSION['USERNAME']);
|
||||
}
|
||||
else {
|
||||
$_SESSION['profile_info'] = 'Der gewählte Name ist bereits vergeben.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue