summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-31 05:49:40 +0300
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-31 05:49:40 +0300
commitc95daba5206cb4bd55b5685e8141311f23606e1a (patch)
treedcf3ab236cbf60c4d2ffc8af9a520804f504a437
parent4f2d900af7636e6744ae14aeeefdf2d6080ac50a (diff)
downloadclassroom-c95daba5206cb4bd55b5685e8141311f23606e1a.tar.gz
classroom-c95daba5206cb4bd55b5685e8141311f23606e1a.tar.bz2
classroom-c95daba5206cb4bd55b5685e8141311f23606e1a.zip
added advances and secure confifuratin parametres
-rw-r--r--core/auth/env.example36
-rw-r--r--core/config/anom_settings.php16
-rw-r--r--html/app/config/app_constants.php39
-rw-r--r--html/app/controllers/Auth.php26
4 files changed, 100 insertions, 17 deletions
diff --git a/core/auth/env.example b/core/auth/env.example
new file mode 100644
index 0000000..fd47dd8
--- /dev/null
+++ b/core/auth/env.example
@@ -0,0 +1,36 @@
+ENVIRONMENT='development'
+
+# MySQL connection
+# --- -- -- - - -
+DB_NAME=
+DB_USER=
+DB_PASS=
+PDO_HOST=
+
+# mailhog
+# == testting/fake email service
+# --- -- -- - - -
+# MAIL_HOST=mailhog_server
+# MAIL_PORT=1025
+# MAIL_USERNAME=
+# MAIL_PASSWORD=
+# MAIL_ENCRYPTION=
+
+# SMTP setup
+# == read mail server
+# --- -- -- - - -
+MAIL_MAILER=smtp
+MAIL_HOST=
+MAIL_PORT=465
+MAIL_USERNAME=
+MAIL_PASSWORD=
+MAIL_ENCRYPTION=ssl
+NO_REPLY_EMAIL=noreply@...
+REPLY_TO_EMAIL=webmaster@r...
+MAIL_FROM_NAME=Classroom
+
+# redis cache server
+# --- -- -- - - -
+# REDIS_HOST=redis
+# REDIS_PASSWORD=
+# REDIS_PORT=6379 \ No newline at end of file
diff --git a/core/config/anom_settings.php b/core/config/anom_settings.php
index 76c7c62..399c180 100644
--- a/core/config/anom_settings.php
+++ b/core/config/anom_settings.php
@@ -12,7 +12,7 @@
*/
if (file_exists("../core/auth/.env")) {
- $ini_array = parse_ini_file("../core/auth/.env");
+ $ini = parse_ini_file("../core/auth/.env");
}
// DEFINE WHETTHER THE APP RUNS ON PRODUCTION
@@ -30,7 +30,7 @@ if (file_exists("../core/auth/.env")) {
# }
# define by .env file
-define('PRODUCTION', ($ini_array['ENVIRONMENT'] == 'production') );
+define('PRODUCTION', ($ini['ENVIRONMENT'] == 'production') );
@@ -243,15 +243,13 @@ define('CSRF_EXCLUDE_URIS', array()); // Array of URIs which ignore CSRF check
* -----------------------------------------------------------------------------
*/
- $ini_array = parse_ini_file("../core/auth/.env");
-
- define('DB_NAME', $ini_array['DB_NAME']);
+define('DB_NAME', $ini['DB_NAME']);
- define('DB_USER', $ini_array['DB_USER']);
+define('DB_USER', $ini['DB_USER']);
- define('DB_PASS', $ini_array['DB_PASS']);
+define('DB_PASS', $ini['DB_PASS']);
- define('PDO_HOST', $ini_array['PDO_HOST']);
+define('PDO_HOST', $ini['PDO_HOST']);
/** This is just good enough
@@ -286,7 +284,7 @@ define('CSRF_EXCLUDE_URIS', array()); // Array of URIs which ignore CSRF check
#
# }
- define('DB_TIMEZONE', "SET time_zone = 'Europe/Athens'");
+define('DB_TIMEZONE', "SET time_zone = 'Europe/Athens'");
/** NOTE:
* Both Redis and Memcached configurations are given as a template to work on;
diff --git a/html/app/config/app_constants.php b/html/app/config/app_constants.php
index a89cc6a..4ddf7ac 100644
--- a/html/app/config/app_constants.php
+++ b/html/app/config/app_constants.php
@@ -1,11 +1,40 @@
<?php
+// Contents
+// Central Defaults (name)
+// Default Values (user-privileges and user-roles)
+
+
+// read ini file id exist
+// --- -- -- - - -
+if (file_exists("../core/auth/.env")) {
+ $env = parse_ini_file("../core/auth/.env");
+}
+
+
// CENTRAL DEFAULTS ////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
+// NOTE:
+// if .env file exists ... do not touch anything
+// else ... replace $env[*] values with your setup
+
+// WEB-APP name and url
+// --- -- -- - - -
define('SITE_TITLE', 'Classroom');
-define('NO_REPLY_EMAIL', 'noreply@roptron.gr');
-define('REPLY_TO_EMAIL', 'noreply@roptron.gr');
+define('SITE_URL', 'http://localhost');
+
+// email setup
+// --- -- -- - - -
+define('MAIL_MAILER', $env['MAIL_MAILER']);
+define('MAIL_HOST', $env['MAIL_HOST']);
+define('MAIL_PORT', $env['MAIL_PORT']);
+define('MAIL_USERNAME', $env['MAIL_USERNAME']);
+define('MAIL_PASSWORD', $env['MAIL_PASSWORD']);
+define('MAIL_ENCRYPTION', $env['MAIL_ENCRYPTION']);
+define('NO_REPLY_EMAIL', $env['NO_REPLY_EMAIL']);
+define('REPLY_TO_EMAIL', $env['REPLY_TO_EMAIL']);
+
// DEFAULT VALUES //////////////////////////////////////////////////////////////
@@ -13,15 +42,15 @@ define('REPLY_TO_EMAIL', 'noreply@roptron.gr');
// default privileges (for the subscribed user)
// (array of privilege aliases)
-// ---
+// --- -- -- - - -
define('DEFAULT_PRIVILEGES', [
'e.1', // economics, level 1
'p.1' // programming. level 1
]);
-
-
+// User Roles
+// --- -- -- - - -
define('READER', 1);
define('EDITOR', 2);
define('ADMIN', 3);
diff --git a/html/app/controllers/Auth.php b/html/app/controllers/Auth.php
index d0462e2..6c3eadc 100644
--- a/html/app/controllers/Auth.php
+++ b/html/app/controllers/Auth.php
@@ -127,11 +127,29 @@ class Auth {
private static function mail_activationCode($letter)
{
$mail = new PHPMailer();
+
+ // setup smpt
+ $mail->SMTPDebug = 2;
+ $mail->IsSMTP();
+ $mail->Host = MAIL_HOST;
+ $mail->SMPTAuth = true;
+ $mail->SMTPSecure = MAIL_ENCRYPTION;
+ $mail->Protocol = 'mail';
+
+ $mail->Mailer = MAIL_MAILER;
+ $mail->Port = MAIL_PORT;
+ $mail->Username = MAIL_USERNAME;
+ $mail->Password = MAIL_PASSWORD;
+
+ // setup format
$mail->CharSet = 'utf-8';
$mail->IsHTML(true);
- //It's important not to use the submitter's address as the from address as it's forgery,
- //which will cause your messages to fail SPF checks.
- //Use an address in your own domain as the from address, put the submitter's address in a reply-to
+
+ // setup THE mail
+ // --- -- -- - - -
+ // It's important not to use the submitter's address as the from address as it's forgery,
+ // which will cause your messages to fail SPF checks.
+ // Use an address in your own domain as the from address, put the submitter's address in a reply-to
$mail->setFrom(NO_REPLY_EMAIL, SITE_TITLE);
$mail->addAddress($letter['email'], $letter['name']);
$mail->addReplyTo(REPLY_TO_EMAIL, SITE_TITLE);
@@ -277,3 +295,5 @@ class Auth {
}
+// NOTE:
+// check: https://netcorecloud.com/tutorials/send-an-email-via-gmail-smtp-server-using-php/ \ No newline at end of file