public function actionIndex(User $user, Session $session)
 {
     $placeholders = [];
     if ($session->hasFlash($this->keySessionFlash)) {
         $placeholders['content'] = i18n::t('successActivate');
         return $this->render('success', $placeholders);
     } elseif ($user->isGuest() && ($users = Users::activate(Request::get('token')))) {
         // auto-login
         $user->addMulti($users->toArray(['id', 'username', 'url']));
         $user->login();
         $session->setFlash($this->keySessionFlash);
         $this->response->redirect(Url::set()->removeAllArgs()->getAbsoluteUrl(true))->send(true);
         return null;
     }
     return $this->notPage('@frontend.views/layouts/notPage');
 }
Example #2
0
 /**
  * Checks a role (RBAC).
  * @param array $roles
  * @return bool
  * @throws FilterException
  */
 protected function matchRole(array $roles)
 {
     if (!$this->user instanceof \rock\user\User) {
         throw new FilterException(FilterException::UNKNOWN_CLASS, ['class' => '\\rock\\user\\User']);
     }
     // all roles
     if (in_array('*', $roles)) {
         return true;
     } elseif (in_array('?', $roles) && $this->user->isGuest()) {
         return true;
         // Authenticated
     } elseif (in_array('@', $roles) && !$this->user->isGuest()) {
         return true;
     }
     foreach ($roles as $role) {
         if (!$this->user->check($role)) {
             $this->sendHeaders();
             return false;
         }
     }
     return true;
 }