summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-28 03:38:35 +0300
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-28 03:38:35 +0300
commit5ce005a4f120c7470cd84c1af306b64c52e3dbfc (patch)
treef93fa229273aad02501d3ecb326091bb2f7d31aa
parentfa7303bc99ed56e6770928d59e16ee3306e26750 (diff)
downloadclassroom-5ce005a4f120c7470cd84c1af306b64c52e3dbfc.tar.gz
classroom-5ce005a4f120c7470cd84c1af306b64c52e3dbfc.tar.bz2
classroom-5ce005a4f120c7470cd84c1af306b64c52e3dbfc.zip
custom user manager extended class (work in progress)
-rw-r--r--composer.json1
-rw-r--r--composer.lock99
-rw-r--r--core/classes/Request.php10
-rw-r--r--docker/config/composer-naked.json1
-rw-r--r--html/app/config/app_constants.php7
-rw-r--r--html/app/controllers/Classroom_user.php69
-rw-r--r--html/app/extends/Classroom_user.php108
-rw-r--r--html/app/models/admin/User_model.php39
-rw-r--r--html/app/views/login.php2
-rw-r--r--tests/userman.php2
10 files changed, 258 insertions, 80 deletions
diff --git a/composer.json b/composer.json
index d4867ea..5cf5df5 100644
--- a/composer.json
+++ b/composer.json
@@ -1,5 +1,6 @@
{
"require": {
+ "phpmailer/phpmailer": "^6.8"
},
"autoload": {
"classmap": [
diff --git a/composer.lock b/composer.lock
new file mode 100644
index 0000000..5810b75
--- /dev/null
+++ b/composer.lock
@@ -0,0 +1,99 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+ "This file is @generated automatically"
+ ],
+ "content-hash": "33cad13092641f81b77ea1ff6e1ca5db",
+ "packages": [
+ {
+ "name": "phpmailer/phpmailer",
+ "version": "v6.8.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/PHPMailer/PHPMailer.git",
+ "reference": "df16b615e371d81fb79e506277faea67a1be18f1"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/df16b615e371d81fb79e506277faea67a1be18f1",
+ "reference": "df16b615e371d81fb79e506277faea67a1be18f1",
+ "shasum": ""
+ },
+ "require": {
+ "ext-ctype": "*",
+ "ext-filter": "*",
+ "ext-hash": "*",
+ "php": ">=5.5.0"
+ },
+ "require-dev": {
+ "dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
+ "doctrine/annotations": "^1.2.6 || ^1.13.3",
+ "php-parallel-lint/php-console-highlighter": "^1.0.0",
+ "php-parallel-lint/php-parallel-lint": "^1.3.2",
+ "phpcompatibility/php-compatibility": "^9.3.5",
+ "roave/security-advisories": "dev-latest",
+ "squizlabs/php_codesniffer": "^3.7.1",
+ "yoast/phpunit-polyfills": "^1.0.4"
+ },
+ "suggest": {
+ "ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses",
+ "ext-openssl": "Needed for secure SMTP sending and DKIM signing",
+ "greew/oauth2-azure-provider": "Needed for Microsoft Azure XOAUTH2 authentication",
+ "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication",
+ "league/oauth2-google": "Needed for Google XOAUTH2 authentication",
+ "psr/log": "For optional PSR-3 debug logging",
+ "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)",
+ "thenetworg/oauth2-azure": "Needed for Microsoft XOAUTH2 authentication"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "PHPMailer\\PHPMailer\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "LGPL-2.1-only"
+ ],
+ "authors": [
+ {
+ "name": "Marcus Bointon",
+ "email": "phpmailer@synchromedia.co.uk"
+ },
+ {
+ "name": "Jim Jagielski",
+ "email": "jimjag@gmail.com"
+ },
+ {
+ "name": "Andy Prevost",
+ "email": "codeworxtech@users.sourceforge.net"
+ },
+ {
+ "name": "Brent R. Matzelle"
+ }
+ ],
+ "description": "PHPMailer is a full-featured email creation and transfer class for PHP",
+ "support": {
+ "issues": "https://github.com/PHPMailer/PHPMailer/issues",
+ "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.8.0"
+ },
+ "funding": [
+ {
+ "url": "https://github.com/Synchro",
+ "type": "github"
+ }
+ ],
+ "time": "2023-03-06T14:43:22+00:00"
+ }
+ ],
+ "packages-dev": [],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": [],
+ "platform-dev": [],
+ "plugin-api-version": "2.3.0"
+}
diff --git a/core/classes/Request.php b/core/classes/Request.php
index cedb8a1..e1148b4 100644
--- a/core/classes/Request.php
+++ b/core/classes/Request.php
@@ -74,6 +74,16 @@ class Request
}
+ /**
+ * Check:
+ *
+ * 1.
+ * https://dev.to/anastasionico/good-practices-how-to-sanitize-validate-and-escape-in-php-3-methods-139b
+ *
+ * 2.
+ * https://benhoyt.com/writings/dont-sanitize-do-escape/
+ *
+ */
private function sanitize($array)
{
// TODO:
diff --git a/docker/config/composer-naked.json b/docker/config/composer-naked.json
index 895e53d..7037711 100644
--- a/docker/config/composer-naked.json
+++ b/docker/config/composer-naked.json
@@ -1,5 +1,6 @@
{
"require": {
+ "phpmailer/phpmailer": "^6.8"
},
"autoload": {
"classmap": [
diff --git a/html/app/config/app_constants.php b/html/app/config/app_constants.php
index c533748..b5fb6d8 100644
--- a/html/app/config/app_constants.php
+++ b/html/app/config/app_constants.php
@@ -37,6 +37,13 @@ define('USER_ACCESS_TYPE', [
+// ERRORS AND ERROR MESSAGES ///////////////////////////////////////////////////
+// -----------------------------------------------------------------------------
+
+define('EMPTY_REQUIRED_FIELDS', 'Δεν έχουν συμπληρωθεί όλα τα υποχρεωτικά πεδία');
+
+
+
// ASSETS: PATHS USED HEAVILY //////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// these paths are used in order to easily find and autoload useful elemets
diff --git a/html/app/controllers/Classroom_user.php b/html/app/controllers/Classroom_user.php
deleted file mode 100644
index 616ebf6..0000000
--- a/html/app/controllers/Classroom_user.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-namespace app\controllers;
-
-use UserManager;
-use Registry;
-# use app\models\admin\User_model;
-
-
-
-/** ClassUserManager
- *
- * extends (anom's) UserManager
- *
- * this way it specializes the UserManagement
- * according to this app's special rules
- *
- */
-class Classroom_user extends UserManager
-{
-
- private $user_identifier = 'email'; // identifing user field (username, email, etc )
-
- protected $user;
-
- public function __construct()
- {
- // $this->user = new UserManager();
-
- }
-
-
- public function register_user()
- {
- $req = Registry::get('REQUEST');
- print_r($req->POST); die();
-
- }
-
-
- public function login_user()
- {
-
- }
-
-
- /** forgot password
- *
- * send an otp
- * (then verify)
- *
- */
- public function forgot_password()
- {
-
- }
-
-
- /** Verify Account
- *
- * check if posted OTP matched the one sent to the user
- *
- */
- public function verify_otp()
- {
-
- }
-
-
-} \ No newline at end of file
diff --git a/html/app/extends/Classroom_user.php b/html/app/extends/Classroom_user.php
new file mode 100644
index 0000000..b451114
--- /dev/null
+++ b/html/app/extends/Classroom_user.php
@@ -0,0 +1,108 @@
+<?php
+namespace app\controllers;
+
+use UserManager;
+use Registry;
+use app\models\admin\User_model;
+
+
+
+/** ClassUserManager
+ *
+ * extends (anom's) UserManager
+ *
+ * this way it specializes the UserManagement
+ * according to this app's special rules
+ *
+ */
+class Classroom_user extends UserManager
+{
+
+ private $index_key = 'email'; // identifing user field (username, email, etc )
+
+ protected $user;
+
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+
+ /** register user
+ *
+ * register into database;
+ * send OTP for account confirmation
+ *
+ * @param (void) : user properties passed via REQUEST->POST
+ *
+ */
+ public function register_user()
+ {
+ $req = Registry::get('REQUEST');
+ $register = User_model::registerUser($req->POST);
+
+ if ($register['success']) {
+
+ //create OTP;
+ $otp = $this->create_OPT($register['id']);
+
+ // send for account confirmation
+
+
+ } else {
+ print_r($register);
+ }
+
+ }
+
+
+ public function login_user()
+ {
+
+ }
+
+
+ /** forgot password
+ *
+ * send an otp
+ * (then verify)
+ *
+ */
+ public function forgot_password()
+ {
+
+ }
+
+
+ /** create OTP
+ *
+ * create a random OTP
+ * keep it into User's database Table
+ *
+ * @param $id (int): user id
+ *
+ */
+ public function create_OTP($id)
+ {
+ $otp = rand(100000,999999);
+ User_model::set_OTP($id, $otp);
+
+ return true;
+ }
+
+
+ /** Verify Account
+ *
+ * check if posted OTP matched the one sent to the user
+ *
+ * @param $identity (array): pair of [index_key => identity_value]
+ * example: [ 'email' => 'geo@roptron.gr' ]
+ *
+ */
+ public function verify_otp($identity, $otp)
+ {
+
+ }
+
+
+} \ No newline at end of file
diff --git a/html/app/models/admin/User_model.php b/html/app/models/admin/User_model.php
index 583d4d9..e4ac2ea 100644
--- a/html/app/models/admin/User_model.php
+++ b/html/app/models/admin/User_model.php
@@ -13,18 +13,18 @@ class User_model
* @param $indexKey (string) : key for user identification
* @param $value (string)
*
- * NOTE:
- * $indexKey MUST BE a unique key identilieng the user
- * ex. username, email, etc ...
- *
- * @return $user : [array] or false
- *
+ * @param $identity (array): pair of [index_key => identity_value]
+ * example: [ 'email' => 'geo@roptron.gr' ]
*/
- public static function checkUser($indexKey, $value)
+ public static function checkUser($identity)
{
+ $indexKey = array_key_first($identity);
+
$user = Registry::use('database')->query(
"SELECT * FROM user WHERE {$indexKey} = :val",
- [ ':val' => $value ]
+ [
+ ':val' => $identity[$indexKey]
+ ]
)->getFirst();
// if no user, return false
@@ -120,10 +120,29 @@ class User_model
/** create user
*
*/
- public static function createUser($data, $privileges = ['ec.1', 'pr.1'])
+ public static function registerUser($data, $privileges = ['ec.1', 'pr.1'])
{
+
+ $required_fields = [
+ 'name',
+ 'surname',
+ 'email',
+ 'password'
+ ];
+
+ // check required fields
+ $isOK = true;
+ foreach($required_fields as $fi) {
+ if (empty($data[$fi])) $isOK = false;
+ }
+ // if empty required fields exists ... return false
+ if (!$isOK) {
+ return [ "success" => false, 'error' => EMPTY_REQUIRED_FIELDS ];
+ }
+
+ // if isOK go on and create user record
$user = [
- 'prefix' => $data['prefix'],
+ 'prefix' => $data['prefix'] ?? '',
'name' => $data['name'],
'surname' => $data['surname'],
'email' => $data['email'],
diff --git a/html/app/views/login.php b/html/app/views/login.php
index cc4556c..e7f9c3e 100644
--- a/html/app/views/login.php
+++ b/html/app/views/login.php
@@ -23,7 +23,7 @@
}
.container { display: flex; height: 100vh; align-items:center; }
.content { position: relative;
- max-width:320px; width: 100%;
+ max-width:640px; width: 100%;
margin: auto auto; padding: 1.5em;
text-align: center; justify-center: center;
opacity: .33;
diff --git a/tests/userman.php b/tests/userman.php
index c08028c..3474a39 100644
--- a/tests/userman.php
+++ b/tests/userman.php
@@ -9,6 +9,8 @@ use app\controllers\Classroom_user as CU;
//
$u = new CU();
+
+
/*
class ClassroomUserManager extends UserManager
{