5 public $defaultAction =
'login';
21 public function filters(){
24 'BadLoginAttemptsFilter + standard',
25 'attemptsCount' => $this->module->loginBadAttemps,
26 'blockTime' => $this->module->loginBlockTime,
31 public function actionStandard()
34 if(!$this->attemptsEnded){
36 $loginForm->attributes = @$_POST[
'UserLogin'];
37 if ($loginForm->validate()) {
38 if ($loginForm->service ==
'standard' && array_key_exists(
'standard', Yii::app()->eauth->services)) {
39 $userIdentity =
new UserIdentity($loginForm->authField, $loginForm->password);
40 if($userIdentity->authenticate() && !isset($_POST[
'ajax'])) {
41 Yii::app()->user->setState(
'UserLogin', null);
42 $returnUrl = Yii::app()->user->getReturnUrl();
43 Yii::app()->user->login($userIdentity, $this->module->loggedInDuration * intval($loginForm->rememberMe));
44 if($returnUrl !=
'/'){
45 $this->redirect($returnUrl);
47 Yii::app()->user->setFlash(Yii::app()->getModule(
'user')->userLoginWidgetFlashSuccess,
UserModule::t(
'You have been successfully logged in.'));
49 $loginForm->applyErrors($userIdentity);
51 if (isset($_REQUEST[
'ajax'])) {
53 echo $loginForm->getAjaxErrors();
57 $loginForm->password = null;
58 Yii::app()->user->setState(
'UserLogin', array(
'attributes' => $loginForm->attributes,
'errors' => $loginForm->getErrors()));
61 throw new CHttpException(400,
'Wrong service');
63 } elseif (isset($_POST[
'ajax'])){
64 echo $loginForm->getAjaxErrors();
67 $loginForm->password = null;
68 Yii::app()->user->setState(
'UserLogin', array(
'attributes' => $loginForm->attributes,
'errors' => $loginForm->getErrors()));
71 Yii::app()->user->setFlash(
72 $this->module->userLoginWidgetFlashError,
UserModule::t(
'Please wait {s} seconds before next login.', array(
'{s}' => $this->timeRemains)));
75 if (isset($_POST[
'return_url'])) {
76 $this->redirect($_POST[
'return_url'],
false);
78 $this->render(
'/user/login', array(
'model' => $loginForm));
82 public function actionTpa()
85 $loginForm->attributes = @$_GET[
'UserLogin'];
86 if (isset($_GET[
'ajax'])){
87 echo $loginForm->getAjaxErrors();
90 if ($loginForm->validate()) {
91 if ($loginForm->service !=
'standard' && array_key_exists($loginForm->service, Yii::app()->eauth->services)) {
92 if(isset($_GET[
'ajax'])) {
93 throw new CHttpException(400,
'Wrong request');
95 $serviceIdentity = Yii::app()->eauth->getIdentity($loginForm->service);
96 $serviceIdentity->redirectUrl = Yii::app()->user->returnUrl;
97 $serviceIdentity->cancelUrl = $this->createAbsoluteUrl(
'user/login');
98 if ($serviceIdentity->authenticate()) {
99 $serviceIdentity->getAttributes();
100 $this->onTPAAuthorizationSuccess($serviceIdentity);
102 if($userIdentity->authenticate()) {
103 Yii::app()->user->setState(
'UserLogin', null);
104 Yii::app()->user->login($userIdentity, $this->module->loggedInDuration * intval($loginForm->rememberMe));
106 $loginForm->applyErrors($userIdentity);
109 Yii::app()->user->setFlash(
'error', $serviceIdentity->getError());
112 throw new CHttpException(400,
'Wrong service');
115 $loginForm->password = null;
116 Yii::app()->user->setState(
'UserLogin', array(
'attributes' => $loginForm->attributes,
'errors' => $loginForm->getErrors()));
119 if (isset($_GET[
'return_url'])) {
120 $this->redirect($_GET[
'return_url']);
122 $this->render(
'/user/login', array(
'model' => $loginForm));
126 private function lastViset()
128 $lastVisit =
User::model()->notsafe()->findByPk(Yii::app()->user->id);
129 $lastVisit->lastvisit = time();
133 public function onLogin($userIdentity)
135 $message =
"User: {$userIdentity->username} logged in. Return URL: " . Yii::app()->user->returnUrl .
". \$_REQUEST['return_url']: " . @$_REQUEST[
'return_url'];
137 Yii::app()->notificationManager->notifyAbout($notification);
141 public function onTPAAuthorizationSuccess($serviceIdentity)
143 $message =
"Account {$serviceIdentity->getEmail()} from TPA: {$serviceIdentity->serviceName} successfuly authorized\n";
145 Yii::app()->notificationManager->notifyAbout($notification);