Skip to content

Commit

Permalink
User Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
sveneld committed Dec 30, 2024
1 parent 29ce802 commit 28d0a73
Show file tree
Hide file tree
Showing 14 changed files with 415 additions and 188 deletions.
31 changes: 0 additions & 31 deletions actions-web.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,6 @@ function trips($userId, $bike = 0)
echo json_encode($jsoncontent); // TODO change to response function
}

function getuserlist()
{
global $db;
$result = $db->query('SELECT users.userId,username,mail,number,privileges,credit,userLimit FROM users LEFT JOIN credit ON users.userId=credit.userId LEFT JOIN limits ON users.userId=limits.userId ORDER BY username');
while ($row = $result->fetch_assoc()) {
$jsoncontent[] = array('userid' => $row['userId'], 'username' => $row['username'], 'mail' => $row['mail'], 'number' => $row['number'], 'privileges' => $row['privileges'], 'credit' => $row['credit'], 'limit' => $row['userLimit']);
}
echo json_encode($jsoncontent); // TODO change to response function
}

function getuserstats()
{
global $db;
Expand All @@ -335,27 +325,6 @@ function getusagestats()
echo json_encode($jsoncontent); // TODO change to response function
}

function edituser($userid)
{
global $db;
$result = $db->query('SELECT users.userId,userName,mail,number,privileges,userLimit,credit FROM users LEFT JOIN limits ON users.userId=limits.userId LEFT JOIN credit ON users.userId=credit.userId WHERE users.userId=' . $userid);
$row = $result->fetch_assoc();
$jsoncontent = array('userid' => $row['userId'], 'username' => $row['userName'], 'email' => $row['mail'], 'phone' => $row['number'], 'privileges' => $row['privileges'], 'limit' => $row['userLimit'], 'credit' => $row['credit']);
echo json_encode($jsoncontent); // TODO change to response function
}

function saveuser($userid, $username, $email, $phone, $privileges, $limit)
{
global $db;
$result = $db->query("UPDATE users SET username='$username',mail='$email',privileges='$privileges' WHERE userId=" . $userid);
if ($phone) {
$result = $db->query("UPDATE users SET number='$phone' WHERE userId=" . $userid);
}

$result = $db->query("UPDATE limits SET userLimit='$limit' WHERE userId=" . $userid);
response(_('Details of user') . ' ' . $username . ' ' . _('updated') . '.');
}

function addcredit($userid, $creditmultiplier)
{
global $db, $user, $creditSystem;
Expand Down
18 changes: 0 additions & 18 deletions command.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@
checkprivileges($userid);
liststands();
break;
case "userlist":
logrequest($userid,$action);
$auth->refreshSession();
checkprivileges($userid);
getuserlist();
break;
case "userstats":
logrequest($userid,$action);
$auth->refreshSession();
Expand All @@ -124,18 +118,6 @@
checkprivileges($userid);
getusagestats();
break;
case "edituser":
logrequest($userid,$action);
$auth->refreshSession();
checkprivileges($userid);
edituser($_GET["edituserid"]);
break;
case "saveuser":
logrequest($userid,$action);
$auth->refreshSession();
checkprivileges($userid);
saveuser($_GET["edituserid"],$_GET["username"],$_GET["email"],$_GET["phone"],$_GET["privileges"],$_GET["limit"]);
break;
case "addcredit":
logrequest($userid,$action);
$auth->refreshSession();
Expand Down
9 changes: 9 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
$routes->add('api_coupon_generate', '/api/coupon/generate')
->methods(['POST'])
->controller([\BikeShare\Controller\Api\CouponController::class, 'generate']);
$routes->add('api_user_index', '/api/user')
->methods(['GET'])
->controller([\BikeShare\Controller\Api\UserController::class, 'index']);
$routes->add('api_user_item', '/api/user/{userId}')
->methods(['GET'])
->controller([\BikeShare\Controller\Api\UserController::class, 'item']);
$routes->add('api_user_item_update', '/api/user/{userId}')
->methods(['PUT'])
->controller([\BikeShare\Controller\Api\UserController::class, 'update']);

$routes->add('personal_stats_year', '/personalStats/year/{year}')
->methods(['GET'])
Expand Down
Loading

0 comments on commit 28d0a73

Please sign in to comment.