Ejemplo n.º 1
0
 public function auth()
 {
     $client_id = $this->input->get('clent_id');
     $application = new Application();
     $application->client_id = $client_id;
     $application->get();
     if (!$application->exists()) {
         $data['title'] = 'Auth Page';
         $data['content'] = 'oauth/noapplication';
         $this->load->view('master', $data);
     } elseif (!$this->user_id) {
         $redirect = 'users/login?redirect_url=oauth/auth?client_id=' . $application->id;
         redirect($redirect);
     } elseif ($this->input->post()) {
         $allow = $this->input->post('allow');
         if ($allow) {
             $user = new User($this->user_id);
             $existing_token = new Token();
             $existing_token->where('user_id', $user->id);
             $existing_token->where('application_id', $application->id);
             $existing_token->get();
             if ($existing_token->exists()) {
                 $existing_token->delete();
             }
             $token = $this->generate_token();
             $token->save(array($application, $user));
             die;
             echo 'here';
         }
     } else {
         $this->load->helper('form');
         $data['application'] = array('id' => $application->id, 'name' => $application->name, 'client_id' => $application->client_id, 'client_secret' => $application->client_secret, 'redirect_url' => $application->redirect_url);
         $data['title'] = 'Auth Page';
         $data['content'] = 'oauth/authorize';
         $this->load->view('master', $data);
     }
 }
Ejemplo n.º 2
0
 function testDelete()
 {
     $patron_id = 1;
     $menu_id = 2;
     $sender_id = 3;
     $test_token = new Token($patron_id, $menu_id, $sender_id);
     $test_token->save();
     $patron_id2 = 4;
     $menu_id2 = 5;
     $sender_id2 = 6;
     $test_token2 = new Token($patron_id2, $menu_id2, $sender_id2);
     $test_token2->save();
     $test_token->delete();
     $result = Token::getAll();
     $this->assertEquals([$test_token2], $result);
 }
Ejemplo n.º 3
0
 /**
  * Revoke specified OAuth token
  *
  * Revokes the authorization token specified by $token_key.
  * Throws exceptions in case of error.
  *
  * @param string $token_key The token to be revoked
  *
  * @access public
  **/
 public function revoke_token($token_key)
 {
     $rt = new Token();
     $rt->tok = $token_key;
     $rt->type = 0;
     $rt->state = 0;
     if (!$rt->find(true)) {
         throw new Exception('Tried to revoke unknown token');
     }
     if (!$rt->delete()) {
         throw new Exception('Failed to delete revoked token');
     }
 }
 /**
  * Revoke specified access token
  *
  * Revokes the token specified by $token_key.
  * Throws exceptions in case of error.
  *
  * @param string $token_key the token to be revoked
  * @param int    $type      type of token (0 = req, 1 = access)
  *
  * @access public
  *
  * @return void
  */
 public function revoke_token($token_key, $type = 0)
 {
     $rt = new Token();
     $rt->tok = $token_key;
     $rt->type = $type;
     $rt->state = 0;
     if (!$rt->find(true)) {
         // TRANS: Exception thrown when an attempt is made to revoke an unknown token.
         throw new Exception(_('Tried to revoke unknown token.'));
     }
     if (!$rt->delete()) {
         // TRANS: Exception thrown when an attempt is made to remove a revoked token.
         throw new Exception(_('Failed to delete revoked token.'));
     }
 }
Ejemplo n.º 5
0
 function _deleteTokens()
 {
     $token = new Token();
     $token->consumer_key = $this->consumer_key;
     $token->delete();
 }
 /**
  * Cancel a subscription
  *
  */
 function cancel($subscriber, $other)
 {
     if (!self::exists($subscriber, $other)) {
         throw new Exception(_('Not subscribed!'));
     }
     // Don't allow deleting self subs
     if ($subscriber->id == $other->id) {
         throw new Exception(_('Couldn\'t delete self-subscription.'));
     }
     if (Event::handle('StartUnsubscribe', array($subscriber, $other))) {
         $sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id, 'subscribed' => $other->id));
         // note we checked for existence above
         assert(!empty($sub));
         // @todo: move this block to EndSubscribe handler for
         // OMB plugin when it exists.
         if (!empty($sub->token)) {
             $token = new Token();
             $token->tok = $sub->token;
             if ($token->find(true)) {
                 $result = $token->delete();
                 if (!$result) {
                     common_log_db_error($token, 'DELETE', __FILE__);
                     throw new Exception(_('Couldn\'t delete subscription OMB token.'));
                 }
             } else {
                 common_log(LOG_ERR, "Couldn't find credentials with token {$token->tok}");
             }
         }
         $result = $sub->delete();
         if (!$result) {
             common_log_db_error($sub, 'DELETE', __FILE__);
             throw new Exception(_('Couldn\'t delete subscription.'));
         }
         self::blow('user:notices_with_friends:%d', $subscriber->id);
         $subscriber->blowSubscriptionsCount();
         $other->blowSubscribersCount();
         Event::handle('EndUnsubscribe', array($subscriber, $other));
     }
     return;
 }
Ejemplo n.º 7
0
 /**
  * Remove old OMB subscription tokens
  *
  * @param User    $user     subscriber
  * @param Profile $other    subscribee
  * @return hook return value
  */
 function onEndUnsubscribe($profile, $other)
 {
     $sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id, 'subscribed' => $other->id));
     if (!empty($sub->token)) {
         $token = new Token();
         $token->tok = $sub->token;
         if ($token->find(true)) {
             $result = $token->delete();
             if (!$result) {
                 common_log_db_error($token, 'DELETE', __FILE__);
                 throw new Exception(_m('Could not delete subscription OMB token.'));
             }
         } else {
             common_log(LOG_ERR, "Couldn't find credentials with token {$token->tok}", __FILE__);
         }
     }
     return true;
 }
Ejemplo n.º 8
0
 private function delete_update_token()
 {
     $this->token->delete();
 }
Ejemplo n.º 9
0
 /**
  * Account logout
  * @param token
  * @return object{status}
  */
 public function logout_post()
 {
     $response = new stdClass();
     $token_entry = new Token();
     $token_entry->get_by_valid_token($this->post('token'))->get();
     if ($token_entry->exists()) {
         $token_entry->delete();
         $response->status = true;
     } else {
         $response->status = false;
         $response->error = 'Token not found or session expired';
     }
     $this->response($response);
 }
Ejemplo n.º 10
0
 /**
  * @group   ecommerce
  * @group   3dsecure
  * @expectedException         Everypay\Exception\RuntimeException
  * @expectedExceptionMessage  Resource Tokens does not support method Everypay\Token::delete
  */
 public function testTokensDelete()
 {
     //applicable both in local and remote mode
     $token = 'ctn_oLyYPaymB2AozoABZYYHnb3g';
     $payment = Token::delete($token);
 }
Ejemplo n.º 11
0
    throw new \Exception('token dont exist');
}
if ($session->id && $user_id != $session->id) {
    throw new \Exception('HACKER stop doing that!');
}
if ($session->id) {
    echo '<div class="critical">You are already logged in! Are you sure you want to reset your password?</div>';
}
if (isset($_POST['reset_pwd']) && isset($_POST['reset_pwd2'])) {
    /// TODO reuse code from register user
    if ($_POST['reset_pwd'] == $_POST['reset_pwd2']) {
        UserHandler::setPassword($user_id, $_POST['reset_pwd']);
        $session->login($user->name, $_POST['reset_pwd']);
        echo '<div class="okay">Your password has been reset. You have been logged in.</div>';
        // delete consumed token
        Token::delete($user_id, 'activation_code');
        return;
    } else {
        $error->add('The passwords dont match');
    }
}
echo $error->render(true);
echo 'Reset password for user <b>' . $user->name . '</b>';
$header->registerJsFunction('function validate_reset_pwd_form(frm)' . '{' . 'if (!frm.reset_pwd.value||!frm.reset_pwd2.value)' . 'return false;' . 'return true;' . '}');
//XXXX use XhtmlForm class, it needs a way to show the images first
echo xhtmlForm('reg_frm', '', '', '', 'return validate_reset_pwd_form(this);');
echo '<table cellpadding="2">';
echo '<tr><td>' . t('New password') . ':</td>' . '<td>' . xhtmlPassword('reset_pwd') . ' ' . xhtmlImage($page->getRelativeCoreDevUrl() . 'gfx/icon_keys.png', t('Password')) . '</td>' . '</tr>';
echo '<tr><td>' . t('Again') . ':</td>' . '<td>' . xhtmlPassword('reset_pwd2') . ' ' . xhtmlImage($page->getRelativeCoreDevUrl() . 'gfx/icon_keys.png', t('Repeat password')) . '</td>' . '</tr>';
echo '</table><br/>';
echo xhtmlSubmit('Reset password', 'button', 'font-weight:bold');
 /**
  * @expectedException         Everypay\Exception\RuntimeException
  * @expectedExceptionMessage  Resource Tokens does not support method Everypay\Token::delete
  */
 public function testTokensDelete()
 {
     $token = 'ctn_oLyYPaymB2AozoABZYYHnb3g';
     $payment = Token::delete($token);
 }