Development

/plugins/sfDoctrineGuardLoginHistoryPlugin/trunk/lib/model/doctrine/PluginUserLoginHistoryTable.class.php

You must first sign up to be able to contribute.

root/plugins/sfDoctrineGuardLoginHistoryPlugin/trunk/lib/model/doctrine/PluginUserLoginHistoryTable.class.php

Revision 30612, 1.3 kB (checked in by caefer, 7 years ago)

imported sources from github

Line 
1 <?php
2
3 /**
4  * PluginUserLoginHistoryTable
5  *
6  * This class has been auto-generated by the Doctrine ORM Framework
7  */
8 class PluginUserLoginHistoryTable extends Doctrine_Table
9 {
10     /**
11      * Returns an instance of this class.
12      *
13      * @return object PluginUserLoginHistoryTable
14      */
15     public static function getInstance()
16     {
17         return Doctrine_Core::getTable('PluginUserLoginHistory');
18     }
19
20   static public function writeLoginHistory(sfEvent $event)
21   {
22     $sessionUser = $event->getSubject();
23     $params = $event->getParameters();
24     if(true === $params['authenticated'])
25     {
26       $userId = $sessionUser->getGuardUser()->id;
27       $sessionUser->setAttribute('user_id', $userId, 'sfDoctrineGuardLoginHistoryPlugin');
28       self::createHistoryEntry('login', $userId);
29     }
30     else
31     {
32       $userId = $sessionUser->getAttributeHolder()->remove('user_id', null, 'sfDoctrineGuardLoginHistoryPlugin');
33       self::createHistoryEntry('logout', $userId);
34     }
35   }
36
37   protected static function createHistoryEntry($state, $userId)
38   {
39     $history = new UserLoginHistory();
40     $history->state = $state;
41     $history->user_id = $userId;
42     $history->ip = getenv('HTTP_X_FORWARDED_FOR') ? getenv('HTTP_X_FORWARDED_FOR') : getenv('REMOTE_ADDR');
43     $history->save();
44   }
45 }
46
Note: See TracBrowser for help on using the browser.