Fix more saml vs internal switches, messages, errors. Allow empty user perms.

This commit is contained in:
Josh North 2021-05-07 15:57:31 -04:00
parent 37806023dc
commit 4ce405ca75
4 changed files with 64 additions and 5 deletions

View File

@ -164,9 +164,9 @@
<ul class="navbar-nav mr-sm-2">
<li class="nav-item"><a class="nav-link<?php $sname=$SiteInfo->getSite($siteid, "0", "0", "0")[0]["sites_name"]; if($sname=="NOSITE") { echo " btn btn-sm btn-outline-warning"; } else { echo " btn btn-sm btn-outline-secondary"; }; ?>" href="#" data-toggle="modal" data-target="#sitetimeModal"><i class="fas fa-map-marker-alt"></i> <?php if ($sname=="NOSITE") {echo $transLang['NOSITE'];} else { echo $sname; } ?></a></li>
<?php if (Registry::AUTHMETHOD == 'SAML') { ?>
<li class="nav-item<?php if ($app_current_pagename==$transLang['LOGOUT']): echo " active"; endif; ?>"><a class="nav-link btn btn-sm btn-outline-danger" href="<?php echo str_replace("http%3A%2F%2F","https%3A%2F%2F",$auth->getLogoutURL()); ?>"><span class="badge badge-light"><?php echo $session_user["0"]["users_username"];?></span> <i class="fas fa-ban"></i> <?php echo $transLang['LOGOUT']; ?></a></li>
<li class="nav-item<?php if ($app_current_pagename==$transLang['LOGOUT']): echo " active"; endif; ?>"><a class="nav-link btn btn-sm btn-outline-danger" href="<?php echo str_replace("http%3A%2F%2F","https%3A%2F%2F",$auth->getLogoutURL()); ?>"><span class="badge badge-light"><?php echo $session_user["0"]["users_firstname"] . " " . $session_user["0"]["users_lastname"];?></span> <i class="fas fa-ban"></i> <?php echo $transLang['LOGOUT']; ?></a></li>
<?php } else { ?>
<li class="nav-item<?php if ($app_current_pagename==$transLang['LOGOUT']): echo " active"; endif; ?>"><a class="nav-link btn btn-sm btn-outline-danger" href="logout.php"><span class="badge badge-light"><?php echo $session_user["0"]["users_username"];?></span> <i class="fas fa-ban"></i> <?php echo $transLang['LOGOUT']; ?></a></li>
<li class="nav-item<?php if ($app_current_pagename==$transLang['LOGOUT']): echo " active"; endif; ?>"><a class="nav-link btn btn-sm btn-outline-danger" href="logout.php"><span class="badge badge-light"><?php echo $session_user["0"]["users_firstname"] . " " . $session_user["0"]["users_lastname"];?></span> <i class="fas fa-ban"></i> <?php echo $transLang['LOGOUT']; ?></a></li>
<?php } ?>
<?php endif; ?>
<form action="changelang.php" method="post" name="changelang" class="changelang">

View File

@ -79,6 +79,9 @@
require_once("inc/header.inc.php");
if ($StaticFunctions->getUserSessionStatus() == false) { // CHECK STATUS
?>
<!-- GUEST CONTENT START -->
<div class="jumbotron">
@ -120,6 +123,41 @@
<?php
} else {
?>
<?php
//on login see if user name fields are set and if not copy from saml when using saml, and then reload
if (Registry::AUTHMETHOD == 'SAML') {
if ($StaticFunctions->getUserSessionStatus() == true) {
if (empty($Users->getUserInitials($uid)[0]["users_lastname"])) {
$Users->updateSAMLName($uid, $attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname'][0], $attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname'][0]);
?>
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="col-sm">
&nbsp;
</div>
<div class="col-sm">
<a class="btn btn-outline-success btn-lg btn-block" tabindex="-1" role="button" aria-disabled="true" href="index.php"><?php echo $transLang['REFRESH']; ?></a>
</div>
<div class="col-sm">
&nbsp;
</div>
</div>
</div>
</div>
<?php
die;
}
}
}
?>
<!-- USER CONTENT START -->
<?php
$post_outtime = filter_input(INPUT_POST, 'outtime');

View File

@ -182,6 +182,20 @@ class Users {
return $count;
}
public function updateSAMLName($uid, $firstname, $lastname) {
$query = "
UPDATE
" . Registry::DB_PRFX . "users
SET
" . Registry::DB_PRFX . "users.firstname = \"$firstname\",
" . Registry::DB_PRFX . "users.lastname = \"$lastname\"
WHERE " . Registry::DB_PRFX . "users.id = \"$uid\"
";
$database = new \App\LobbySIO\Database\Connect();
$count = $database->runQuery($query);
return $count;
}
public function getUserType ($usertypeid){
$query = "
SELECT

View File

@ -220,6 +220,7 @@ if (Registry::AUTHMETHOD == 'INTERNAL') {
};
if (!empty($_POST['editusercomplete'])): // EDIT USER
if (Registry::AUTHMETHOD == 'INTERNAL') {
require_once("src/Misc/PasswordHash.php");
if (empty($_POST['username'])): $errors['username'] = $transLang['USERNAME_NOTEMPTY']; endif;
if (preg_match('/[^a-zA-Z0-9 .-_]/', $_POST['username'])): $errors['username'] = $transLang['ILLEGAL_CHARACTERS']; endif;
@ -234,18 +235,22 @@ if (Registry::AUTHMETHOD == 'INTERNAL') {
// if ($existing[0]["users_username"] == $_POST['username']): $errors['username'] = $transLang['USERNAME_USED']; endif;
// if ($existing[0]["users_email"] == $email): $errors['email'] = $transLang['PASSWORD_USED']; endif;
// endif;
}
endif;
if (!empty($_POST['editusercomplete']) && empty($errors)):
// $hasher = new PasswordHash(8, FALSE);
// $password = $hasher->HashPassword($_POST['password']);
$Users->editUserInfo($_POST['edituserid'], $_POST['firstname'], $_POST['lastname'], $_POST['username'], $_POST['email'], $_POST['usertype']);
if (Registry::AUTHMETHOD == 'INTERNAL') {
$editedusername=$_POST['username'];
} else {
$editedusername="SAML/SSO";
}
$Users->editUserInfo($_POST['edituserid'], $_POST['firstname'], $_POST['lastname'], $editedusername, $_POST['email'], $_POST['usertype']);
//foreach loop to check if exists, if new, delete or add as needed
if (!empty($_POST['sitepermissions'])){
$SiteInfo->delSitePerms($_POST['edituserid']);
foreach($_POST['sitepermissions'] as $editsitepermission) {
$SiteInfo->setSitePerms($editsitepermission, $_POST['edituserid']);
}
}
header('Location: ' . $_SERVER['PHP_SELF']);
endif;
@ -340,9 +345,11 @@ if (0 === $row_count): else: $page_count = (int)ceil($row_count / $StaticFunctio
<div class="modal-body">
<form class="form-inline my-2 my-lg-0" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="row">
<?php if (Registry::AUTHMETHOD == 'INTERNAL') { ?>
<div class="col-sm">
<p class="lead"><?php echo $transLang['ADD_USER_DESC'] . $minpasslength; ?></p>
</div>
<?php } ?>
</div>
<fieldset id="registration">
<div class="form-group">