File tree 3 files changed +35
-7
lines changed
3 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ class UserModule extends CWebModule
58
58
public $ logoutUrl = array ("/user/logout " );
59
59
public $ profileUrl = array ("/user/profile " );
60
60
public $ returnUrl = array ("/user/profile " );
61
+ public $ firstLoginReturnUrl = array ("/user/profile " );
61
62
public $ returnLogoutUrl = array ("/user/login " );
62
63
63
64
public $ captchaParams = array (
@@ -281,4 +282,17 @@ public static function getUserByName($username) {
281
282
public function users () {
282
283
return User;
283
284
}
285
+
286
+ /**
287
+ * Return redirect url for user
288
+ *
289
+ * @param bool $firstLogin
290
+ * @return mixed
291
+ */
292
+ public static function getReturnUrl ($ firstLogin = true )
293
+ {
294
+ return ($ firstLogin && isset (Yii::app ()->controller ->module ->firstLoginReturnUrl ) && !empty (Yii::app ()->controller ->module ->firstLoginReturnUrl )) ?
295
+ Yii::app ()->controller ->module ->firstLoginReturnUrl :
296
+ Yii::app ()->controller ->module ->returnUrl ;
297
+ }
284
298
}
Original file line number Diff line number Diff line change @@ -17,23 +17,35 @@ public function actionLogin()
17
17
$ model ->attributes =$ _POST ['UserLogin ' ];
18
18
// validate user input and redirect to previous page if valid
19
19
if ($ model ->validate ()) {
20
+ $ returnUrl = UserModule::getReturnUrl (!$ this ->isUserWasLogined ());
20
21
$ this ->lastViset ();
21
- if (Yii::app ()->getBaseUrl ()."/index.php " === Yii:: app ()-> user -> returnUrl )
22
+ if (Yii::app ()->getBaseUrl ()."/index.php " === $ returnUrl )
22
23
$ this ->redirect (Yii::app ()->controller ->module ->returnUrl );
23
24
else
24
- $ this ->redirect (Yii:: app ()-> user -> returnUrl );
25
+ $ this ->redirect ($ returnUrl );
25
26
}
26
27
}
27
28
// display the login form
28
29
$ this ->render ('/user/login ' ,array ('model ' =>$ model ));
29
30
} else
30
31
$ this ->redirect (Yii::app ()->controller ->module ->returnUrl );
31
32
}
32
-
33
+
33
34
private function lastViset () {
34
- $ lastVisit = User:: model ()-> notsafe ()-> findByPk (Yii:: app ()-> user -> id );
35
- $ lastVisit ->lastvisit_at = date ('Y-m-d H:i:s ' );
36
- $ lastVisit ->save ();
35
+ $ user = UserModule:: user ( );
36
+ $ user ->lastvisit_at = date ('Y-m-d H:i:s ' );
37
+ $ user ->save ();
37
38
}
38
39
40
+ /**
41
+ * Return if it's user's was already logged in.
42
+ *
43
+ * @return bool
44
+ */
45
+ private function isUserWasLogined ()
46
+ {
47
+ $ user = UserModule::user ();
48
+
49
+ return $ user ->lastvisit_at != '0000-00-00 00:00:00 ' ;
50
+ }
39
51
}
Original file line number Diff line number Diff line change @@ -55,7 +55,9 @@ public function actionRegistration() {
55
55
$ identity =new UserIdentity ($ model ->username ,$ soucePassword );
56
56
$ identity ->authenticate ();
57
57
Yii::app ()->user ->login ($ identity ,0 );
58
- $ this ->redirect (Yii::app ()->controller ->module ->returnUrl );
58
+ $ model ->lastvisit_at = date ('Y-m-d H:i:s ' );
59
+ $ model ->save ();
60
+ $ this ->redirect (UserModule::getReturnUrl ());
59
61
} else {
60
62
if (!Yii::app ()->controller ->module ->activeAfterRegister &&!Yii::app ()->controller ->module ->sendActivationMail ) {
61
63
Yii::app ()->user ->setFlash ('registration ' ,UserModule::t ("Thank you for your registration. Contact Admin to activate your account. " ));
You can’t perform that action at this time.
0 commit comments