summaryrefslogtreecommitdiff
path: root/public/app/routes/user.php
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-06-12 01:12:30 +0300
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-06-12 01:12:30 +0300
commit5375e22de976b74f5f04d800014c30d9c66f0fe5 (patch)
tree3f9d79b898c4bbb392c2a4ec5ec65c0fde5c6f01 /public/app/routes/user.php
parent0b0076b2ece062f248b7c048d6bb28abbe9174a5 (diff)
downloadgyraf1gov-5375e22de976b74f5f04d800014c30d9c66f0fe5.tar.gz
gyraf1gov-5375e22de976b74f5f04d800014c30d9c66f0fe5.tar.bz2
gyraf1gov-5375e22de976b74f5f04d800014c30d9c66f0fe5.zip
official Reliese Candidate; themes added; routes organized; fine tuning
Diffstat (limited to 'public/app/routes/user.php')
-rw-r--r--public/app/routes/user.php114
1 files changed, 55 insertions, 59 deletions
diff --git a/public/app/routes/user.php b/public/app/routes/user.php
index 622dc57..63e4e07 100644
--- a/public/app/routes/user.php
+++ b/public/app/routes/user.php
@@ -1,8 +1,9 @@
<?php
use app\controllers\Auth;
-use app\controllers\Classroom_user;
use app\controllers\Office;
+use app\models\Content_model;
+use app\models\Access_model;
/** User Connection Management Routes
@@ -12,14 +13,6 @@ use app\controllers\Office;
// common requests (GET method)
// --- -- -- - - -
-// request login ... -> then sends to POST:/account/check-login
-Route::add('/login', function() {
- if (Auth::is_connected()) { header('Location: /panel');
- } else {
- Render::view('user/login');
- }
-});
-
// request logout
Route::add('/logout', function() {
Auth::logout();
@@ -27,53 +20,20 @@ Route::add('/logout', function() {
});
-// TODO:
-// // request password reset
-// Route::add('/account/reset_password', function() { Auth::reset_password(); } );
-
-
-// Replies to common requests (POST method)
-// --- -- -- - - -
-
-// user sends login form
-Route::add('/account/check-login', function() {
- $response = Auth::login();
- Render::json(['status' => $response]);
- },
- 'post'
-);
-
-
-
-/* DEPRICATED:
- // Account Management
- ////////////////////////////////////////////////////////////////////////////////
-
- // user profile
- Route::add('/account/profile', function() {
- $user = Auth::is_connected();
- if ($user === false) {
- Render::view('error/general',
- [
- 'title' => 'Nope!',
- 'message' => "<h2>No profile</h2>User is not connected"
- ]
- );
-
- } else {
- Render::json(['success' => true, 'status' => 'user is connected']);
- }
- }
- );
---- */
-
// routes for connected users
////////////////////////////////////////////////////////////////////////////////
if (Auth::is_connected()) {
- // serve content
+ // login while authenticated ... -> redirect to panel
+ Route::add('/login', function() { header('Location: /panel'); });
+
+ // set invitation while authenticated ... -> redirect to panel
+ Route::add('/invitation/([0-9a-f]*)', function($id) { header('Location: /panel'); });
+
+
+ // SERVE content
// -------------------------------------------------------------------------
// control panel
@@ -159,7 +119,6 @@ if (Auth::is_connected()) {
Office::add_petition();
}, 'post');
-
}
@@ -176,9 +135,27 @@ if (Auth::in_admin_group()) {
});
- // GET JSON: request RESULTS list my petitions
+ // GET HTML: administer users (page)
+ // --- -- -- - - -
+ Route::add('/admin/users', function() {
+ Render::view('templates/admin_users');
+ });
+
+
+ // GET JSON: request RESULTS list all petitions
Route::add('/admin/get/petitions', function() {
- Office::all_petitions();
+ Render::json([
+ 'success' => true,
+ 'data' => Content_model::all_petitions()
+ ]);
+ });
+
+
+ // GET JSON: request RESULTS list all petitions
+ Route::add('/admin/get/users', function() {
+ Render::json( Registry::use('database')->runQuery(
+ "SELECT * FROM user ORDER BY last_name, first_name", []
+ ));
});
@@ -188,22 +165,42 @@ if (Auth::in_admin_group()) {
}, 'post');
+ // GET AJAX: activate user (with user-id)
+ Route::add('/admin/user/activate/([0-9]*)', function( $uid ) {
+ Render::json([ 'success' => Access_model::activate_user($uid) ]);
+ // TODO: Cache_service::update_teachers();
+ });
+
+
+ // GET AJAX: depricate user (with user-id)
+ Route::add('/admin/user/deprecate/([0-9]*)', function( $uid ) {
+ Render::json([ 'success' => Access_model::deprecate_user($uid) ]);
+ // TODO: Cache_service::update_teachers();
+ });
+
+
// invite user(s)
// --- -- -- - - -
Route::add('/admin/invite', function() {
$teachers = Registry::use('database')->runQuery(
"SELECT id, concat(last_name, ' ', first_name) as TeacherName
- FROM user ORDER BY TeacherName
- WHERE otp_expiration < :now OR otp_expiration IS NULL",
+ FROM user
+ WHERE (
+ otp_expiration < :now OR otp_expiration IS NULL
+ ) AND deprecated IS NULL
+ ORDER BY TeacherName",
[ ':now' => time() ]
);
Render::view('templates/invite', ['teachers' => $teachers]);
});
+
// POST AJAX: set petition protocol
+ // --- -- -- - - -
Route::add('/admin/send/invitation', function() {
Office::send_invitation();
}, 'post');
+
}
@@ -214,9 +211,8 @@ if (Auth::in_admin_group()) {
// test connection
if (!PRODUCTION) {
- Route::add('/check/connection', function() { Auth::is_connected(); });
+ Route::add('/check/connection', function() {
+ Render::json( Auth::is_connected() );
+ });
}
-
-
-