Skip to content

Commit

Permalink
Merge pull request #169 from cjsaylor/2.4.2
Browse files Browse the repository at this point in the history
2.4.2
  • Loading branch information
cjsaylor committed Jan 5, 2014
2 parents 62c54f2 + 1f3485d commit 1b7b3e1
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.project

app/Vendor/
app/Plugin/DebugKit
app/Plugin/GChart

# config
app/Config/environment.php
Expand Down
3 changes: 3 additions & 0 deletions app/Config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 6 additions & 0 deletions app/Config/environment.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
'database' => 'boxmeup'
)
),
'Email' => array(
'mailgun' => array(
'domain' => '',
'api_key' => ''
)
),
'Feature' => array(
'api' => true,
'mobile' => true,
Expand Down
40 changes: 40 additions & 0 deletions app/Controller/Component/CustomEmailComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Mailgun\Mailgun;

App::uses('Component', 'Controller');

Class CustomEmailComponent extends Component {

const SEND_OK = 200;

public function getMailer() {
return new Mailgun(Configure::read('Email.mailgun.api_key'));
}

public function send($to, $subject, $template, $data, $type = 'text') {
$body = $this->evaluate(APP . "/View/Emails/$type/$template.ctp", $data);
$result = $this->getMailer()->sendMessage(Configure::read('Email.mailgun.domain'), array(
'from' => 'Boxmeup Team <[email protected]>',
'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();
}

}
30 changes: 16 additions & 14 deletions app/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 = '[email protected]';
$this->Email->from = 'Boxmeup App <[email protected]>';
$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');
Expand Down
1 change: 0 additions & 1 deletion app/Plugin/DebugKit
Submodule DebugKit deleted from e314ca
1 change: 0 additions & 1 deletion app/Plugin/GChart
Submodule GChart deleted from ad3769
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.*"
Expand Down
188 changes: 187 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1b7b3e1

Please sign in to comment.