Skip to content

Commit

Permalink
Merge pull request #59 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored May 10, 2018
2 parents 2350cd6 + f1888af commit 57cdb75
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
6 changes: 3 additions & 3 deletions test/unit/test_userinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testCreateIncorrectPass()
$_SESSION = array("user"=>"admin", "password"=>"admin");
$_GET = array("op"=>"add");
$_POST = array("username"=>"userinfotest", "password"=>"passwordtest",
"password2"=>"password", "user_groups"=>"users", "permissions"=>"0");
"password2"=>"password", "user_groups"=>array("users"), "permissions"=>"0");
include('../../userinfo.php');
$this->assertEquals(array('Location: error.php?msg=The+passwords+are+not+equal.'),xdebug_get_headers());

Expand All @@ -41,7 +41,7 @@ public function testCreate()
$_SESSION = array("user"=>"admin", "password"=>"admin");
$_GET = array("op"=>"add");
$_POST = array("username"=>"userinfotest", "password"=>"passwordtest",
"password2"=>"passwordtest", "user_groups"=>"users", "permissions"=>"0");
"password2"=>"passwordtest", "user_groups"=>array("users"), "permissions"=>"0");
include('../../userinfo.php');
$this->assertEquals(array('Location: user_list.php'),xdebug_get_headers());

Expand All @@ -60,7 +60,7 @@ public function testEdit()
$_SESSION = array("user"=>"admin", "password"=>"admin");
$_GET = array("op"=>"edit");
$_POST = array("id"=>"userinfotest", "username"=>"newuserinfotest", "password"=>"passwordtest",
"password2"=>"passwordtest", "user_groups"=>"users", "permissions"=>"0");
"password2"=>"passwordtest", "user_groups"=>array("users"), "permissions"=>"0");
include('../../userinfo.php');
$this->assertEquals(array('Location: user_list.php'),xdebug_get_headers());

Expand Down
38 changes: 21 additions & 17 deletions user.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,18 @@ function insert_user($username, $password, $groups, $permissions) {

$all_ok = true;
$error_msg = "";
foreach ($groups as $group) {
$fields = array();
$fields[] = "'" . $db->escapeString($group) . "'";
$fields[] = "'" . $db->escapeString($username) . "'";
$res = $db->insert_item_into_table("users_grp",$fields);
if ($res != "") {
$all_ok = false;
$error_msg = $res;
}
if (!is_null($groups)) {
foreach ($groups as $group) {
$fields = array();
$fields[] = "'" . $db->escapeString($group) . "'";
$fields[] = "'" . $db->escapeString($username) . "'";
$res = $db->insert_item_into_table("users_grp",$fields);
if ($res != "") {
$all_ok = false;
$error_msg = $res;
}

}
}
if (!$all_ok) {
$res = "Error adding user groups: " . $error_msg;
Expand Down Expand Up @@ -197,14 +199,16 @@ function edit_user($username, $new_username, $password, $groups, $permissions) {

$all_ok = true;
$error_msg = "";
foreach ($groups as $group) {
$fields = array();
$fields[] = "'" . $db->escapeString($group) . "'";
$fields[] = "'" . $db->escapeString($username) . "'";
$grp_res = $db->insert_item_into_table("users_grp",$fields);
if ($grp_res != "") {
$all_ok = false;
$error_msg = $grp_res;
if (!is_null($groups)) {
foreach ($groups as $group) {
$fields = array();
$fields[] = "'" . $db->escapeString($group) . "'";
$fields[] = "'" . $db->escapeString($username) . "'";
$grp_res = $db->insert_item_into_table("users_grp",$fields);
if ($grp_res != "") {
$all_ok = false;
$error_msg = $grp_res;
}
}
}
if (!$all_ok) {
Expand Down
4 changes: 2 additions & 2 deletions userinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$groups = explode(",", $_POST['user_groups']);
$groups = $_POST['user_groups'];
$permissions = $_POST['permissions'];

$err = "";
Expand All @@ -118,7 +118,7 @@
$new_username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$groups = explode(",", $_POST['user_groups']);
$groups = $_POST['user_groups'];
$permissions = $_POST['permissions'];

$err = "";
Expand Down

0 comments on commit 57cdb75

Please sign in to comment.