From 291a701f606a7ff2a07813f94e0b9d00e3f9813b Mon Sep 17 00:00:00 2001 From: Chris Saylor Date: Sun, 5 Jan 2014 10:42:36 -0500 Subject: [PATCH 1/4] Removed old submodule reference directories. --- app/Plugin/DebugKit | 1 - app/Plugin/GChart | 1 - 2 files changed, 2 deletions(-) delete mode 160000 app/Plugin/DebugKit delete mode 160000 app/Plugin/GChart diff --git a/app/Plugin/DebugKit b/app/Plugin/DebugKit deleted file mode 160000 index e314ca4..0000000 --- a/app/Plugin/DebugKit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e314ca42256a8c8547158b8d62ffd2efa576ceee diff --git a/app/Plugin/GChart b/app/Plugin/GChart deleted file mode 160000 index ad3769d..0000000 --- a/app/Plugin/GChart +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ad3769de11f78d2ab259d96f2a2a3dbcb26ed844 From 01c38526deebb9f2a2762a1dfdcbd2c25ed01141 Mon Sep 17 00:00:00 2001 From: Chris Saylor Date: Sun, 5 Jan 2014 12:02:16 -0500 Subject: [PATCH 2/4] Add dynamic dependencies to ignore list. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 069e7fb..21d9c14 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ .project app/Vendor/ +app/Plugin/DebugKit +app/Plugin/GChart # config app/Config/environment.php From eab4d1f12c688a50e00ac379a17f1538ade91bc3 Mon Sep 17 00:00:00 2001 From: Chris Saylor Date: Sun, 5 Jan 2014 12:03:40 -0500 Subject: [PATCH 3/4] Created Mailgun component. --- app/Config/bootstrap.php | 3 + app/Config/environment.sample.php | 6 + .../Component/CustomEmailComponent.php | 40 ++++ composer.json | 3 +- composer.lock | 188 +++++++++++++++++- 5 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 app/Controller/Component/CustomEmailComponent.php diff --git a/app/Config/bootstrap.php b/app/Config/bootstrap.php index 54c9823..5fe8a43 100755 --- a/app/Config/bootstrap.php +++ b/app/Config/bootstrap.php @@ -58,6 +58,9 @@ Configure::write('Feedback.github.auth_token', Configure::read('Env.Feedback.github.auth_token')); Configure::write('Feedback.github.labels', array('Feedback')); +// Email Config +Configure::write('Email.mailgun', Configure::read('Env.Email.mailgun')); + // Message Configure::write('Message.message', Configure::read('Env.Message.message') ?: 'Some user message.'); Configure::write('Message.cookie_suffix', Configure::read('Env.Message.cookie_suffix') ?: '001'); diff --git a/app/Config/environment.sample.php b/app/Config/environment.sample.php index 3ce7ae4..7e14b46 100644 --- a/app/Config/environment.sample.php +++ b/app/Config/environment.sample.php @@ -14,6 +14,12 @@ 'database' => 'boxmeup' ) ), + 'Email' => array( + 'mailgun' => array( + 'domain' => '', + 'api_key' => '' + ) + ), 'Feature' => array( 'api' => true, 'mobile' => true, diff --git a/app/Controller/Component/CustomEmailComponent.php b/app/Controller/Component/CustomEmailComponent.php new file mode 100644 index 0000000..e62c589 --- /dev/null +++ b/app/Controller/Component/CustomEmailComponent.php @@ -0,0 +1,40 @@ +evaluate(APP . "/View/Emails/$type/$template.ctp", $data); + $result = $this->getMailer()->sendMessage(Configure::read('Email.mailgun.domain'), array( + 'from' => 'Boxmeup Team ', + 'to' => $to, + 'subject' => $subject, + 'text' => $body + )); + return $result->http_response_code === static::SEND_OK; + } + + /** + * Get the rendered output of a ctp file. + * + * @param string $filePath + * @param array $data + * @return string + */ + protected function evaluate($filePath, $data = array()) { + extract($data); + ob_start(); + include $filePath; + return ob_get_clean(); + } + +} diff --git a/composer.json b/composer.json index 4556b74..9155bc6 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "composer/installers": "*", "pear-cakephp/cakephp": "2.3.10", "neutron/sphinxsearch-api": "2.0.8", - "cjsaylor/gchart": "2.0.2" + "cjsaylor/gchart": "2.0.2", + "mailgun/mailgun-php": "1.5" }, "require-dev": { "cakephp/debug_kit": "2.2.*" diff --git a/composer.lock b/composer.lock index 3722305..916a29b 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "82378ce725482630442b2fc6355271a6", + "hash": "7fd73327239a2e86f0d9360623ec1848", "packages": [ { "name": "cjsaylor/gchart", @@ -127,6 +127,138 @@ ], "time": "2013-12-24 18:04:46" }, + { + "name": "guzzle/guzzle", + "version": "v3.7.4", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "b170b028c6bb5799640e46c8803015b0f9a45ed9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/b170b028c6bb5799640e46c8803015b0f9a45ed9", + "reference": "b170b028c6bb5799640e46c8803015b0f9a45ed9", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "php": ">=5.3.3", + "symfony/event-dispatcher": ">=2.1" + }, + "replace": { + "guzzle/batch": "self.version", + "guzzle/cache": "self.version", + "guzzle/common": "self.version", + "guzzle/http": "self.version", + "guzzle/inflection": "self.version", + "guzzle/iterator": "self.version", + "guzzle/log": "self.version", + "guzzle/parser": "self.version", + "guzzle/plugin": "self.version", + "guzzle/plugin-async": "self.version", + "guzzle/plugin-backoff": "self.version", + "guzzle/plugin-cache": "self.version", + "guzzle/plugin-cookie": "self.version", + "guzzle/plugin-curlauth": "self.version", + "guzzle/plugin-error-response": "self.version", + "guzzle/plugin-history": "self.version", + "guzzle/plugin-log": "self.version", + "guzzle/plugin-md5": "self.version", + "guzzle/plugin-mock": "self.version", + "guzzle/plugin-oauth": "self.version", + "guzzle/service": "self.version", + "guzzle/stream": "self.version" + }, + "require-dev": { + "doctrine/cache": "*", + "monolog/monolog": "1.*", + "phpunit/phpunit": "3.7.*", + "psr/log": "1.0.*", + "symfony/class-loader": "*", + "zendframework/zend-cache": "2.0.*", + "zendframework/zend-log": "2.0.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.7-dev" + } + }, + "autoload": { + "psr-0": { + "Guzzle\\Tests": "tests/", + "Guzzle": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Guzzle Community", + "homepage": "https://github.com/guzzle/guzzle/contributors" + } + ], + "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2013-10-02 20:47:00" + }, + { + "name": "mailgun/mailgun-php", + "version": "1.5", + "source": { + "type": "git", + "url": "https://github.com/mailgun/mailgun-php.git", + "reference": "0018d4f6ad271c418bc87d4c664ef07df0c85fad" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mailgun/mailgun-php/zipball/0018d4f6ad271c418bc87d4c664ef07df0c85fad", + "reference": "0018d4f6ad271c418bc87d4c664ef07df0c85fad", + "shasum": "" + }, + "require": { + "guzzle/guzzle": "3.7.*" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*" + }, + "type": "library", + "autoload": { + "psr-0": { + "Mailgun\\Tests": "tests/", + "Mailgun": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Travis Swientek", + "email": "travis@mailgunhq.com" + } + ], + "description": "The Mailgun SDK provides methods for all API functions.", + "time": "2013-12-05 21:23:38" + }, { "name": "neutron/sphinxsearch-api", "version": "2.0.8", @@ -194,6 +326,60 @@ "/" ], "description": "CakePHP is an application development framework for PHP 5.2+" + }, + { + "name": "symfony/event-dispatcher", + "version": "v2.4.1", + "target-dir": "Symfony/Component/EventDispatcher", + "source": { + "type": "git", + "url": "https://github.com/symfony/EventDispatcher.git", + "reference": "e3ba42f6a70554ed05749e61b829550f6ac33601" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/e3ba42f6a70554ed05749e61b829550f6ac33601", + "reference": "e3ba42f6a70554ed05749e61b829550f6ac33601", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/dependency-injection": "~2.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\EventDispatcher\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "http://symfony.com", + "time": "2013-12-28 08:12:03" } ], "packages-dev": [ From 1f3485dd363f7db356f5cbcc6d5a8fb37cb25995 Mon Sep 17 00:00:00 2001 From: Chris Saylor Date: Sun, 5 Jan 2014 12:03:56 -0500 Subject: [PATCH 4/4] Implemented mailgun component usage. --- app/Controller/UsersController.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/Controller/UsersController.php b/app/Controller/UsersController.php index 37e109b..834c8ee 100644 --- a/app/Controller/UsersController.php +++ b/app/Controller/UsersController.php @@ -5,7 +5,7 @@ class UsersController extends AppController { public $name = 'Users'; - public $components = array('Email'); + public $components = array('CustomEmail'); protected $ssl = array( 'login', 'signup', 'account', 'reset_password', 'auth' @@ -148,19 +148,21 @@ public function forgot_password() { $secretKey = ClassRegistry::init('Api.ApiUser')->getSecretKey($apiKey); $dynKey = base64_encode(date('c')); $hash = sha1($dynKey . $secretKey); - $this->Email->to = $this->request->data['User']['email']; - $this->Email->subject = 'Boxmeup Password Recovery'; - $this->Email->replyTo = 'no-reply@boxmeupapp.com'; - $this->Email->from = 'Boxmeup App '; - $this->Email->template = 'forgot_password'; - $this->Email->sendAs = 'text'; - $this->set(array( - 'password' => $new_password, - 'api_key' => $apiKey, - 'dynamic_key' => $dynKey, - 'hash' => $hash - )); - $this->Email->send(); + $sent = $this->CustomEmail->send( + $this->request->data['User']['email'], + 'Boxmeup Password Recovery', + 'forgot_password', + array( + 'password' => $new_password, + 'api_key' => $apiKey, + 'dynamic_key' => $dynKey, + 'hash' => $hash + ) + ); + if (!$sent) { + $this->Session->setFlash(__('Failed to send recovery email.'), 'notification/error'); + $this->redirect('/users/forgot_password'); + } } $this->Session->setFlash(__('Successfully sent recovery request.'), 'notification/success'); $this->redirect('/login');