Use POST for managing identities, validate input
parent
9d760f7dc3
commit
6ca8988128
|
@ -1,21 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
$HTML->setHTMLTitle("Identitäten");
|
|
||||||
$HTML->importSeitenInhalt("identities.html");
|
|
||||||
|
|
||||||
$statementCreateTable = $RUNTIME['PDO']->prepare("CREATE TABLE IF NOT EXISTS `UserIdentitys` (`PrincipalID` VARCHAR(38) NOT NULL, `IdentityID` VARCHAR(38) NOT NULL, PRIMARY KEY (`IdentityID`))");
|
$statementCreateTable = $RUNTIME['PDO']->prepare("CREATE TABLE IF NOT EXISTS `UserIdentitys` (`PrincipalID` VARCHAR(38) NOT NULL, `IdentityID` VARCHAR(38) NOT NULL, PRIMARY KEY (`IdentityID`))");
|
||||||
$statementCreateTable->execute();
|
$statementCreateTable->execute();
|
||||||
|
|
||||||
$statementCheckForEntry = $RUNTIME['PDO']->prepare("SELECT 1 FROM UserIdentitys WHERE PrincipalID = ? LIMIT 1");
|
if($_SERVER['REQUEST_TYPE'] == 'POST') {
|
||||||
$statementCheckForEntry->execute(array($_SESSION['UUID']));
|
include '../app/FormValidator.php';
|
||||||
|
if(isset($_POST['enableIdent'])) {
|
||||||
|
$validator = new FormValidator(array(
|
||||||
|
'newuuid' => array('required' => true, 'regex' => '/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/')
|
||||||
|
));
|
||||||
|
|
||||||
if($statementCheckForEntry->rowCount() == 0)
|
if($validator->isValid($_POST)) {
|
||||||
{
|
|
||||||
$statement = $RUNTIME['PDO']->prepare('INSERT INTO `UserIdentitys` (PrincipalID, IdentityID) VALUES (:PrincipalID, :IdentityID)');
|
|
||||||
$statement->execute(['PrincipalID' => $_SESSION['UUID'], 'IdentityID' => $_SESSION['UUID']]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($_REQUEST['enableIdent']) && isset($_REQUEST['newuuid']) && $_REQUEST['enableIdent'] == "" && $_REQUEST['newuuid'] != "")
|
|
||||||
{
|
|
||||||
$statement = $RUNTIME['PDO']->prepare("SELECT 1 FROM UserIdentitys WHERE PrincipalID = :PrincipalID AND IdentityID = :IdentityID LIMIT 1");
|
$statement = $RUNTIME['PDO']->prepare("SELECT 1 FROM UserIdentitys WHERE PrincipalID = :PrincipalID AND IdentityID = :IdentityID LIMIT 1");
|
||||||
$statement->execute(['PrincipalID' => $_SESSION['UUID'], 'IdentityID' => $_REQUEST['newuuid']]);
|
$statement->execute(['PrincipalID' => $_SESSION['UUID'], 'IdentityID' => $_REQUEST['newuuid']]);
|
||||||
|
|
||||||
|
@ -55,20 +49,18 @@
|
||||||
|
|
||||||
$_SESSION['LOGIN'] = 'false';
|
$_SESSION['LOGIN'] = 'false';
|
||||||
session_destroy();
|
session_destroy();
|
||||||
|
|
||||||
header("Location: index.php?page=identities");
|
|
||||||
die();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$HTML->ReplaceSeitenInhalt("%%MESSAGE%%", '<div class="alert alert-danger" role="alert">Du kannst die Identität nicht ändern, während du angemeldet bist. Bitte schließe den Viewer.</div>');
|
$_SESSION['identities_err'] = 'Du kannst die Identität nicht ändern, während du angemeldet bist. Bitte schließe den Viewer.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if(isset($_POST['createIdent'])) {
|
||||||
|
$validator = new FormValidator(array(
|
||||||
|
'newName' => array('required' => true, 'regex' => '')
|
||||||
|
));
|
||||||
|
|
||||||
include 'app/OpenSim.php';
|
if($validator->isValid($_POST)) {
|
||||||
$opensim = new OpenSim();
|
|
||||||
|
|
||||||
if(isset($_REQUEST['createIdent']) && isset($_REQUEST['newName']) && $_REQUEST['createIdent'] == "" && $_REQUEST['newName'] != "")
|
|
||||||
{
|
|
||||||
$avatarNameParts = explode(" ", trim($_REQUEST['newName']));
|
$avatarNameParts = explode(" ", trim($_REQUEST['newName']));
|
||||||
|
|
||||||
if(count($avatarNameParts) == 2)
|
if(count($avatarNameParts) == 2)
|
||||||
|
@ -78,30 +70,46 @@
|
||||||
|
|
||||||
if($statement->rowCount() == 0)
|
if($statement->rowCount() == 0)
|
||||||
{
|
{
|
||||||
$avatarUUID = $opensim->gen_uuid();
|
include 'app/OpenSim.php';
|
||||||
|
$avatarUUID = (new OpenSim())->gen_uuid();
|
||||||
|
|
||||||
$statementAccounts = $RUNTIME['PDO']->prepare('INSERT INTO UserAccounts (PrincipalID, ScopeID, FirstName, LastName, Email, ServiceURLs, Created, UserLevel, UserFlags, UserTitle, active) VALUES (:PrincipalID, :ScopeID, :FirstName, :LastName, :Email, :ServiceURLs, :Created, :UserLevel, :UserFlags, :UserTitle, :active )');
|
$statementAccounts = $RUNTIME['PDO']->prepare('INSERT INTO UserAccounts (PrincipalID, ScopeID, FirstName, LastName, Email, ServiceURLs, Created, UserLevel, UserFlags, UserTitle, active) VALUES (:PrincipalID, :ScopeID, :FirstName, :LastName, :Email, :ServiceURLs, :Created, :UserLevel, :UserFlags, :UserTitle, :active )');
|
||||||
$statementAccounts->execute(['PrincipalID' => $avatarUUID, 'ScopeID' => "00000000-0000-0000-0000-000000000000", 'FirstName' => $avatarNameParts[0], 'LastName' => $avatarNameParts[1], 'Email' => $_SESSION['EMAIL'], 'ServiceURLs' => "HomeURI= GatekeeperURI= InventoryServerURI= AssetServerURI= ", 'Created' => time(), 'UserLevel' => 0, 'UserFlags' => 0, 'UserTitle' => "", 'active' => 1]);
|
$statementAccounts->execute(['PrincipalID' => $avatarUUID, 'ScopeID' => "00000000-0000-0000-0000-000000000000", 'FirstName' => $avatarNameParts[0], 'LastName' => $avatarNameParts[1], 'Email' => $_SESSION['EMAIL'], 'ServiceURLs' => "HomeURI= GatekeeperURI= InventoryServerURI= AssetServerURI= ", 'Created' => time(), 'UserLevel' => 0, 'UserFlags' => 0, 'UserTitle' => "", 'active' => 1]);
|
||||||
//print_r($statementAccounts->errorInfo());
|
|
||||||
|
|
||||||
$statementUserIdentitys = $RUNTIME['PDO']->prepare('INSERT INTO UserIdentitys (PrincipalID, IdentityID) VALUES (:PrincipalID, :IdentityID)');
|
$statementUserIdentitys = $RUNTIME['PDO']->prepare('INSERT INTO UserIdentitys (PrincipalID, IdentityID) VALUES (:PrincipalID, :IdentityID)');
|
||||||
$statementUserIdentitys->execute(['PrincipalID' => $_SESSION['UUID'], 'IdentityID' => $avatarUUID]);
|
$statementUserIdentitys->execute(['PrincipalID' => $_SESSION['UUID'], 'IdentityID' => $avatarUUID]);
|
||||||
//print_r($statementUserIdentitys->errorInfo());
|
}else{
|
||||||
|
$_SESSION['identities_err'] = 'Dieser Name ist schon in Benutzung.';
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$_SESSION['identities_err'] = 'Der Name muss aus einem Vor und einem Nachnamen bestehen.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
header('Location: index.php?page=identities');
|
header('Location: index.php?page=identities');
|
||||||
die();
|
die();
|
||||||
}else{
|
|
||||||
$HTML->ReplaceSeitenInhalt("%%MESSAGE%%", '<div class="alert alert-danger" role="alert">Dieser Name ist schon in Benutzung.</div>');
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
$HTML->ReplaceSeitenInhalt("%%MESSAGE%%", '<div class="alert alert-danger" role="alert">Der Name muss aus einem Vor und einem Nachnamen bestehen.</div>');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$HTML->setHTMLTitle("Identitäten");
|
||||||
|
$HTML->importSeitenInhalt("identities.html");
|
||||||
|
|
||||||
|
$statementCheckForEntry = $RUNTIME['PDO']->prepare("SELECT 1 FROM UserIdentitys WHERE PrincipalID = ? LIMIT 1");
|
||||||
|
$statementCheckForEntry->execute(array($_SESSION['UUID']));
|
||||||
|
|
||||||
|
if($statementCheckForEntry->rowCount() == 0)
|
||||||
|
{
|
||||||
|
$statement = $RUNTIME['PDO']->prepare('INSERT INTO `UserIdentitys` (PrincipalID, IdentityID) VALUES (:PrincipalID, :IdentityID)');
|
||||||
|
$statement->execute(['PrincipalID' => $_SESSION['UUID'], 'IdentityID' => $_SESSION['UUID']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = '<table class="table"><thead><tr><th scope="col">Name</th><th scope="col">Aktionen</th></thead><tbody>%%ENTRY%%</tbody></table>';
|
$table = '<table class="table"><thead><tr><th scope="col">Name</th><th scope="col">Aktionen</th></thead><tbody>%%ENTRY%%</tbody></table>';
|
||||||
$statement = $RUNTIME['PDO']->prepare("SELECT IdentityID FROM UserIdentitys WHERE PrincipalID = ? ORDER BY IdentityID ASC");
|
$statement = $RUNTIME['PDO']->prepare("SELECT IdentityID FROM UserIdentitys WHERE PrincipalID = ? ORDER BY IdentityID ASC");
|
||||||
$statement->execute(array($_SESSION['UUID']));
|
$statement->execute(array($_SESSION['UUID']));
|
||||||
|
|
||||||
|
include 'app/OpenSim.php';
|
||||||
|
$opensim = new OpenSim();
|
||||||
|
|
||||||
while($row = $statement->fetch())
|
while($row = $statement->fetch())
|
||||||
{
|
{
|
||||||
if($row['IdentityID'] == $_SESSION['UUID'])
|
if($row['IdentityID'] == $_SESSION['UUID'])
|
||||||
|
@ -117,7 +125,13 @@
|
||||||
$table = str_replace("%%ENTRY%%", "", $table);
|
$table = str_replace("%%ENTRY%%", "", $table);
|
||||||
$HTML->ReplaceSeitenInhalt("%%IDENT-LIST%%", $table);
|
$HTML->ReplaceSeitenInhalt("%%IDENT-LIST%%", $table);
|
||||||
$HTML->ReplaceSeitenInhalt("%%link%%", ' ');
|
$HTML->ReplaceSeitenInhalt("%%link%%", ' ');
|
||||||
$HTML->ReplaceSeitenInhalt("%%MESSAGE%%", ' ');
|
|
||||||
|
$message = '';
|
||||||
|
if(isset($_SESSION['identities_err'])) {
|
||||||
|
$message = '<div class="alert alert-danger" role="alert">'.$_SESSION['identities_err'].'</div>';
|
||||||
|
unset($_SESSION['identities_err']);
|
||||||
|
}
|
||||||
|
$HTML->ReplaceSeitenInhalt("%%MESSAGE%%", $message);
|
||||||
|
|
||||||
$HTML->build();
|
$HTML->build();
|
||||||
echo $HTML->ausgabe();
|
echo $HTML->ausgabe();
|
||||||
|
|
Loading…
Reference in New Issue