Exemple #1
0
 public function testInit()
 {
     $this->assertEquals(0, User::objects()->count());
     $this->assertEquals(0, Group::objects()->count());
     $this->assertEquals(0, Permission::objects()->count());
     $this->assertEquals(0, UserPermission::objects()->count());
     $this->assertEquals(0, GroupPermission::objects()->count());
     $this->assertEquals(0, Key::objects()->count());
     $this->assertEquals(0, Session::objects()->count());
 }
Exemple #2
0
 public static function recordActionInternal($owner, $text)
 {
     if ($owner->classNameShort() == UserLog::classNameShort() || $owner->classNameShort() == Session::classNameShort() || Mindy::app()->getUser()->is_staff === false) {
         return;
     } else {
         $url = method_exists($owner, 'getAbsoluteUrl') ? $owner->getAbsoluteUrl() : null;
         $message = strtr('{model} {url} ' . $text, ['{model}' => $owner->classNameShort()]);
         $app = Mindy::app();
         $module = $owner->getModule();
         UserLog::objects()->create(['user' => $app->getUser()->getIsGuest() ? null : $app->getUser(), 'module' => $owner->getModuleName(), 'model' => $owner->classNameShort(), 'url' => $url, 'ip' => $app->getUser()->getIp(), 'name' => (string) $owner, 'message' => $module->t($message, ['{url}' => $url ? "<a href='" . $owner->getAbsoluteUrl() . "'>" . (string) $owner . "</a>" : (string) $owner])]);
     }
 }
Exemple #3
0
 /**
  * Updates the current session id with a newly generated one.
  * Please refer to {@link http://php.net/session_regenerate_id} for more details.
  * @param boolean $deleteOldSession Whether to delete the old associated session file or not.
  * @since 1.1.8
  */
 public function regenerateID($deleteOldSession = false)
 {
     $oldID = $this->getId();
     // if no session is started, there is nothing to regenerate
     if (empty($oldID)) {
         return;
     }
     parent::regenerateID(false);
     $newID = $this->getId();
     $session = Session::objects()->filter(['id' => $oldID])->get();
     if ($session !== null) {
         if ($deleteOldSession) {
             $session->objects()->update(['id' => $newID]);
         } else {
             $session->id = $newID;
             $session->save();
         }
     } else {
         $session = new Session(['id' => $newID, 'data' => '']);
         $session->save();
     }
 }
Exemple #4
0
 public function login(Model $model, $duration = null)
 {
     $time = $model->getDb()->getQueryBuilder()->convertToDateTime(time());
     $model->last_login = $time;
     $model->save(['last_login']);
     if ($duration === null) {
         $duration = Mindy::app()->getModule('User')->loginDuration;
     }
     $this->saveToCookie($model, $duration);
     if ($this->absoluteAuthTimeout) {
         $this->getStorage()->add(self::AUTH_ABSOLUTE_TIMEOUT_VAR, time() + $this->absoluteAuthTimeout);
     }
     $model->setIsGuest(false);
     $this->setModel($model);
     $sessionId = Mindy::app()->session->getId();
     $session = Session::objects()->get(['id' => $sessionId]);
     if ($session) {
         $session->user = $model;
         $session->save();
     }
     $this->getEventManager()->send($this, 'onAuth', $model);
     if (class_exists('\\Modules\\UserActions\\Models\\UserLog')) {
         \Modules\UserActions\Models\UserLog::objects()->create(['message' => UserModule::t('User <a href="{url}">{name}</a> logged in', ['{url}' => $model->getAbsoluteUrl(), '{name}' => (string) $model]), 'module' => $model->getModuleName(), 'ip' => $model->getIp(), 'user' => $model]);
     }
     return !$this->getIsGuest();
 }
Exemple #5
0
 public static function render()
 {
     echo self::renderTemplate("core/debug_panel.html", ['memory_peak' => self::bytesToSize(memory_get_peak_usage()), 'sessions' => Session::objects()->count()]);
 }
 /**
  * Session GC (garbage collection) handler.
  * Do not call this method directly.
  * @param integer $maxlifetime the number of seconds after which data will be seen as 'garbage' and cleaned up.
  * @return boolean whether session is GCed successfully
  */
 public function gc($maxlifetime)
 {
     Session::objects()->filter(['expire__lt' => time()])->delete();
     return true;
 }
Exemple #7
0
 /**
  * Get current user session model
  * @return Session
  */
 public function getSession()
 {
     return Session::objects()->notExpired()->latest()->get(['id' => Mindy::app()->session->getId()]);
 }