Yii Framework Forum: Logout All Users Connected - Yii Framework Forum

Jump to content

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

Logout All Users Connected Rate Topic: -----

#1 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 08 November 2012 - 04:02 AM

Hi,

I look for a way to logout all users connected to my website. I have some actions which could be required a user logout in order to avoid some errors when checking their session information. And to avoid these errors, a simple reconnection should be enough.
0

#2 User is offline   nkd 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 28-September 12

Posted 08 November 2012 - 05:34 AM

View PostZugluk, on 08 November 2012 - 04:02 AM, said:

Hi,

I look for a way to logout all users connected to my website. I have some actions which could be required a user logout in order to avoid some errors when checking their session information. And to avoid these errors, a simple reconnection should be enough.


If you have sessions stored in the database (you are using CDbHttpSession), then you can empty the session table. By default its name is YiiSession if I remember correctly.



0

#3 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 09 November 2012 - 03:44 AM

I saw there was a destroy() function for session, but I'm wondering if I call it it will destroy all active session. The question is more, how to have access to this session table.

I'm using CUserIdentity to create user at login, then I store some information with setState(). To collect information I use Yii::app()->user->getSomeThing() etc... Logout the user which click on is easy but my will is to be able to do it for every user connected... so I think it's like remove all session stored, but I didn't find how to do it.
0

#4 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 12 November 2012 - 04:57 AM

So, no way to force logout on all users connected ?
0

#5 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 12 November 2012 - 10:53 AM

Dear Zugluk

Kindly checkout whether the following would serve the purpose.

We are going to create two actions in SiteController.You can impose appropriate permissions on these two actions.

SiteController.php
public function actionMassLogout()
	
	{ 
             Yii::app()->setGlobalState('massLogout',true);
	     $this->redirect(array('site/index'));
        }
    
    public function actionAllowLogin()
	
	{ 
              Yii::app()->setGlobalState('massLogout',false);
              $this->redirect(array('site/index'));	
        }


You can paste the following code in header section in main layout file to know the current status.
if(Yii::app()->getGlobalState('massLogout') && (Yii::app()->user->name=='admin'))
	      echo "Site is on Mass Logout Mode";


Create a file maintanance.php in views/site/pages folder.
maintanance.php
<h2>The site is under active maintanance.Please login with your credentials later.</h2>


Now we have to create a behavior for our application.

applicationBehavior.php in components folder.
<?php
class applicationBehavior extends CBehavior
{	private $_owner;
	
	public function events() 
        {

                return  array(   
			     'onBeginRequest'=>'massLogout',	        
		        );
        }

        public function massLogout()
		
	{
            $owner=$this->_owner=$this->getOwner();	
            if($owner->getGlobalState('massLogout') && ($owner->user->name!=='admin'))
		{			
	             $owner->user->clearStates();
		     $owner->catchAllRequest=array('site/page','view'=>'maintanance');
							
		}	
			
	}
}


Attach this behavior as a property in main configuration file.
main.php
'behaviors'=>array(
'class'=>'application.components.applicationBehavior',
),


If the admin sets the state as massLogout, he is going to logout all the users excluding him.

After that every request is going to the default page.

The effect will not be perceived unless user registers a fresh request.

Here we have used runtime directory to save the massLogout status.

We can also use database tables to store the values

Regards.
0

#6 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 13 November 2012 - 08:32 AM

Hey seenivasa, thanks a lot for your answer. It helps a lot in my reflexion however it's not totally what I'm looking for.
The fact is that I don't want to create an "unavailable state" of my website. It's just that, for every page, I have a function which get some information of profiles of the current user. Every profiles are stored in session of the user when logging. Thus, when a user want to go on a page, I can accede to these information and use them.
Each of this profiles has name, and a user can belongs to several profiles. If the admin of the website decides to change the name, or delete for example, of one of these profiles, when we will use these profiles stored in his session, they risked to not exist anymore... so when my function will look for it, it will give an exception cause I search something that doesn't exist.

So my will would be to, when the admin change a profile, or delete one, to logout all users connected. Then they will have to login again and their session will be filled with new profiles existing.
0

#7 User is offline   Mohammad Tokallo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 25-June 12

Posted 19 December 2012 - 03:24 AM

Good tut
But Please Tell me How Can i Logout User After Changeing Password in System And showing Flash Messages so finally logout
0

#8 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 07 January 2013 - 08:55 AM

View PostMohammad Tokallo, on 19 December 2012 - 03:24 AM, said:

Good tut
But Please Tell me How Can i Logout User After Changeing Password in System And showing Flash Messages so finally logout



$this->redirect('/your/home/url/logout');
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