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 Yii::app()->user->setState(
'UserLogin', array(
'attributes' => $loginForm->attributes,
'errors' => $loginForm->getErrors()));
60 throw new CHttpException(400,
'Wrong service');
62 } elseif (isset($_POST[
'ajax'])){
63 echo $loginForm->getAjaxErrors();
66 Yii::app()->user->setState(
'UserLogin', array(
'attributes' => $loginForm->attributes,
'errors' => $loginForm->getErrors()));
69 Yii::app()->user->setFlash(
70 $this->module->userLoginWidgetFlashError,
UserModule::t(
'Please wait {s} seconds before next login.', array(
'{s}' => $this->timeRemains)));
73 if (isset($_POST[
'return_url'])) {
74 $this->redirect($_POST[
'return_url'],
false);
76 $this->render(
'/user/login', array(
'model' => $loginForm));
80 public function actionTpa()
83 $loginForm->attributes = @$_GET[
'UserLogin'];
84 if (isset($_GET[
'ajax'])){
85 echo $loginForm->getAjaxErrors();
88 if ($loginForm->validate()) {
89 if ($loginForm->service !=
'standard' && array_key_exists($loginForm->service, Yii::app()->eauth->services)) {
90 if(isset($_GET[
'ajax'])) {
91 throw new CHttpException(400,
'Wrong request');
93 $serviceIdentity = Yii::app()->eauth->getIdentity($loginForm->service);
94 $serviceIdentity->redirectUrl = Yii::app()->user->returnUrl;
95 $serviceIdentity->cancelUrl = $this->createAbsoluteUrl(
'user/login');
96 if ($serviceIdentity->authenticate()) {
97 $serviceIdentity->getAttributes();
98 $this->onTPAAuthorizationSuccess($serviceIdentity);
100 if($userIdentity->authenticate()) {
101 Yii::app()->user->setState(
'UserLogin', null);
102 Yii::app()->user->login($userIdentity, $this->module->loggedInDuration * intval($loginForm->rememberMe));
104 $loginForm->applyErrors($userIdentity);
107 Yii::app()->user->setFlash(
'error', $serviceIdentity->getError());
110 throw new CHttpException(400,
'Wrong service');
113 Yii::app()->user->setState(
'UserLogin', array(
'attributes' => $loginForm->attributes,
'errors' => $loginForm->getErrors()));
116 if (isset($_GET[
'return_url'])) {
117 $this->redirect($_GET[
'return_url']);
119 $this->render(
'/user/login', array(
'model' => $loginForm));
123 private function lastViset()
125 $lastVisit =
User::model()->notsafe()->findByPk(Yii::app()->user->id);
126 $lastVisit->lastvisit = time();
130 public function onLogin($userIdentity)
132 $message =
"User: {$userIdentity->username} logged in. Return URL: " . Yii::app()->user->returnUrl .
". \$_REQUEST['return_url']: " . @$_REQUEST[
'return_url'];
134 Yii::app()->notificationManager->notifyAbout($notification);
138 public function onTPAAuthorizationSuccess($serviceIdentity)
140 $message =
"Account {$serviceIdentity->getEmail()} from TPA: {$serviceIdentity->serviceName} successfuly authorized\n";
142 Yii::app()->notificationManager->notifyAbout($notification);