diff --git a/composer.json b/composer.json index 64f175e073e7c5f084360f238dbab212f9e7e9c5..a6ea8116dbfba95ae83009f9bc6295fdab6c4848 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "unl/php-wdn-templates": "^4.1", "unl/unl_cache_lite": "0.1.*", "php-activerecord/php-activerecord": "^1.1", - "altorouter/altorouter": "1.1.0" + "altorouter/altorouter": "1.1.0", + "phpmailer/phpmailer": "^5.2" }, "repositories": [ { diff --git a/composer.lock b/composer.lock index 27e683d8e050699ad7a90d1d352432c00f295684..068cdd40444492f166578c842a93069d530b7c8f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "76bd1e54c765a6b01a21c2ef0afcbefd", + "hash": "c78edb53b57d623af394537be259da40", "packages": [ { "name": "altorouter/altorouter", @@ -362,6 +362,66 @@ ], "time": "2013-04-26 21:01:08" }, + { + "name": "phpmailer/phpmailer", + "version": "v5.2.16", + "source": { + "type": "git", + "url": "https://github.com/PHPMailer/PHPMailer.git", + "reference": "1d85f9ef3ecfc42bbc4f3c70d5e37ca9a65f629a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/1d85f9ef3ecfc42bbc4f3c70d5e37ca9a65f629a", + "reference": "1d85f9ef3ecfc42bbc4f3c70d5e37ca9a65f629a", + "shasum": "" + }, + "require": { + "php": ">=5.0.0" + }, + "require-dev": { + "phpdocumentor/phpdocumentor": "*", + "phpunit/phpunit": "4.7.*" + }, + "suggest": { + "league/oauth2-google": "Needed for Google XOAUTH2 authentication" + }, + "type": "library", + "autoload": { + "classmap": [ + "class.phpmailer.php", + "class.phpmaileroauth.php", + "class.phpmaileroauthgoogle.php", + "class.smtp.php", + "class.pop3.php", + "extras/EasyPeasyICS.php", + "extras/ntlm_sasl_client.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "Jim Jagielski", + "email": "jimjag@gmail.com" + }, + { + "name": "Marcus Bointon", + "email": "phpmailer@synchromedia.co.uk" + }, + { + "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", + "time": "2016-06-06 09:09:37" + }, { "name": "tedivm/stash", "version": "v0.12.3", diff --git a/config.sample.php b/config.sample.php index ee963e24865fd5496aada6509ea438815b10d5a5..2072e744f9f889587f24ecfd536a44625b0c7ce3 100644 --- a/config.sample.php +++ b/config.sample.php @@ -1,5 +1,7 @@ <?php +global $ENV = 'production'; + # standard autoloader function autoload($class) { @@ -26,4 +28,5 @@ ActiveRecord\Config::initialize(function ($cfg) { $cfg->set_connections(array( 'development' => 'mysql://root:admin@localhost/lockups' )); -}); \ No newline at end of file +}); + diff --git a/db/2016-07-11-add-email-to-users.sql b/db/2016-07-11-add-email-to-users.sql new file mode 100644 index 0000000000000000000000000000000000000000..6dd6296b2653f2b73572d4c68e432117422fa2bf --- /dev/null +++ b/db/2016-07-11-add-email-to-users.sql @@ -0,0 +1 @@ +ALTER TABLE users ADD COLUMN `email` varchar(255) DEFAULT NULL; \ No newline at end of file diff --git a/src/Auth.php b/src/Auth.php index 061edb297622af60b8abf65e34f5f9b6662abb7c..5cead64960e3dfb59d35b6103f2702d5f074406d 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -83,16 +83,56 @@ class Auth $user = User::find(array('username' => $username)); if ($user) { # they exist, no worries + # if they don't have an email, they were created before we had emails in teh system + if (empty($user->email)) { + $info = self::getUserInfo($username); + $user->email = $info['email']; + $user->save(); + } } else { + $info = self::getUserInfo($username); # Create a new user $user = User::create(array( 'username' => $username, - 'date_created' => date('Y-m-d H:i:s') + 'date_created' => date('Y-m-d H:i:s'), + 'email' => $info['email'] )); } return $user; } + + /** + * Get a user's information from directory.unl.edu + * + * @param string $uid + * @return array + */ + public static function getUserInfo($uid) { + $info = array(); + + if (!$json = @file_get_contents(self::$directory_url . '?uid=' . $uid . '&format=json')) { + return $info; + } + + if (!$json = json_decode($json, true)) { + return $info; + } + + $map = array( + 'givenName' => 'first_name', + 'sn' => 'last_name', + 'mail' => 'email' + ); + + foreach ($map as $from => $to) { + if (isset($json[$from][0])) { + $info[$to] = $json[$from][0]; + } + } + + return $info; + } /** * Set up the SimpleCAS client diff --git a/src/Controllers/LockupsController.php b/src/Controllers/LockupsController.php index 90f7124ee1fe49018ccdc9ebcb89ee565f308c38..e5ee4e81370a35ff297461f33cf0aa5643354360 100644 --- a/src/Controllers/LockupsController.php +++ b/src/Controllers/LockupsController.php @@ -3,6 +3,7 @@ namespace Controllers; use Models\Lockup; use Models\LockupFile; use Models\User; +use \Emailer as Emailer; use \SvgGenerator as SVG; class LockupsController extends Controller { @@ -233,6 +234,25 @@ class LockupsController extends Controller { } $lockup->save(); + # send an email + if ($lockup->status == Lockup::APPROVED && $lockup->creative_status == Lockup::APPROVED) { + $body = ' +Your lockup, ' . $lockup->getName() . ', has been approved and is ready to generate. +Please visit <a href="' . $lockup->getPreviewURL() . '">' . $lockup->getPreviewURL() . '</a> to generate its files. + +CREATIVE FEEDBACK: +' . $lockup->creative_feedback . ' + +COMMUNICATOR FEEDBACK: +' . $lockup->communicator_feedback . ' + +If you can’t see your lockups or if there are issues with any versions, please contact Marcelo Plioplis at 2-7524 or mplioplis2@unl.edu or Tyler Lemburg at 2-7031 or lemburg@unl.edu + +UNL Lockup Factory'; + + Emailer::sendMail($lockup->user->email, "Lockup Approved", $body); + } + \Core::redirect($lockup->getPreviewURL()); } @@ -272,6 +292,23 @@ class LockupsController extends Controller { } $lockup->save(); + # send an email + $body = ' +Feedback has been left on your lockup, ' . $lockup->getName() . '. +Please visit <a href="' . $lockup->getPreviewURL() . '">' . $lockup->getPreviewURL() . '</a> to view your lockup, and edit it if necessary. + +CREATIVE FEEDBACK: +' . $lockup->creative_feedback . ' + +COMMUNICATOR FEEDBACK: +' . $lockup->communicator_feedback . ' + +If you can’t see your lockups or if there are issues with any versions, please contact Marcelo Plioplis at 2-7524 or mplioplis2@unl.edu or Tyler Lemburg at 2-7031 or lemburg@unl.edu + +UNL Lockup Factory'; + + Emailer::sendMail($lockup->user->email, "Lockup Feedback Given", $body); + \Core::redirect($lockup->getPreviewURL()); } @@ -303,6 +340,23 @@ class LockupsController extends Controller { } $lockup->save(); + # send an email + $body = ' +Your lockup, ' . $lockup->getName() . ', has been denied. +Please visit <a href="' . $lockup->getPreviewURL() . '">' . $lockup->getPreviewURL() . '</a> to view your lockup, and edit it if necessary. + +CREATIVE FEEDBACK: +' . $lockup->creative_feedback . ' + +COMMUNICATOR FEEDBACK: +' . $lockup->communicator_feedback . ' + +If you can’t see your lockups or if there are issues with any versions, please contact Marcelo Plioplis at 2-7524 or mplioplis2@unl.edu or Tyler Lemburg at 2-7031 or lemburg@unl.edu + +UNL Lockup Factory'; + + Emailer::sendMail($lockup->user->email, "Lockup Feedback Given", $body); + \Core::redirect($lockup->getPreviewURL()); } diff --git a/src/Emailer.php b/src/Emailer.php new file mode 100644 index 0000000000000000000000000000000000000000..7f2675c44461a0f1e2eaf7fc4b258b29230da639 --- /dev/null +++ b/src/Emailer.php @@ -0,0 +1,42 @@ +<?php +//require 'PHPMailerAutoload.php'; + +class Emailer { + static $mailer; + + private static function initializeMailer() { + global $ENV; + if ($ENV == 'production') { + self::$mailer = new PHPMailer; + self::$mailer->isSendmail(); + } else { + self::$mailer = new PHPMailer; + self::$mailer->Host = 'smtp://127.0.0.1:1025'; + self::$mailer->SMTPAuth = false; + } + } + + + public static function sendMail($to, $subject, $body) { + self::initializeMailer(); + self::$mailer->setFrom('unl.lockup.factory@unl.edu', 'UNL Lockup Factory'); + if (is_array($to)) { + foreach ($to as $email) { + self::$mailer->addAddress($email); + } + } else { + self::$mailer->addAddress($to); + } + self::$mailer->addReplyTo('lemburg@unl.edu', 'Tyler Lemburg'); + self::$mailer->isHTML(true); + + self::$mailer->Subject = $subject; + self::$mailer->Body = $body; + + if(!self::$mailer->send()) { + return array('error' => self::$mailer->ErrorInfo); + } else { + return array('success' => true); + } + } +} \ No newline at end of file