Created
November 18, 2013 09:58
-
-
Save markphi2013/7525420 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('Component', 'Controller'); | |
App::uses('User', 'Model'); | |
App::uses('CakeEmail', 'Network/Email'); | |
class TicketComponent extends Component | |
{ | |
var $components = array('Email'); | |
var $sitename = 'http://vusion.texttochange.org'; | |
//var $linkdomain = 'vusion.texttochange.org'; | |
var $linkdomain = '192.168.0.160:81'; | |
public function initialize(Controller $controller) | |
{ | |
parent::startup($controller); | |
CakeEmail::transport(); | |
$this->Controller = $controller; | |
if(isset($this->Controller->redis)){ | |
$this->redis = $this->Controller->redis; | |
}else{ | |
$this->redis = new Redis(); | |
$this->redis->connect('127.0.0.1'); | |
} | |
if(isset($this->Controller->redisTicketPrefix)){ | |
$this->redisTicketPrefix = $this->Controller->redisTicketPrefix; | |
}else{ | |
$this->redisTicketPrefix = 'vusion:passwordreset'; | |
} | |
} | |
public function createMessage($token) | |
{ | |
$ms='<html><head><title>Password Reset Request</title></head>'; | |
$ms .='<body>Your email has been used in a password reset request at '.$this->sitename.'<br/>'; | |
$ms .='If you did not initiate this request, then ignore this message.<br/>'; | |
$ms .=' Click the link below into your browser to reset your password.<br/>'; | |
$ms .='<a href="http://'.$this->linkdomain.'/users/useTicket/'.$token.'">Reset Password</a>'; | |
$ms .='</body></html>'; | |
$ms = wordwrap($ms,70); | |
return $ms; | |
} | |
public function sendEmail($userEmail, $userName, $message) | |
{ | |
$email = new CakeEmail(); | |
$email->config('smtp2'); | |
$email->from(array('mssembajjwe@texttochange.com' => 'vusion.com')); | |
$email->to($userEmail); | |
$email->subject('Message from '.$this->sitename.' for '.$userName); | |
$email->send($message); | |
} | |
/// I need to add $userid in this function so as to get "vusion:passwordreset:$userId:$hash" | |
but i need help on how to call the user id here | |
protected function _getTicketKey($hash) | |
{ | |
return $this->redisTicketPrefix.':'.$hash; | |
} | |
public function checkTicket($hash) | |
{ | |
$result=false; | |
$ticketKey = $this->_getTicketKey($hash); | |
$ticket = $this->redis->get($ticketKey); | |
if (empty($ticket)) { | |
$result = $hash; | |
$this->redis->setex($ticketKey, 1000, $hash); | |
} | |
return $result; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment