summaryrefslogtreecommitdiff
path: root/html
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-04-09 04:50:17 +0300
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-04-09 04:50:17 +0300
commita584bf73b6d64dad98f150caba0f25e790cde010 (patch)
tree76c47f080248ebc97f6ae14fdaa364c2f1750b8d /html
parent45d853b343b485bff7e6089e2689dba5f7d901cf (diff)
downloadclassroom-a584bf73b6d64dad98f150caba0f25e790cde010.tar.gz
classroom-a584bf73b6d64dad98f150caba0f25e790cde010.tar.bz2
classroom-a584bf73b6d64dad98f150caba0f25e790cde010.zip
user registration and login scenarios
Diffstat (limited to 'html')
-rw-r--r--html/app/config/app_constants.php20
-rw-r--r--html/app/controllers/Auth.php25
-rw-r--r--html/app/extends/Classroom_user.php1
-rw-r--r--html/app/models/admin/User_model.php12
-rw-r--r--html/app/routes/frontend.php11
-rw-r--r--html/app/views/error/general.php18
-rw-r--r--html/app/views/user/login.php28
7 files changed, 102 insertions, 13 deletions
diff --git a/html/app/config/app_constants.php b/html/app/config/app_constants.php
index 5a2c9b3..0d04dc2 100644
--- a/html/app/config/app_constants.php
+++ b/html/app/config/app_constants.php
@@ -134,17 +134,33 @@ define('FONT_FILES', array(
// Mesagges ////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
+// 404
+// ---
+define('PAGE_404_TITLE', '404: Not Found');
+
+// registration
+// ---
define('REGISTRATION_SUCCESS', "<h3>Επιτυχής Εγγραφή</h3>
<p>
Παρακαλώ ελέγξτε το email σας και ακολουθήστε το σύνδεσμο ενεργοποίησης
που σας 'εχει αποσταλεί, ώστε να έχετε πρόσβαση σε επιπλέον περιεχόμενο του site
</p>"
);
-
define ('REGISTRATION_USER_EXISTS', "<h3>Αποτυχία Εγγραφής</h3>
<p>
Υπάρχει ήδη χρήστης με αυτό το email. Αν δεν θυμάστε το password
μπορείτε να κάνετε επαναφορά του ακολουθώντας
<a href='/reset-password'>αυτό το σύνδεσμο</a>.
</p>"
-); \ No newline at end of file
+);
+
+
+// activation
+// ---
+define('ACCOUNT_ACTIVATED_TITLE', 'Ο λογαριασμός σας έχει ενεργοποιηθεί');
+define('ACCOUNT_ACTIVATED_MESSAGE', 'Τώρα μπορείτε να κάνετε
+ <a href="/login">Είσοδο στο σύστημα</a>
+ για να δείτε περισσότερο περιεχόμενο');
+define('NOT_VALID_ACTIVATION_TITLE', 'Σφάλμα!');
+define('NOT_VALID_ACTIVATION_MESSAGE', 'Ο κωδικός ενεργοποίησης δεν είναι σωστός.
+ Μήπως τον έχετε ενεργοποιήσει στο παρελθόν;'); \ No newline at end of file
diff --git a/html/app/controllers/Auth.php b/html/app/controllers/Auth.php
index 50f8fe4..6555f1c 100644
--- a/html/app/controllers/Auth.php
+++ b/html/app/controllers/Auth.php
@@ -2,6 +2,7 @@
namespace app\controllers;
use Registry;
+use Render;
// user classes and models
use app\extends\Classroom_user;
@@ -56,13 +57,29 @@ class Auth {
}
-
+ /** activate
+ * resolves a call like: /account/activate?ticket=ca42d68cfba5fbbafeacc010b8e3a551
+ */
public static function activate()
{
$req = Registry::get('REQUEST');
// get the record of the target user
- $record = User_model::activate($req->GET['ticket']);
+ $check = User_model::activate($req->GET['ticket']);
+
+ if ($check == true) {
+ Render::view('/error/general', [
+ 'title' => ACCOUNT_ACTIVATED_TITLE,
+ 'message' => ACCOUNT_ACTIVATED_MESSAGE
+ ]);
+
+ } else {
+ Render::view('/error/general', [
+ 'title' => NOT_VALID_ACTIVATION_TITLE,
+ 'message' => NOT_VALID_ACTIVATION_MESSAGE
+ ]);
+ }
+
}
/** register
@@ -118,9 +135,7 @@ class Auth {
'success' => false,
'message' => 'error on sending email'
];
- }
-
-
+ }
}
diff --git a/html/app/extends/Classroom_user.php b/html/app/extends/Classroom_user.php
index fd1e573..c51c79b 100644
--- a/html/app/extends/Classroom_user.php
+++ b/html/app/extends/Classroom_user.php
@@ -37,6 +37,7 @@ class Classroom_user extends User
return $this->privileges;
}
+
/** setPrivileges()
*
* @param array $privileges
diff --git a/html/app/models/admin/User_model.php b/html/app/models/admin/User_model.php
index 187da2d..397f198 100644
--- a/html/app/models/admin/User_model.php
+++ b/html/app/models/admin/User_model.php
@@ -188,6 +188,14 @@ class User_model
}
+ /** activate
+ *
+ * check if activation code is valid;
+ * if valid, set account active;
+ *
+ * @param $ticket (hex/MD5): activation code;
+ *
+ */
public static function activate($ticket)
{
$user = Registry::use('database')->query(
@@ -201,13 +209,13 @@ class User_model
// remove activation code from user record
Registry::use('database')->runQuery(
"UPDATE user
- SET activated = 1, `activation` = NULL
+ SET active = 1, `activation` = NULL
WHERE activation = :ticket",
[ 'ticket' => $ticket ]
);
// update history
- History::trackUserAccess($new_user_id, TRACK_ACCOUNT, 'User Account Activated');
+ History::trackUserAccess($user['id'], TRACK_ACCOUNT, 'User Account Activated');
return true;
diff --git a/html/app/routes/frontend.php b/html/app/routes/frontend.php
index e602e87..ba831d6 100644
--- a/html/app/routes/frontend.php
+++ b/html/app/routes/frontend.php
@@ -44,13 +44,22 @@ Route::add('/registration', function() { Render::view('user/registration'); });
+Route::add('/account/check-login', function() { Auth::login(); });
// user sends a registration form;
-Route::add('/account/register', function() { $x = Auth::register(); print_r($x); }, 'post');
+Route::add('/account/register', function() { Auth::register(); }, 'post');
// user requests activation
Route::add('/account/activate', function() { Auth::activate(); } );
+// user profile
+Route::add('/account/profile', function() {
+ // check if user is activated and loged in
+ // then ...
+ },
+ 'post'
+);
+
Route::add('/account/reset_password', function() { Auth::reset_password(); } );
diff --git a/html/app/views/error/general.php b/html/app/views/error/general.php
index 84cc4d9..257e68d 100644
--- a/html/app/views/error/general.php
+++ b/html/app/views/error/general.php
@@ -1,8 +1,20 @@
-<!DOCTYPE html>
+<?php
+/** general message template
+ *
+ * passed:
+ * @var $title (string): page title
+ * @var $message (string): message
+ */
+?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
- <title>404: Not Found</title>
+ <title>
+ <?= isset($title)
+ ? (SITE_TITLE .": ". $title)
+ : PAGE_404_TITLE
+ ?>
+ </title>
<style>
html,body{
@@ -32,7 +44,7 @@
<body>
<div class='container'>
<div class='content'>
- <h3>Error</h3>
+ <h3><?= isset($title) ? $title : PAGE_404_TITLE ?></h3>
Oops!<br />
<br />
diff --git a/html/app/views/user/login.php b/html/app/views/user/login.php
index 4451d52..dbfb2e5 100644
--- a/html/app/views/user/login.php
+++ b/html/app/views/user/login.php
@@ -60,4 +60,32 @@
</div>
</div>
</body>
+
+<script>
+ // When form is submited
+ // -------------------------------------------------------------------------
+
+ $('.content form').submit( event => {
+ event.preventDefault();
+
+
+ // prepare data to POST
+ var data = {
+ email: $('input[name=email]').val(),
+ password: $('input[name=password]').val()
+ };
+
+ // select action url (add or update)
+ var request = '/account/check-login';
+
+ // send POST request
+ $.post(request, data)
+ .done(function( data ) {
+ console.log(data);
+ });
+
+
+ });
+</script>
+
</html>