FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Mail.php
Go to the documentation of this file.
1 <?php
2 
4 
5 class Mail extends \Rsi\Fred\User\Authenticator{
6 
7  public $tokenLength = 8;
8  public $tokenChars = '234678ACEFGHJKLMNPQRTUVWXYZ';
9  public $tokenTime = 300; //!< Time (in seconds) for which the token is valid.
10  public $tokenTries = 5; //!< Maximum number of times to enter the correct token.
11 
12  public $mailFrom = null; //!< Mail message sender address (default when empty).
13  public $mailSubject = 'Authentication token';
14  public $mailBody = '[token]';
15  public $mailHtml = false; //!< True when the message body is in HTML format.
16 
17  protected function check(){
18  return null;
19  }
20 
21  protected function tags($token){
22  return ['token' => $token];
23  }
24 
25  public function token($email){
26  if(!$email) $this->checked = false;
27  elseif($this->session->time < time() - $this->tokenTime){
28  $this->session->time = time();
29  $this->session->tries = 0;
30  $tags = $this->tags($this->session->token = \Rsi\Str::random($this->tokenLength,$this->tokenChars));
31  $trans = $this->component('trans');
32  $this->component('mail')->send($this->mailFrom,$email,$trans->str($this->mailSubject,$tags),$trans->str($this->mailBody,$tags),$this->mailHtml);
33  }
34  return $this->session->token;
35  }
36 
37  public function verify($token){
38  $this->verified($token && !strcasecmp($this->session->token,$token) && ($this->session->time > time() - $this->tokenTime));
39  if(++$this->session->tries >= $this->tokenTries) $this->session->time = null;
40  return $this->checked;
41  }
42 
43 }
$tokenTime
Time (in seconds) for which the token is valid.
Definition: Mail.php:9
$mailFrom
Mail message sender address (default when empty).
Definition: Mail.php:12
$mailHtml
True when the message body is in HTML format.
Definition: Mail.php:15
$tokenTries
Maximum number of times to enter the correct token.
Definition: Mail.php:10
verified($result)
Process the result of a verification.
component($name)
Get a component (local or default).
Definition: Component.php:80