/**
  * @param Request $request
  * @throws \Mindy\Exception\HttpException
  */
 public function processRequest(Request $request)
 {
     if (Console::isCli() === false) {
         $authKey = $this->getToken($request);
         if (!empty($authKey)) {
             $key = Key::objects()->get(['key' => $authKey]);
             if ($key !== null) {
                 $user = $key->user;
                 $app = Mindy::app();
                 /** @var \Modules\Sites\SitesModule $siteModule */
                 $siteModule = $app->getModule('Sites');
                 if ($this->useSubDomains) {
                     $site = $siteModule->getSite();
                     if ($user && $user->is_active && ($site->id == $user->site_id || $user->is_superuser)) {
                         $app->auth->login($user);
                     }
                 } else {
                     if ($user && $user->is_active) {
                         $app->auth->login($user);
                         $siteModule->setSite($user->site);
                     }
                 }
             }
         }
     }
 }
Exemple #2
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());
 }
 protected function clearKeys(User $model)
 {
     Key::objects()->filter(['user' => $model])->delete();
 }