1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Hello\Modules\AbstractModule\Forms\Users; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Trait RecoverPasswordFormTrait |
7
|
|
|
* @package ByTIC\Hello\Modules\AbstractModule\Forms\Users |
8
|
|
|
*/ |
9
|
|
|
trait RecoverPasswordFormTrait |
10
|
|
|
{ |
11
|
|
|
public function init() |
12
|
|
|
{ |
13
|
|
|
parent::init(); |
14
|
|
|
$this->removeClass('form-horizontal'); |
|
|
|
|
15
|
|
|
$this->addClass('user-recover'); |
|
|
|
|
16
|
|
|
|
17
|
|
|
$this->initEmailInput(); |
18
|
|
|
|
19
|
|
|
$this->addButton('save', translator()->trans('submit')); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
protected function initEmailInput() |
23
|
|
|
{ |
24
|
|
|
$this->addInput('email', translator()->trans('email'), true); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function processValidation() |
28
|
|
|
{ |
29
|
|
|
parent::processValidation(); |
30
|
|
|
|
31
|
|
|
$this->processValidationEmail(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function processValidationEmail() |
35
|
|
|
{ |
36
|
|
|
$email = $this->getElement('email'); |
|
|
|
|
37
|
|
|
if (!$email->isError()) { |
38
|
|
|
$value = $email->getValue(); |
39
|
|
|
if (!valid_email($value) && false) { |
|
|
|
|
40
|
|
|
$email->addError($this->getModelMessage('email.bad')); |
|
|
|
|
41
|
|
|
} else { |
42
|
|
|
$users = $this->getModelManager()->findByEmail($value); |
|
|
|
|
43
|
|
|
if (count($users) == 1) { |
44
|
|
|
$this->getModel()->email = $value; |
|
|
|
|
45
|
|
|
} else { |
46
|
|
|
$email->addError($this->getModelMessage('email.dnx')); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function process() |
53
|
|
|
{ |
54
|
|
|
$this->getModel()->recoverPassword(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function getDataFromModel() |
58
|
|
|
{ |
59
|
|
|
parent::getDataFromModel(); |
60
|
|
|
$this->_addModelFormMessage('no-email', 'email.empty'); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|