Browse Source

add a re-send button

closes #5
main
Aaron Parecki 6 years ago
parent
commit
9fc6042d44
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 35 additions and 3 deletions
  1. +10
    -3
      controllers/API.php
  2. +9
    -0
      controllers/Controller.php
  3. +16
    -0
      views/webmention-details.php

+ 10
- 3
controllers/API.php View File

@ -41,7 +41,7 @@ class API {
# Require the token or csrf parameter # Require the token or csrf parameter
if($csrf=$request->get('_csrf')) { if($csrf=$request->get('_csrf')) {
session_start(); session_start();
if($csrf != $_SESSION['_csrf']) {
if(!isset($_SESSION['_csrf']) || $csrf != $_SESSION['_csrf']) {
return $this->respond($response, 401, [ return $this->respond($response, 401, [
'error' => 'invalid_csrf_token', 'error' => 'invalid_csrf_token',
'error_description' => 'An error occurred. Make sure you have only one tab open.', 'error_description' => 'An error occurred. Make sure you have only one tab open.',
@ -52,7 +52,7 @@ class API {
'error' => 'authentication_required', 'error' => 'authentication_required',
'error_description' => 'A token is required to use the API' 'error_description' => 'A token is required to use the API'
]); ]);
} else {
# Verify the token is valid # Verify the token is valid
$role = ORM::for_table('roles')->where('token', $token)->find_one(); $role = ORM::for_table('roles')->where('token', $token)->find_one();
@ -219,7 +219,14 @@ class API {
]; ];
$headers = []; $headers = [];
} }
return $this->respond($response, 201, $body, $headers);
if($request->get('_redirect') == 'true') {
$response->setStatusCode(302);
$response->headers->set('Location', $body['location'].'/details');
return $response;
} else {
return $this->respond($response, 201, $body, $headers);
}
} }
public function superfeedr_tracker(Request $request, Response $response, $args) { public function superfeedr_tracker(Request $request, Response $response, $args) {

+ 9
- 0
controllers/Controller.php View File

@ -242,6 +242,14 @@ class Controller {
$site = ORM::for_table('sites')->where_id_is($webmention->site_id)->find_one(); $site = ORM::for_table('sites')->where_id_is($webmention->site_id)->find_one();
// Find the user's role for this site
if($site && $this->_user()) {
$role = ORM::for_table('roles')
->where('site_id', $site['id'])
->where('user_id', $this->_user()['id'])
->find_one();
}
$statuses = ORM::for_table('webmention_status')->where('webmention_id', $webmention->id)->order_by_desc('created_at')->find_many(); $statuses = ORM::for_table('webmention_status')->where('webmention_id', $webmention->id)->order_by_desc('created_at')->find_many();
if(count($statuses) == 0) { if(count($statuses) == 0) {
@ -256,6 +264,7 @@ class Controller {
'user' => $this->_user(), 'user' => $this->_user(),
'accounts' => $this->_accounts(), 'accounts' => $this->_accounts(),
'site' => $site, 'site' => $site,
'role' => isset($role) ? $role : false,
'webmention' => $webmention, 'webmention' => $webmention,
'statuses' => $statuses, 'statuses' => $statuses,
'icon' => $icon, 'icon' => $icon,

+ 16
- 0
views/webmention-details.php View File

@ -48,6 +48,22 @@
<td class="right"><?= $this->e($webmention->callback) ?></td> <td class="right"><?= $this->e($webmention->callback) ?></td>
</tr> </tr>
<? endif; ?> <? endif; ?>
<?php if($role && $status != 'pending'): ?>
<tr>
<td class="left">
</td>
<td class="right">
<form action="/webmention" method="post">
<input type="hidden" name="source" value="<?= $this->e($webmention->source) ?>">
<input type="hidden" name="target" value="<?= $this->e($webmention->target) ?>">
<input type="hidden" name="token" value="<?= $this->e($role->token) ?>">
<input type="hidden" name="_redirect" value="true">
<input type="submit" class="ui tiny button" value="Send Again">
</form>
</td>
</tr>
<?php endif ?>
</tbody></table> </tbody></table>
<h2>Details</h2> <h2>Details</h2>

Loading…
Cancel
Save