From 463139601c046a5201cb8a73473f8fe5c568b760 Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Thu, 27 Apr 2023 20:15:02 +0300 Subject: rearangment completed; now anything is simplel --- public/app/extends/Cache_service.php | 4 +- public/app/extends/Classroom_manager.php | 4 +- public/app/extends/SendMail_service.php | 212 +++++++++++++++++++++++++++++++ public/app/extends/Send_mail.php | 212 ------------------------------- 4 files changed, 216 insertions(+), 216 deletions(-) create mode 100644 public/app/extends/SendMail_service.php delete mode 100644 public/app/extends/Send_mail.php (limited to 'public/app/extends') diff --git a/public/app/extends/Cache_service.php b/public/app/extends/Cache_service.php index e372e1e..c435b75 100644 --- a/public/app/extends/Cache_service.php +++ b/public/app/extends/Cache_service.php @@ -2,7 +2,7 @@ namespace app\extends; use app\models\Cms_model; -use app\models\admin\Privilege_model; +use app\models\Access_model; /** Cache service * ----------------------------------------------------------------------------- @@ -39,7 +39,7 @@ class Cache_service public static function privileges_hierarchy( $options = 0 ) { return proxy( - [\app\models\admin\Privilege_model::class, 'privileges'], + [\app\models\Access_model::class, 'privileges'], [], CACHE_ROOT_TTL, $options ); diff --git a/public/app/extends/Classroom_manager.php b/public/app/extends/Classroom_manager.php index 4d38ba3..ea2e891 100644 --- a/public/app/extends/Classroom_manager.php +++ b/public/app/extends/Classroom_manager.php @@ -37,7 +37,7 @@ class Classroom_manager extends UserManager public function register_user() { $req = Registry::get('REQUEST'); - $register = User_model::registerUser($req->POST); + $register = Access_model::registerUser($req->POST); if ($register['success']) { @@ -83,7 +83,7 @@ class Classroom_manager extends UserManager public function create_OTP($id) { $otp = rand(100000,999999); - User_model::set_OTP($id, $otp); + Access_model::set_OTP($id, $otp); return true; } diff --git a/public/app/extends/SendMail_service.php b/public/app/extends/SendMail_service.php new file mode 100644 index 0000000..c717e61 --- /dev/null +++ b/public/app/extends/SendMail_service.php @@ -0,0 +1,212 @@ + user email + * name => user full name + * subject => subject + * body => email message body + * ] + * + * then send the email; + * + * @param $activator (array): [ + * email => user email, + * name => user full name, + * code => activation code + * ] + * + * @return success_starus (boolean) + * + * TODO: + * check for email templating: + * + https://stackoverflow.com/questions/2391171/how-to-get-output-from-local-script-in-php + * + https://stackoverflow.com/questions/171318/how-do-i-capture-php-output-into-a-variable + */ + public static function send_activation_code($activator) + { + $activation_url = SITE_URL ."/account/activate?ticket=". $activator['code']; + $envelope = [ + 'email' => $activator['email'], + 'name' => $activator['name'], + 'subject' => 'Εγγραφή στο Classroom', + 'body' => "Χαίρετε,
+ το παρόν αυτοποιημένο email σάς έχει σταλεί + γιατί έχει γίνει αίτημα εγγραφής σας στο Classroom.
+
+ Όνομα επαφής: ". $activator['name'] ."
+ Email : ". $activator['email'] ."
+
+ Για να ενεργοποιήσετε την πρόσβασή σας στο site + θα πρέπει ακολουθήσετε τον παρακάτω σύνδεσμο: + ". $activation_url .". +
+
+ Μετά την ενεργοποίηση θα έχετε πρόσσβαση + στο περιεχόμενο του site.
+ Μην απαντήσετε στο email, + δεν υπάρχει φυσική επαφή η οποία να λαμβάνει τυχόν replies." + ]; + + switch (DEFAULT_MAIL_SERVICE) { + case 'mailjet': + $reply = self::send_mailjet($envelope); + break; + + case 'phpMailer': + $reply = self::send_phpMailer($envelope); + break; + } + + return $reply; + + } + + + /** send phpMailer + * + * send email using phpMailer class; + * optional SMTP server configuration; + * + * @param $envelope + * @return success_starus (boolean) + */ + public static function send_phpMailer($envelope) + { + $mail = new PHPMailer(); + + # // setup smpt + $mail->SMTPDebug = 3; + $mail->IsSMTP(); + $mail->Host = MAIL_HOST; + # $mail->SMPTAuth = false; + $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); + + // 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, MAIL_FROM_NAME); + $mail->addAddress($envelope['email'], $envelope['name']); + $mail->addReplyTo(REPLY_TO_EMAIL, MAIL_FROM_NAME); + $mail->Subject = $envelope['subject']; + $mail->Body = $envelope['body']; + + return (!$mail->send()) ? false : true; + + } + + + /** send_mailjet + * + * send email using CURL mail-relay of Mailjet + * + * @param $envelope + * @return success_starus (boolean) + */ + public static function send_mailjet($envelope) + { + $body = [ + 'Messages' => [ + [ + 'From' => [ + 'Email' => REPLY_TO_EMAIL, + 'Name' => MAIL_FROM_NAME + ], + 'To' => [ + [ + 'Email' => $envelope['email'], + 'Name' => $envelope['name'] + ] + ], + 'Subject' => $envelope['subject'], + 'HTMLPart' => $envelope['body'] + ] + ] + ]; + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, "https://api.mailjet.com/v3.1/send"); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json') + ); + curl_setopt( + $ch, + CURLOPT_USERPWD, + MAILJET_APIKEY. ':'. MAILJET_SECRET + ); + $server_output = curl_exec($ch); + curl_close ($ch); + + $response = json_decode($server_output); + + return ($response->Messages[0]->Status == 'success'); + + } + + + +} + + + + + +/** NOTE: + * ----------------------------------------------------------------------------- + * (brainstorming) + * + +Optimization per concept alternative technologies +--- -- -- - - - + +## Session +File Session +Database Session +Redis Session +Memcached Session + +--- + +## Cache +File Cache +Database Cache +Redis Cache +Memcashed Cache + +--- + +## Log +File Log +Database Log +Log event to Slack +Log event to Email + + * ----------------------------------------------------------------------------- + */ diff --git a/public/app/extends/Send_mail.php b/public/app/extends/Send_mail.php deleted file mode 100644 index 52eab53..0000000 --- a/public/app/extends/Send_mail.php +++ /dev/null @@ -1,212 +0,0 @@ - user email - * name => user full name - * subject => subject - * body => email message body - * ] - * - * then send the email; - * - * @param $activator (array): [ - * email => user email, - * name => user full name, - * code => activation code - * ] - * - * @return success_starus (boolean) - * - * TODO: - * check for email templating: - * + https://stackoverflow.com/questions/2391171/how-to-get-output-from-local-script-in-php - * + https://stackoverflow.com/questions/171318/how-do-i-capture-php-output-into-a-variable - */ - public static function send_activation_code($activator) - { - $activation_url = SITE_URL ."/account/activate?ticket=". $activator['code']; - $envelope = [ - 'email' => $activator['email'], - 'name' => $activator['name'], - 'subject' => 'Εγγραφή στο Classroom', - 'body' => "Χαίρετε,
- το παρόν αυτοποιημένο email σάς έχει σταλεί - γιατί έχει γίνει αίτημα εγγραφής σας στο Classroom.
-
- Όνομα επαφής: ". $activator['name'] ."
- Email : ". $activator['email'] ."
-
- Για να ενεργοποιήσετε την πρόσβασή σας στο site - θα πρέπει ακολουθήσετε τον παρακάτω σύνδεσμο: - ". $activation_url .". -
-
- Μετά την ενεργοποίηση θα έχετε πρόσσβαση - στο περιεχόμενο του site.
- Μην απαντήσετε στο email, - δεν υπάρχει φυσική επαφή η οποία να λαμβάνει τυχόν replies." - ]; - - switch (DEFAULT_MAIL_SERVICE) { - case 'mailjet': - $reply = self::send_mailjet($envelope); - break; - - case 'phpMailer': - $reply = self::send_phpMailer($envelope); - break; - } - - return $reply; - - } - - - /** send phpMailer - * - * send email using phpMailer class; - * optional SMTP server configuration; - * - * @param $envelope - * @return success_starus (boolean) - */ - public static function send_phpMailer($envelope) - { - $mail = new PHPMailer(); - - # // setup smpt - $mail->SMTPDebug = 3; - $mail->IsSMTP(); - $mail->Host = MAIL_HOST; - # $mail->SMPTAuth = false; - $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); - - // 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, MAIL_FROM_NAME); - $mail->addAddress($envelope['email'], $envelope['name']); - $mail->addReplyTo(REPLY_TO_EMAIL, MAIL_FROM_NAME); - $mail->Subject = $envelope['subject']; - $mail->Body = $envelope['body']; - - return (!$mail->send()) ? false : true; - - } - - - /** send_mailjet - * - * send email using CURL mail-relay of Mailjet - * - * @param $envelope - * @return success_starus (boolean) - */ - public static function send_mailjet($envelope) - { - $body = [ - 'Messages' => [ - [ - 'From' => [ - 'Email' => REPLY_TO_EMAIL, - 'Name' => MAIL_FROM_NAME - ], - 'To' => [ - [ - 'Email' => $envelope['email'], - 'Name' => $envelope['name'] - ] - ], - 'Subject' => $envelope['subject'], - 'HTMLPart' => $envelope['body'] - ] - ] - ]; - - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, "https://api.mailjet.com/v3.1/send"); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json') - ); - curl_setopt( - $ch, - CURLOPT_USERPWD, - MAILJET_APIKEY. ':'. MAILJET_SECRET - ); - $server_output = curl_exec($ch); - curl_close ($ch); - - $response = json_decode($server_output); - - return ($response->Messages[0]->Status == 'success'); - - } - - - -} - - - - - -/** NOTE: - * ----------------------------------------------------------------------------- - * (brainstorming) - * - -Optimization per concept alternative technologies ---- -- -- - - - - -## Session -File Session -Database Session -Redis Session -Memcached Session - ---- - -## Cache -File Cache -Database Cache -Redis Cache -Memcashed Cache - ---- - -## Log -File Log -Database Log -Log event to Slack -Log event to Email - - * ----------------------------------------------------------------------------- - */ -- cgit v1.2.3