Yii Framework Forum: redirect after successful login - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

redirect after successful login Rate Topic: -----

#1 User is offline   vanja 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 07-February 10
  • Location:Podgorica, Montenegro

Posted 11 February 2010 - 12:10 PM

Hello!

I have 2 tables: tbl_users and tbl_pj in mysql database.

I'm trying to modify action Login to redirect (after successful login) not to returnUrl but to
a) in case user is admin - to redirect to crud page of users, so admin can add/delete/update users
B) in case user is simple user - to redirect to other crud pj where authenticated users can add/delete/update
records in table pj.


Any suggestions?
0

#2 User is offline   Arvind 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 03-October 09
  • Location:Calgary, AB, Canada

Posted 11 February 2010 - 02:24 PM

Hi,
This is easy...
assuming you are going with the default code generated by the yiic tool.

inside your /yourapp/protected/controllers/SiteController.php

find the actionLogin()

there you will find this line
if($form->validate())
$this->redirect(Yii::app()->user->returnUrl);


change ur logic here like
if($form->validate())
{
if (Yii::app()->user->id=='admin') /* which ever way u implement adminc check*/
$this->redirect('myview/admin');
else
$this->redirect(Yii::app()->user->returnUrl);

}


enjoy!

Arvind
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users