forked from idno/known
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Password.php
69 lines (48 loc) · 2.16 KB
/
Password.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Recover a forgotten password
*/
namespace Idno\Pages\Account {
use Idno\Core\Email;
use Idno\Entities\User;
/**
* Default class to serve the password recovery page
*/
class Password extends \Idno\Common\Page
{
function getContent()
{
$this->reverseGatekeeper();
$t = \Idno\Core\site()->template();
if ($sent = $this->getInput('sent')) {
$t->body = $t->draw('account/password/sent');
$t->title = 'Password recovery email sent';
} else {
$t->body = $t->draw('account/password');
$t->title = 'Recover password';
}
$t->drawPage();
}
function postContent()
{
$this->reverseGatekeeper();
$email_address = $this->getInput('email');
if ($user = User::getByEmail($email_address)) {
if ($auth_code = $user->addPasswordRecoveryCode()) {
$user->save(); // Save the recovery code to the user
$t = clone \Idno\Core\site()->template();
$t->setTemplateType('email');
$email = new Email();
$email->setSubject("Password reset");
$email->addTo($user->email);
$email->setHTMLBody($t->__(array('email' => $email_address, 'code' => $auth_code))->draw('account/password'));
$email->setTextBodyFromTemplate('account/password', array('email' => $email_address, 'code' => $auth_code));
$email->send();
$this->forward(\Idno\Core\site()->config()->getURL() . 'account/password/?sent=true');
}
}
\Idno\Core\site()->session()->addErrorMessage("Oh no! We couldn't find an account associated with that email address.");
$this->forward(\Idno\Core\site()->config()->getURL() . 'account/password');
}
}
}