示例#1
0
 public function testGetByIdAndSession()
 {
     $this->model->login = '******';
     $this->model->save();
     $this->model->updateLastActivity();
     $user = User::getByIdAndSession($this->model->id, \Bazalt\Session::getSessionId());
     $this->assertEquals($this->model->id, $user->id);
 }
 public function testGet()
 {
     \Bazalt\Auth::logout();
     $response = new \Bazalt\Rest\Response(200, ['guest_id' => Session::getSessionId(), 'is_guest' => 1, 'roles' => [], 'acl' => []]);
     $this->assertResponse('GET /auth/session', ['contentType' => 'application/json'], $response);
 }
示例#3
0
 public function updateLastActivity($time = null)
 {
     if ($time == null) {
         $time = time();
     }
     $q = SiteRefUser::select()->where('user_id = ?', $this->id)->andWhere('site_id = ?', \Bazalt\Site::getId());
     $activity = $q->fetch();
     if (!$activity) {
         $activity = new SiteRefUser();
         $activity->site_id = \Bazalt\Site::getId();
         $activity->user_id = $this->id;
     }
     $activity->session_id = \Bazalt\Session::getSessionId();
     $activity->last_activity = date('Y-m-d H:i:s', $time);
     $activity->save();
     ORM::update('Bazalt\\Auth\\Model\\User')->set('last_activity', date('Y-m-d H:i:s', $time))->where('id = ?', $this->id)->autoClearCache(false)->exec(false);
 }