예제 #1
0
파일: app.php 프로젝트: eric116/BotQueue
 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());
     }
 }