Exemplo n.º 1
0
 public function revoke_app()
 {
     $this->assertLoggedIn();
     $this->set('area', 'app');
     try {
         $token = new OAuthToken($this->args('id'));
         if (!$token->isHydrated()) {
             throw new Exception("This app does not exist.");
         }
         if ($token->get('type') == 2 && $token->get('user_id') != User::$me->id) {
             throw new Exception("You are not authorized to delete this app.");
         }
         $app = $token->getConsumer();
         if ($token->get('type') == 2) {
             $this->setTitle('Revoke App Permissions - ' . $app->getName());
         } else {
             $this->setTitle('Deny App - ' . $app->getName());
         }
         $this->set('token', $token);
         $this->set('app', $app);
         if ($this->args('submit')) {
             if ($token->get('type') == 2) {
                 Activity::log("removed the app named " . $app->getLink() . ".");
             } else {
                 Activity::log("denied the app named " . $app->getLink() . ".");
             }
             $token->delete();
             $this->forwardToUrl("/apps");
         }
     } catch (Exception $e) {
         $this->setTitle('Error');
         $this->set('megaerror', $e->getMessage());
     }
 }
Exemplo n.º 2
0
 public function revoke_app()
 {
     $this->assertLoggedIn();
     $this->set('area', 'app');
     try {
         $token = new OAuthToken($this->args('id'));
         if (!$token->isHydrated()) {
             throw new Exception("This app does not exist.");
         }
         /** @var User $user */
         $user = new User($token->get('user_id'));
         if ($user->isHydrated() && $user->id != User::$me->id) {
             throw new Exception("You are not authorized to delete this app.");
         }
         $form = new Form();
         $field = WarningField::name('warning');
         if ($token->isVerified()) {
             $this->setTitle('Revoke App Permissions - ' . $token->getName());
             $form->submitText = "Revoke App Permissions";
             $field->value("Are you sure you want to revoke access to this app? Any apps currently using these credentials to print will be broken");
         } else {
             $this->setTitle('Deny App - ' . $token->getName());
             $form->submitText = "Deny App";
             $field->value("Are you sure you want to deny access to this app?");
         }
         $form->add($field);
         $this->set('form', $form);
         if ($form->checkSubmitAndValidate($this->args())) {
             if ($token->isVerified()) {
                 Activity::log("removed the app named " . $token->getLink() . ".");
             } else {
                 Activity::log("denied the app named " . $token->getLink() . ".");
             }
             $token->delete();
             $this->forwardToUrl("/apps");
         }
     } catch (Exception $e) {
         $this->setTitle('Error');
         $this->set('megaerror', $e->getMessage());
     }
 }