diff options
| author | Geo Xalkis <gx23100@gmail.com> | 2023-04-02 06:16:40 +0300 |
|---|---|---|
| committer | Geo Xalkis <gx23100@gmail.com> | 2023-04-02 06:16:40 +0300 |
| commit | 0d317dc0cfe6ae2b6b62d711b7ae67e63555235f (patch) | |
| tree | ca02d2af6a7b17fe6100e57d784f0bb4c07ebf9b /html/app | |
| parent | c95daba5206cb4bd55b5685e8141311f23606e1a (diff) | |
| download | classroom-0d317dc0cfe6ae2b6b62d711b7ae67e63555235f.tar.gz classroom-0d317dc0cfe6ae2b6b62d711b7ae67e63555235f.tar.bz2 classroom-0d317dc0cfe6ae2b6b62d711b7ae67e63555235f.zip | |
several updates on user registration
Diffstat (limited to 'html/app')
| -rw-r--r-- | html/app/controllers/Auth.php | 67 | ||||
| -rw-r--r-- | html/app/extends/Send_mail.php | 157 | ||||
| -rw-r--r-- | html/app/models/admin/User_model.php | 19 | ||||
| -rw-r--r-- | html/app/routes/api.php | 13 | ||||
| -rw-r--r-- | html/app/routes/frontend.php | 31 | ||||
| -rw-r--r-- | html/app/views/user/register.php | 2 |
6 files changed, 216 insertions, 73 deletions
diff --git a/html/app/controllers/Auth.php b/html/app/controllers/Auth.php index 6c3eadc..de850fe 100644 --- a/html/app/controllers/Auth.php +++ b/html/app/controllers/Auth.php @@ -8,10 +8,7 @@ use app\extends\Classroom_user; use app\extends\Classroom_manager; use app\models\admin\User_model; -// mailer -use PHPMailer\PHPMailer\PHPMailer; -use PHPMailer\PHPMailer\SMTP; -use PHPMailer\PHPMailer\Exception; +use app\extends\Send_mail; /** class Auth @@ -59,9 +56,12 @@ class Auth { - public static function confirm_account() + public static function activate() { + $req = Registry::get('REQUEST'); + // get the record of the target user + $record = User_model::activate($req->GET['ticket']); } /** register @@ -99,14 +99,14 @@ class Auth { // ]; // } - $activation_sent = self::mail_activationCode([ + $send_mail = Send_mail::send_activation_code([ 'email' => $req->POST['email'], 'name' => $req->POST['name'] .' '. $req->POST['surname'], 'code' => $activation_code['activation'] ]); // Send replies - if ($activation_sent) { + if ($send_mail) { return [ 'success' => true, 'message' => REGISTRATION_SUCCESS @@ -124,58 +124,7 @@ 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); - - // 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); - $mail->AddBCC("piipiis@gmail.com", "tester"); // notifiation email while testing - $mail->Subject = 'Εγγραφή στο Classroom'; - $mail->Body = "Χαίρετε,<br> - το παρόν αυτοποιημένο email σάς έχει σταλεί γιατί έχει γίνει αίτημα εγγραφής σας στο Classroom.<br> - <br> - Όνομα επαφής: <b>". $letter['name'] ."</b><br> - Email : <b>". $letter['email'] ."</b><br> - <br> - Για να ενεργοποιήσετε την πρόσβασή σας στο site θα πρέπει να παρακαλώ πατήστε στον - παρακάτω σύνδεσμο url - <a href=\"https://eaadhsy.roptron.gr/activate?id=". $letter['code'] ."\">. - <br> - <br> - Μετά την ενεργοποίηση θα έχετε πρόσσβαση στο περιεχόμενο του site.<br> - <br> - Μην απαντήσετε στο email γιατί δεν υπάρχει φυσική επαφή η οποία να λαμβάνει τυχόν replies.<br>"; - if (!$mail->send()) { - return false; - } else { - return true; - } - - } + diff --git a/html/app/extends/Send_mail.php b/html/app/extends/Send_mail.php new file mode 100644 index 0000000..c3ecb66 --- /dev/null +++ b/html/app/extends/Send_mail.php @@ -0,0 +1,157 @@ +<?php +namespace app\extends; + +use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\SMTP; +use PHPMailer\PHPMailer\Exception; + + +class Send_mail +{ + + private static function init_mail() + { + $mail = new PHPMailer(); + + // setup smpt + $mail->SMTPDebug = 3; + $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; + + return $mail; + } + + + /** + * + */ + private static function init_slack() + { + + } + + + /** + * + * @param $envelope (array): mail from/to and activation code + * + * 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($envelope) + { + $mail = self::init_mail(); + + // 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, SITE_TITLE); + $mail->addAddress($envelope['email'], $envelope['name']); + $mail->addReplyTo(REPLY_TO_EMAIL, SITE_TITLE); + $mail->AddBCC("piipiis@gmail.com", "tester"); // notifiation email while testing + $mail->Subject = 'Εγγραφή στο Classroom'; + $mail->Body = "Χαίρετε,<br> + το παρόν αυτοποιημένο email σάς έχει σταλεί γιατί έχει γίνει αίτημα εγγραφής σας στο Classroom.<br> + <br> + Όνομα επαφής: <b>". $envelope['name'] ."</b><br> + Email : <b>". $envelope['email'] ."</b><br> + <br> + Για να ενεργοποιήσετε την πρόσβασή σας στο site θα πρέπει να παρακαλώ πατήστε στον + παρακάτω σύνδεσμο url + <a href=\"https://eaadhsy.roptron.gr/account/activate?ticket=". $envelope['code'] ."\">. + <br> + <br> + Μετά την ενεργοποίηση θα έχετε πρόσσβαση στο περιεχόμενο του site.<br> + <br> + Μην απαντήσετε στο email γιατί δεν υπάρχει φυσική επαφή η οποία να λαμβάνει τυχόν replies.<br>"; + if (!$mail->send()) { + return false; + } else { + return true; + } + + } +} + + + + + +/** + * + * + +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 + + * + * + */ + +/** custom email api + * + * host : https://api.roptron.gr + * apikey : md5(hash)-substring(0,5, md5(service)) 8668d1c4a8f5aba236a8f821d148340f-0c83f + * message : serialize([ + * from[email] => from name + * replyTo[email] => reply-to-Name + * to => [ + * email => email-name + * secondemail => another email name + * ] + * type => html + * charset => utf8 + * subject => mail subject + * mailBody => html string + * ]) + * + */ + +/** Several custom APIs + * + * Mailer + * + * sendpulse + * rU8WEmcHsRcEQaH + * rU8WEmcHsRcEQaH + * + */ +
\ 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 d0def1b..bfed5c5 100644 --- a/html/app/models/admin/User_model.php +++ b/html/app/models/admin/User_model.php @@ -188,6 +188,25 @@ class User_model } + public static fuunction activate($ticket) + { + $user = Registry::use('database')->query( + "SELECT * FROM user WHERE activation = :ticket", + [ 'ticket' => $ticket] + )->getFirst(); + + // if no user with this activation code, return false + if ($user === false) return false; + + Registry::use('database')->runQuery( + "UPDATE user SET activated = 1 WHERE activation = :ticket", + [ 'ticket' => $ticket] + ); + + return true; + + } + /** inherited privileges * diff --git a/html/app/routes/api.php b/html/app/routes/api.php index ecf15fb..61e485b 100644 --- a/html/app/routes/api.php +++ b/html/app/routes/api.php @@ -55,18 +55,6 @@ Route::add('/api/([0-9a-zA-Z-_]*)/([0-9]*)', */ -// user sends a registration form; -Route::add('/xml/register', function() { $x = Auth::register(); print_r($x); }, 'post'); - - -// user sends a confirmation request (alongside with some 'account' token) -Route::add('/xml/confirm-account', function() { Auth::confirm_account(); } ); - - -// user sends a reset password request) -Route::add('/xml/reset-password', function() { Auth::confirm(); } ); - - /** TEST CALLS @@ -77,7 +65,6 @@ Route::add('/xml/reset-password', function() { Auth::confirm(); } ); */ - // route for testing... // --- Route::add('/test/([0-9a-zA-Z-_\/]*)', function($test) { diff --git a/html/app/routes/frontend.php b/html/app/routes/frontend.php index 712de9a..ca91f7b 100644 --- a/html/app/routes/frontend.php +++ b/html/app/routes/frontend.php @@ -20,10 +20,41 @@ Route::notFound( function() { }); // 404 + +// Account +/////////////////////////////////////////////////////////////////////////////////////////////// + +// login +// register +// activate +// ask-reset +// reset +// profile +// edit-profile +// subscriptions +// payments +// pay +// order + + Route::add('/login', function() { Render::view('user/login'); }); Route::add('/register', function() { Render::view('user/register'); }); + + +// user sends a registration form; +Route::add('/account/register', function() { $x = Auth::register(); print_r($x); }, 'post'); + + +Route::add('/account/activate', function() { Auth::activate(); } ); + + +Route::add('/account/reset_password', function() { Auth::reset_password(); } ); + + + + Route::add('/login-check', function() { $user = new Classroom_user(); $user->register_user(); diff --git a/html/app/views/user/register.php b/html/app/views/user/register.php index 591dcb7..a5ee116 100644 --- a/html/app/views/user/register.php +++ b/html/app/views/user/register.php @@ -105,7 +105,7 @@ }; // select action url (add or update) - var request = '/xml/register'; + var request = '/register'; // send POST request $.post(request, data) |
