Login/Logout

Permalink
I am coming to Concrete from the nightmarish world of Drupal and thus far I like what I see. One of things I have often had to do in Drupal while developing sites, adding modules etc is to go into the database and force a logout by clearing a few table entries.

I would like to be able to do the same thing while playing around with C5. Could someone tell me where C5 stores login information?

 
Mnkras replied on at Permalink Reply
Mnkras
You can use the API to log them out.
FredAt replied on at Permalink Reply
Ummm.... How do you mean? In Drupal I found it a whole lot easier to simply go and clear out a few database table fields.
Fernandos replied on at Permalink Reply
Fernandos
hi FredAt, you can have a loot athttp://www.concrete5.org/api/Users/User.html#logout... it contains following piece of code.

function logout() {
         // First, we check to see if we have any collection in edit mode
         $this->unloadCollectionEdit();
         @session_unset();
         @session_destroy();
         if ($_COOKIE['ccmUserHash']) {
            setcookie("ccmUserHash", "", 315532800, DIR_REL . '/');
         }
      }


There is no builtin way of logging a specific person out of concrete5 as far as I can tell.
Fernandos replied on at Permalink Best Answer Reply
Fernandos
..woah.. I still feel the vodka from yesterday..

Here is what I put together so far.. it's not working yet, but maybe you get the idea.


Basically I define an event that looks up if forced_logouts are enabled, and if yes we set an array with the userIDs to be looged off.

Lastly the user who should get logged off will get redirected to /login/logoff.

// in config/site_events.php
<?php defined('C5_EXECUTE') or die("Access Denied.");
Events::extend(
   'on_remote_logout',
   'UserController',
   'logoutByUserID',
   'controllers/user.php',
   $params = array()
);
?>
// extending the user model by a controller
<?php defined('C5_EXECUTE') or die("Access Denied.");
class UserController extends Controller {
  public function logoutByUserID($uID) {
      if($this->getCollectionAttributeValue('force_logout') == 1) {


I've tried to avoid sql queries, but I couldn't avoid it for the force_logout attribute checkup, but that's not required anyway, so you can remove it if you don't need a checkup.

Maybe it looks better in pastie then here:http://pastie.org/1422201

@andrew I wish something like this could make it's way into the core.

It's also possible to add a column in the users table for uIsOnline but you would need an insert and select for each user, causing stress on mysql.
FredAt replied on at Permalink Reply
Thank you!