-
Notifications
You must be signed in to change notification settings - Fork 39
/
Component.php
85 lines (75 loc) · 2.74 KB
/
Component.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
class Kwc_User_Login_Form_Component extends Kwc_Form_Component
{
public static function getSettings($param = null)
{
$ret = parent::getSettings($param);
$ret['placeholder']['submitButton'] = trlKwfStatic('Login');
$ret['generators']['child']['component']['success'] = 'Kwc_User_Login_Form_Success_Component';
$ret['plugins'][] = 'Kwc_User_Login_Form_UseViewCachePlugin';
return $ret;
}
public function preProcessInput(array $postData)
{
$this->_processInput($postData);
parent::preProcessInput($postData);
}
public function processInput(array $postData)
{
// Already called in preProcessInput
}
public function _getBaseParams()
{
$ret = parent::_getBaseParams();
if (!empty($_GET['redirect'])) $ret['redirect'] = $_GET['redirect'];
return $ret;
}
public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer)
{
$ret = parent::getTemplateVars($renderer);
$ret['register'] = $this->_getRegisterComponent();
return $ret;
}
protected function _getRegisterComponent()
{
return Kwf_Component_Data_Root::getInstance()
->getComponentByClass(
'Kwc_User_Register_Component',
array('subroot' => $this->getData())
);
}
protected function _afterSave(Kwf_Model_Row_Interface $row)
{
$result = $this->_getAuthenticateResult($row->email, $row->password);
if ($result->isValid()) {
$authedUser = Kwf_Registry::get('userModel')->getAuthedUser();
if ($row->auto_login) {
Kwf_User_Autologin::setCookies($authedUser);
} else {
//user logged in without autologin activated, clear the autologin token
Kwf_User_Autologin::clearToken($authedUser);
}
$this->_afterLogin($authedUser);
} else {
if ($result->getMessages()) {
foreach ($result->getMessages() as $message) {
$this->_errors[] = array('message' => $this->getData()->trlStaticExecute($message));
}
} else {
$this->_errors[] = array('message' => $this->getData()->trlKwf('Invalid E-Mail or password, please try again.'));
}
}
}
protected function _afterLogin(Kwf_User_Row $user)
{
}
private function _getAuthenticateResult($identity, $credential)
{
$adapter = new Kwf_Auth_Adapter_PasswordAuth();
$adapter->setIdentity($identity);
$adapter->setCredential($credential);
$auth = Kwf_Auth::getInstance();
$auth->clearIdentity();
return $auth->authenticate($adapter);
}
}