|
1
|
|
|
<?php
|
|
2
|
|
|
/**
|
|
3
|
|
|
* @author Alexey Tatarinov <[email protected]>
|
|
4
|
|
|
* @link https://github.com/shogodev/argilla/
|
|
5
|
|
|
* @copyright Copyright © 2003-2014 Shogo
|
|
6
|
|
|
* @license http://argilla.ru/LICENSE
|
|
7
|
|
|
* @package frontend.controllers
|
|
8
|
|
|
*/
|
|
9
|
|
|
class UserController extends FController
|
|
10
|
|
|
{
|
|
11
|
|
|
public function actionSocialLogin($service)
|
|
12
|
|
|
{
|
|
13
|
|
|
if( isset($service) )
|
|
14
|
|
|
{
|
|
15
|
|
|
$this->socialRegistration($service);
|
|
16
|
|
|
}
|
|
17
|
|
|
}
|
|
18
|
|
|
|
|
19
|
3 |
|
public function actionLogin()
|
|
20
|
|
|
{
|
|
21
|
3 |
|
if( !Yii::app()->user->isGuest )
|
|
22
|
3 |
|
$this->redirect($this->createUrl('userProfile/profile'), true, 200);
|
|
23
|
|
|
|
|
24
|
3 |
|
$this->breadcrumbs = array('Вход');
|
|
25
|
|
|
|
|
26
|
3 |
|
$loginForm = new FForm('LoginForm', new Login());
|
|
27
|
3 |
|
$loginForm->action = Yii::app()->controller->createUrl('user/login');
|
|
28
|
3 |
|
$loginForm->ajaxSubmit = false;
|
|
29
|
3 |
|
$loginForm->validateOnChange = false;
|
|
30
|
3 |
|
$loginForm->validateOnSubmit = false;
|
|
31
|
3 |
|
$loginForm->autocomplete = true;
|
|
32
|
|
|
|
|
33
|
3 |
|
if( $loginForm->process() )
|
|
34
|
2 |
|
{
|
|
35
|
1 |
|
$this->redirect(Yii::app()->user->returnUrl);
|
|
36
|
|
|
Yii::app()->end();
|
|
|
|
|
|
|
37
|
|
|
}
|
|
38
|
|
|
|
|
39
|
1 |
|
$this->render('login', array('loginForm' => $loginForm));
|
|
40
|
1 |
|
}
|
|
41
|
|
|
|
|
42
|
1 |
|
public function actionLogout()
|
|
43
|
|
|
{
|
|
44
|
1 |
|
$returnUrl = Yii::app()->user->returnUrl;
|
|
45
|
1 |
|
Yii::app()->user->logout(false);
|
|
46
|
1 |
|
$this->redirect($returnUrl);
|
|
47
|
|
|
Yii::app()->end();
|
|
|
|
|
|
|
48
|
|
|
}
|
|
49
|
|
|
|
|
50
|
2 |
|
public function actionRegistration()
|
|
51
|
|
|
{
|
|
52
|
2 |
|
if( Yii::app()->user->isGuest )
|
|
53
|
2 |
|
{
|
|
54
|
2 |
|
$this->breadcrumbs = array('Регистрация');
|
|
55
|
|
|
|
|
56
|
2 |
|
$registrationForm = new FForm('UserRegistration', new User());
|
|
57
|
2 |
|
$registrationForm->loadFromSession = true;
|
|
58
|
2 |
|
$registrationForm->clearAfterSubmit = true;
|
|
59
|
2 |
|
$registrationForm['profile']->model = new UserProfile(User::SCENARIO_REGISTRATION);
|
|
60
|
|
|
|
|
61
|
2 |
|
if( Yii::app()->request->isPostRequest )
|
|
62
|
2 |
|
$registrationForm->model->email = CHtml::encode(Yii::app()->request->getParam('email', ''));
|
|
63
|
|
|
|
|
64
|
2 |
|
$registrationForm->ajaxValidation();
|
|
65
|
|
|
|
|
66
|
2 |
|
if( Yii::app()->request->isAjaxRequest && $registrationForm->save() )
|
|
67
|
2 |
|
{
|
|
68
|
|
|
|
|
69
|
1 |
|
Yii::app()->notification->send(
|
|
70
|
1 |
|
'UserRegistration',
|
|
71
|
|
|
array(
|
|
72
|
1 |
|
'model' => $registrationForm->model,
|
|
73
|
1 |
|
'profile' => $registrationForm['profile']->model
|
|
74
|
1 |
|
),
|
|
75
|
1 |
|
$registrationForm->model->email
|
|
76
|
1 |
|
);
|
|
77
|
|
|
|
|
78
|
1 |
|
Yii::app()->notification->send(
|
|
79
|
1 |
|
'UserRegistrationBackend',
|
|
80
|
|
|
array(
|
|
81
|
1 |
|
'model' => $registrationForm->model,
|
|
82
|
1 |
|
'profile' => $registrationForm['profile']->model
|
|
83
|
1 |
|
),
|
|
84
|
1 |
|
null,
|
|
85
|
|
|
'backend'
|
|
86
|
1 |
|
);
|
|
87
|
|
|
|
|
88
|
1 |
|
echo CJSON::encode(array(
|
|
89
|
1 |
|
'status' => 'ok',
|
|
90
|
1 |
|
'messageForm' => $this->textBlockRegister(
|
|
91
|
1 |
|
'Успешная регистрация',
|
|
92
|
|
|
'Регистрация успешно завершена'
|
|
93
|
1 |
|
),
|
|
94
|
1 |
|
'removeElements' => array('registration-text')
|
|
95
|
1 |
|
));
|
|
96
|
1 |
|
Yii::app()->end();
|
|
|
|
|
|
|
97
|
|
|
}
|
|
98
|
|
|
|
|
99
|
1 |
|
$this->render('registration', array('registrationForm' => $registrationForm));
|
|
100
|
1 |
|
}
|
|
101
|
|
|
else
|
|
102
|
|
|
{
|
|
103
|
|
|
$this->render('registration');
|
|
104
|
|
|
}
|
|
105
|
1 |
|
}
|
|
106
|
|
|
|
|
107
|
2 |
|
public function actionRestore()
|
|
108
|
|
|
{
|
|
109
|
2 |
|
$this->breadcrumbs = array('Восстановление пароля');
|
|
110
|
|
|
|
|
111
|
2 |
|
$restoreForm = new FForm('UserRestore', new RestorePassword(RestorePassword::GENERATE_RESTORE_CODE));
|
|
112
|
2 |
|
$restoreForm->validateOnChange = false;
|
|
113
|
2 |
|
$restoreForm->ajaxValidation();
|
|
114
|
|
|
|
|
115
|
2 |
|
if( Yii::app()->request->isAjaxRequest && $restoreForm->process() )
|
|
116
|
2 |
|
{
|
|
117
|
1 |
|
Yii::app()->notification->send(
|
|
118
|
1 |
|
'UserRequestRestorePassword',
|
|
119
|
1 |
|
array('model' => $restoreForm->model),
|
|
120
|
1 |
|
$restoreForm->model->email
|
|
121
|
1 |
|
);
|
|
122
|
|
|
|
|
123
|
1 |
|
$restoreForm->responseSuccess(Yii::app()->controller->textBlockRegister(
|
|
124
|
1 |
|
'Email успешно отправлен',
|
|
125
|
|
|
'Вам на E-mail отправлены дальнейшие инструкции'
|
|
126
|
1 |
|
));
|
|
127
|
|
|
}
|
|
128
|
|
|
else
|
|
129
|
1 |
|
$this->render('restore', array('restoreForm' => $restoreForm));
|
|
130
|
1 |
|
}
|
|
131
|
|
|
|
|
132
|
2 |
|
public function actionRestoreConfirmed($code)
|
|
133
|
|
|
{
|
|
134
|
2 |
|
$this->breadcrumbs = array('Восстановление пароля');
|
|
135
|
|
|
|
|
136
|
2 |
|
$restorePassword = new RestorePassword(RestorePassword::GENERATE_NEW_PASSWORD);
|
|
137
|
2 |
|
$restorePassword->attributes = array('restoreCode' => $code);
|
|
138
|
|
|
|
|
139
|
2 |
|
if( $restorePassword->validate() )
|
|
140
|
2 |
|
{
|
|
141
|
1 |
|
Yii::app()->notification->send(
|
|
142
|
1 |
|
'UserRestorePassword',
|
|
143
|
|
|
array(
|
|
144
|
1 |
|
'model' => $restorePassword,
|
|
145
|
1 |
|
'password' => $restorePassword->user->password
|
|
|
|
|
|
|
146
|
1 |
|
),
|
|
147
|
1 |
|
$restorePassword->user->email
|
|
|
|
|
|
|
148
|
1 |
|
);
|
|
149
|
|
|
|
|
150
|
1 |
|
$this->render('restore', array('restoreForm' => 'Новый пароль выслан на ваш E-mail.'));
|
|
151
|
1 |
|
}
|
|
152
|
|
|
else
|
|
153
|
1 |
|
$this->redirect(array('user/restore'));
|
|
154
|
1 |
|
}
|
|
155
|
|
|
|
|
156
|
|
|
private function socialRegistration($service)
|
|
157
|
|
|
{
|
|
158
|
|
|
/**
|
|
159
|
|
|
* @var $eauth EAuthServiceBase
|
|
160
|
|
|
*/
|
|
161
|
|
|
$eauth = Yii::app()->eauth->getIdentity($service);
|
|
162
|
|
|
$eauth->redirectUrl = Yii::app()->user->getReturnUrl($this->createAbsoluteUrl('index/index'));
|
|
|
|
|
|
|
163
|
|
|
$eauth->cancelUrl = Yii::app()->user->getReturnUrl($this->createAbsoluteUrl('index/index'));
|
|
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
try
|
|
166
|
|
|
{
|
|
167
|
|
|
if( $eauth->authenticate() )
|
|
168
|
|
|
{
|
|
169
|
|
|
$identity = new FUserSocialIdentity($eauth);
|
|
170
|
|
|
|
|
171
|
|
|
if( $identity->authenticate() )
|
|
172
|
|
|
{
|
|
173
|
|
|
Yii::app()->user->login($identity);
|
|
174
|
|
|
$eauth->redirect();
|
|
175
|
|
|
}
|
|
176
|
|
|
else
|
|
177
|
|
|
{
|
|
178
|
|
|
$eauth->cancel();
|
|
179
|
|
|
}
|
|
180
|
|
|
}
|
|
181
|
|
|
|
|
182
|
|
|
Yii::app()->user->setFlash('success', 'Авторизация прошла успешно');
|
|
183
|
|
|
|
|
184
|
|
|
// Something went wrong, redirect to login page
|
|
185
|
|
|
$this->redirect(Yii::app()->user->getReturnUrl($this->createAbsoluteUrl('user/data')));
|
|
186
|
|
|
}
|
|
187
|
|
|
catch(EAuthException $e)
|
|
188
|
|
|
{
|
|
189
|
|
|
// save authentication error to session
|
|
190
|
|
|
Yii::app()->user->setFlash('error', 'Ошибка авторизации: '.$e->getMessage());
|
|
191
|
|
|
|
|
192
|
|
|
// close popup window and redirect to cancelUrl
|
|
193
|
|
|
$eauth->redirect($eauth->getCancelUrl());
|
|
194
|
|
|
}
|
|
195
|
|
|
}
|
|
196
|
|
|
} |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: