Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Controller #214

Merged
merged 4 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 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,40 +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;

$minRequiredCredit = $creditSystem->getMinRequiredCredit();
$addcreditamount = $minRequiredCredit * $creditmultiplier;
$result = $db->query('UPDATE credit SET credit=credit+' . $addcreditamount . ' WHERE userId=' . $userid);
$result = $db->query("INSERT INTO history SET userId=$userid,bikeNum=0,action='CREDITCHANGE',parameter='" . $addcreditamount . '|add+' . $addcreditamount . "'");
$userName = $user->findUserName($userid);

response(_('Added') . ' ' . $addcreditamount . $creditSystem->getCreditCurrency() . ' ' . _('credit for') . ' ' . $userName . '.');
}

function validatecoupon($userid, $coupon)
{
global $db, $creditSystem;
Expand Down
24 changes: 0 additions & 24 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,24 +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();
checkprivileges($userid);
addcredit($_GET["edituserid"],$_GET["creditmultiplier"]);
break;
case "trips":
logrequest($userid,$action);
$auth->refreshSession();
Expand Down
12 changes: 12 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@
$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('api_credit_add', '/api/credit')
->methods(['PUT'])
->controller([\BikeShare\Controller\Api\CreditController::class, 'add']);

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