From: LeonardoBizzoni Date: Sun, 29 May 2022 07:23:02 +0000 (+0200) Subject: Mailer and final doc X-Git-Url: http://git.leonardobizzoni.com/?a=commitdiff_plain;h=304a529fb27ed6faec562c40aae6cb582a0e24f3;p=highschool-graduation-project Mailer and final doc --- diff --git a/README.org b/README.org index bd2af73..7e11f61 100644 --- a/README.org +++ b/README.org @@ -12,9 +12,9 @@ Attraverso la web app è possibile visualizzare quali vtuber sono attualmente live e partecipare ad una di esse senza doversi recare sul sito di streaming da loro adottato. Gli utenti registrati possono anche aggiungere una vtuber alla loro lista personale di vtuber preferite e ricevere una notifica via email quando una di esse va in onda. -Un utente può anche richiedere l'aggiunta di una vtuber al catalogo della web app, qualora essa non ne faccia già parte, semplicemente inviando, tramite l'apposito form, l'URL al canale della vtuber, sia esso su [[twitch.tv/][twitch]] o [[youtube.com/][youtube]]. +Un utente può anche richiedere l'aggiunta di una vtuber al catalogo della web app, qualora essa non ne faccia già parte, semplicemente inviando, tramite l'apposito form, l'URL al canale della vtuber, sia esso su [[https://www.twitch.tv/][Twitch]] o [[https://www.youtube.com/][YouTube]]. -** DONE Home page +** Home page Attraverso la pagina "home" è possibile partecipare alla stream di una vtuber direttamente senza recarsi sul sito di streaming da loro utilizzato. Appena si visita quasta pagina vengono visualizzate 2 liste: - *In live*: lista di tutte le vtuber presenti nel catalogo attualmente in onda @@ -25,7 +25,7 @@ Se l'utente è registrato allora viene visualizzata un'ulteriore lista che mostr L'aggiunta di una vtuber viene effettuata tramite l'apposito form visibile agli utenti registrati tramite il tasto "Add vtuber". Una volta cliccato verrà chiesto all'utente l'inserimento dell'URL del canale della vtuber che desidera venga aggiunta al catalogo. -** TODO List page +** List page Attraverso la pagina "list", visibile solo agli utenti registrati, un utente può gestire le sue vtuber preferite. L'utente può quindi: - decidere di rimuovere una vtuber dai suoi preferiti @@ -33,7 +33,8 @@ L'utente può quindi: * Progettazione [[./media/wbs.jpg]] -* DONE Setup + +* Setup ** Configurazione ed installazione server L'architettura a 3 livelli è un'architettura software che organizza il codice in 3 livelli logici: - Presentation layer: interfaccia con l'utente @@ -88,3 +89,4 @@ La tabella *migrations* viene utilizzata per tenere traccia delle migrazioni app Per effettuare una modifica al database si utilizza lo script PHP [[./www/migrationScript.php][migrationScript]], questo prende *in ordine* tutte le *classi migration* presenti nella directory [[./www/Migrations][Migrations]]. Lo script chiama di ogni classe il metodo "*up()*" che applica la modifica al database, crea una nuova entry nella tabella migrations per indicare che la migration in questione è stata applicata. Prima di eseguire il metodo "up()" controlla che la migration non sia già stata applicata cercando una entry che abbia il nome della migration, se lo trova non esegue il metodo "up()" e prosegue con la successiva migration, se non lo trova deve eserguirla ed aggiungere una entry nella tabella. + diff --git a/www/composer.json b/www/composer.json index e3d1d63..3104a49 100644 --- a/www/composer.json +++ b/www/composer.json @@ -13,6 +13,7 @@ }, "require": { "vlucas/phpdotenv": "^5.4", - "google/apiclient": "^2.0" + "google/apiclient": "^2.0", + "phpmailer/phpmailer": "^6.6" } } diff --git a/www/composer.lock b/www/composer.lock index a0da0d5..40ffb34 100644 --- a/www/composer.lock +++ b/www/composer.lock @@ -4,27 +4,32 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3a4a19dac36d14c0ce28853e4186794b", + "content-hash": "ceaaba012ccefab9b7b08812c0e44185", "packages": [ { "name": "firebase/php-jwt", - "version": "v6.1.1", + "version": "v6.2.0", "source": { "type": "git", "url": "https://github.com/firebase/php-jwt.git", - "reference": "e67638d067a537731e3f9c03e097c7c1b1f31fe8" + "reference": "d28e6df83830252650da4623c78aaaf98fb385f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/firebase/php-jwt/zipball/e67638d067a537731e3f9c03e097c7c1b1f31fe8", - "reference": "e67638d067a537731e3f9c03e097c7c1b1f31fe8", + "url": "https://api.github.com/repos/firebase/php-jwt/zipball/d28e6df83830252650da4623c78aaaf98fb385f3", + "reference": "d28e6df83830252650da4623c78aaaf98fb385f3", "shasum": "" }, "require": { "php": "^7.1||^8.0" }, "require-dev": { - "phpunit/phpunit": "^7.5||9.5" + "guzzlehttp/guzzle": "^6.5||^7.4", + "phpspec/prophecy-phpunit": "^1.1", + "phpunit/phpunit": "^7.5||^9.5", + "psr/cache": "^1.0||^2.0", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0" }, "suggest": { "paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present" @@ -59,22 +64,22 @@ ], "support": { "issues": "https://github.com/firebase/php-jwt/issues", - "source": "https://github.com/firebase/php-jwt/tree/v6.1.1" + "source": "https://github.com/firebase/php-jwt/tree/v6.2.0" }, - "time": "2022-04-13T23:27:14+00:00" + "time": "2022-05-13T20:54:50+00:00" }, { "name": "google/apiclient", - "version": "v2.12.3", + "version": "v2.12.4", "source": { "type": "git", "url": "https://github.com/googleapis/google-api-php-client.git", - "reference": "506c488cb22c960022adf515bf0acc1d266e81db" + "reference": "702eed9ae7022ba20dc7118c8161060cb50ee9f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/googleapis/google-api-php-client/zipball/506c488cb22c960022adf515bf0acc1d266e81db", - "reference": "506c488cb22c960022adf515bf0acc1d266e81db", + "url": "https://api.github.com/repos/googleapis/google-api-php-client/zipball/702eed9ae7022ba20dc7118c8161060cb50ee9f8", + "reference": "702eed9ae7022ba20dc7118c8161060cb50ee9f8", "shasum": "" }, "require": { @@ -130,22 +135,22 @@ ], "support": { "issues": "https://github.com/googleapis/google-api-php-client/issues", - "source": "https://github.com/googleapis/google-api-php-client/tree/v2.12.3" + "source": "https://github.com/googleapis/google-api-php-client/tree/v2.12.4" }, - "time": "2022-04-18T16:01:04+00:00" + "time": "2022-04-20T16:44:03+00:00" }, { "name": "google/apiclient-services", - "version": "v0.244.0", + "version": "v0.250.0", "source": { "type": "git", "url": "https://github.com/googleapis/google-api-php-client-services.git", - "reference": "e938c389a3e89bf7a9147b897b9e8bb2ae7bceba" + "reference": "3db4c0db2a5452e623b54f06dd993c432e6d6f8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/e938c389a3e89bf7a9147b897b9e8bb2ae7bceba", - "reference": "e938c389a3e89bf7a9147b897b9e8bb2ae7bceba", + "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/3db4c0db2a5452e623b54f06dd993c432e6d6f8c", + "reference": "3db4c0db2a5452e623b54f06dd993c432e6d6f8c", "shasum": "" }, "require": { @@ -174,9 +179,9 @@ ], "support": { "issues": "https://github.com/googleapis/google-api-php-client-services/issues", - "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.244.0" + "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.250.0" }, - "time": "2022-04-18T00:58:38+00:00" + "time": "2022-05-22T01:16:11+00:00" }, { "name": "google/auth", @@ -300,16 +305,16 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.4.2", + "version": "7.4.3", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "ac1ec1cd9b5624694c3a40be801d94137afb12b4" + "reference": "74a8602c6faec9ef74b7a9391ac82c5e65b1cdab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ac1ec1cd9b5624694c3a40be801d94137afb12b4", - "reference": "ac1ec1cd9b5624694c3a40be801d94137afb12b4", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/74a8602c6faec9ef74b7a9391ac82c5e65b1cdab", + "reference": "74a8602c6faec9ef74b7a9391ac82c5e65b1cdab", "shasum": "" }, "require": { @@ -404,7 +409,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.4.2" + "source": "https://github.com/guzzle/guzzle/tree/7.4.3" }, "funding": [ { @@ -420,7 +425,7 @@ "type": "tidelift" } ], - "time": "2022-03-20T14:16:28+00:00" + "time": "2022-05-25T13:24:33+00:00" }, { "name": "guzzlehttp/promises", @@ -623,16 +628,16 @@ }, { "name": "monolog/monolog", - "version": "2.5.0", + "version": "2.6.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "4192345e260f1d51b365536199744b987e160edc" + "reference": "247918972acd74356b0a91dfaa5adcaec069b6c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/4192345e260f1d51b365536199744b987e160edc", - "reference": "4192345e260f1d51b365536199744b987e160edc", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/247918972acd74356b0a91dfaa5adcaec069b6c0", + "reference": "247918972acd74356b0a91dfaa5adcaec069b6c0", "shasum": "" }, "require": { @@ -645,18 +650,23 @@ "require-dev": { "aws/aws-sdk-php": "^2.4.9 || ^3.0", "doctrine/couchdb": "~1.0@dev", - "elasticsearch/elasticsearch": "^7", + "elasticsearch/elasticsearch": "^7 || ^8", + "ext-json": "*", "graylog2/gelf-php": "^1.4.2", + "guzzlehttp/guzzle": "^7.4", + "guzzlehttp/psr7": "^2.2", "mongodb/mongodb": "^1.8", "php-amqplib/php-amqplib": "~2.4 || ^3", "php-console/php-console": "^3.1.3", - "phpspec/prophecy": "^1.6.1", + "phpspec/prophecy": "^1.15", "phpstan/phpstan": "^0.12.91", - "phpunit/phpunit": "^8.5", + "phpunit/phpunit": "^8.5.14", "predis/predis": "^1.1", "rollbar/rollbar": "^1.3 || ^2 || ^3", - "ruflin/elastica": ">=0.90@dev", - "swiftmailer/swiftmailer": "^5.3|^6.0" + "ruflin/elastica": "^7", + "swiftmailer/swiftmailer": "^5.3|^6.0", + "symfony/mailer": "^5.4 || ^6", + "symfony/mime": "^5.4 || ^6" }, "suggest": { "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", @@ -706,7 +716,7 @@ ], "support": { "issues": "https://github.com/Seldaek/monolog/issues", - "source": "https://github.com/Seldaek/monolog/tree/2.5.0" + "source": "https://github.com/Seldaek/monolog/tree/2.6.0" }, "funding": [ { @@ -718,7 +728,7 @@ "type": "tidelift" } ], - "time": "2022-04-08T15:43:54+00:00" + "time": "2022-05-10T09:36:00+00:00" }, { "name": "paragonie/constant_time_encoding", @@ -837,6 +847,84 @@ }, "time": "2020-10-15T08:29:30+00:00" }, + { + "name": "phpmailer/phpmailer", + "version": "v6.6.0", + "source": { + "type": "git", + "url": "https://github.com/PHPMailer/PHPMailer.git", + "reference": "e43bac82edc26ca04b36143a48bde1c051cfd5b1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/e43bac82edc26ca04b36143a48bde1c051cfd5b1", + "reference": "e43bac82edc26ca04b36143a48bde1c051cfd5b1", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-filter": "*", + "ext-hash": "*", + "php": ">=5.5.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", + "doctrine/annotations": "^1.2", + "php-parallel-lint/php-console-highlighter": "^0.5.0", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.3.5", + "roave/security-advisories": "dev-latest", + "squizlabs/php_codesniffer": "^3.6.2", + "yoast/phpunit-polyfills": "^1.0.0" + }, + "suggest": { + "ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses", + "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication", + "league/oauth2-google": "Needed for Google XOAUTH2 authentication", + "psr/log": "For optional PSR-3 debug logging", + "stevenmaguire/oauth2-microsoft": "Needed for Microsoft XOAUTH2 authentication", + "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)" + }, + "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.6.0" + }, + "funding": [ + { + "url": "https://github.com/Synchro", + "type": "github" + } + ], + "time": "2022-02-28T15:31:21+00:00" + }, { "name": "phpoption/phpoption", "version": "1.8.1", @@ -1322,25 +1410,25 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.0.1", + "version": "v3.1.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c" + "reference": "07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", - "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918", + "reference": "07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918", "shasum": "" }, "require": { - "php": ">=8.0.2" + "php": ">=8.1" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "3.0-dev" + "dev-main": "3.1-dev" }, "thanks": { "name": "symfony/contracts", @@ -1369,7 +1457,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.1" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.1.0" }, "funding": [ { @@ -1385,7 +1473,7 @@ "type": "tidelift" } ], - "time": "2022-01-02T09:55:41+00:00" + "time": "2022-02-25T11:15:52+00:00" }, { "name": "symfony/polyfill-ctype", diff --git a/www/controllers/SiteController.php b/www/controllers/SiteController.php index 05226be..8a0c709 100644 --- a/www/controllers/SiteController.php +++ b/www/controllers/SiteController.php @@ -33,6 +33,7 @@ class SiteController extends BaseController public function live(Request $req) { $vtuberLive = []; + $favorites = []; $singleVtuber = false; $vtuberModel = new Vtubers; diff --git a/www/mailer.php b/www/mailer.php new file mode 100644 index 0000000..8a20ff2 --- /dev/null +++ b/www/mailer.php @@ -0,0 +1,60 @@ +load(); + +$config = [ + "db" => [ + "dsn" => $_ENV["DB_DSN"], + "user" => $_ENV["DB_USER"], + "password" => $_ENV["DB_PASSWORD"] + ], + "mail" => [ + "username" => $_ENV["MAIL_USERNAME"], + "pass" => $_ENV["MAIL_PASSWORD"], + ], + "userClass" => null +]; + +$app = new Application(__DIR__, $config); + +$stmt = $app->db->pdo->prepare(" +select email, vtubers.username, vtubers.id, notify +from users, vtubers, favoriteVtuber +where _vtuberID=vtubers.id +and _userID=users.id +and notify=1"); + +$stmt->execute(); +$data = $stmt->fetchAll(); + + +foreach ($data as $row) { + // var_dump($row); + $mail = new PHPMailer; + $mail->IsSMTP(); // telling the class to use SMTP + $mail->SMTPAuth = true; + $mail->SMTPSecure = "ssl"; + $mail->Host = "smtp.gmail.com"; + $mail->Port = "465"; + + $mail->Username = Application::$app->config["mail"]["username"]; + $mail->Password = Application::$app->config["mail"]["pass"]; + + $mail->SetFrom($mail->Username); + + $mail->Subject = $row["username"] . " is live!"; + $mail->Body = " "; + + $mail->AddAddress($row["email"]); + + if (!$mail->Send()) { + echo "Mailer Error: " . $mail->ErrorInfo . "\n"; + } else { + echo "Message sent!\n"; + } +}