diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-03-30 05:03:23 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-03-30 05:03:23 +0300 |
| commit | 4f2d900af7636e6744ae14aeeefdf2d6080ac50a (patch) | |
| tree | 1f80775437510591656e6ef13375516226ed27f3 /html/app/controllers/Auth.php | |
| parent | a16d070c4f8301a8b68220aca6d3573705be9025 (diff) | |
| download | classroom-4f2d900af7636e6744ae14aeeefdf2d6080ac50a.tar.gz classroom-4f2d900af7636e6744ae14aeeefdf2d6080ac50a.tar.bz2 classroom-4f2d900af7636e6744ae14aeeefdf2d6080ac50a.zip | |
several mail options tested; mailhog (fake) mailer is working
Diffstat (limited to 'html/app/controllers/Auth.php')
| -rw-r--r-- | html/app/controllers/Auth.php | 105 |
1 files changed, 94 insertions, 11 deletions
diff --git a/html/app/controllers/Auth.php b/html/app/controllers/Auth.php index c75f979..d0462e2 100644 --- a/html/app/controllers/Auth.php +++ b/html/app/controllers/Auth.php @@ -1,11 +1,17 @@ <?php - namespace app\controllers; use Registry; -use UserManager; -use User; -use app\models\user\User_model; + +// user classes and models +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; /** class Auth @@ -52,28 +58,105 @@ class Auth { } + + public static function confirm_account() + { + + } + /** register * - * registers new user + * Method for new user registration * */ public static function register() { - $userManager = new UserManager(); + $userManager = new Classroom_manager(); $req = Registry::get('REQUEST'); // create a salted password hash $password = $userManager->cryptPassword($req->POST['password']); + + // echo $password; print_r($req->POST); die(); // OK! - $user = (new User()) - ->setUserName($req->POST['username']) + $user = (new Classroom_user()) + ->setUserName($req->POST['email']) ->setPassword($password) - ->setRoles(['ROLE_USER']); + ->setRoles([ READER ]) // Role: authorized reader + ->setPrivileges([]); // none privilege until acount confirmation + + // create user record + $activation_code = User_model::registerUser($req->POST, $password); // TODO: - // store user to database + // handle error on user registration + // ... + // + // if ($activatopn_code[] == -1) { + // return [ + // 'success' => false, + // 'message' => REGISTRATION_USER_EXISTS + // ]; + // } + + $activation_sent = self::mail_activationCode([ + 'email' => $req->POST['email'], + 'name' => $req->POST['name'] .' '. $req->POST['surname'], + 'code' => $activation_code['activation'] + ]); + + // Send replies + if ($activation_sent) { + return [ + 'success' => true, + 'message' => REGISTRATION_SUCCESS + ]; - $userManager->createUserToken($user); + } else { + return [ + 'success' => false, + 'message' => 'error on sending email' + ]; + } + + + + } + + + private static function mail_activationCode($letter) + { + $mail = new PHPMailer(); + $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 + $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; + } + } |
