Make updating of anime list work
This commit is contained in:
parent
05912cd540
commit
dfe91d0f1c
@ -7,10 +7,10 @@
|
|||||||
<h2><?= $escape->html($name) ?></h2>
|
<h2><?= $escape->html($name) ?></h2>
|
||||||
<section class="media-wrap">
|
<section class="media-wrap">
|
||||||
<?php foreach($items as $item): ?>
|
<?php foreach($items as $item): ?>
|
||||||
<article class="media" id="a-<?= $item['id'] ?>">
|
<article class="media" id="<?= $item['anime']['slug'] ?>">
|
||||||
<?php /*if (is_logged_in()): ?>
|
<?php if ($auth->is_authenticated()): ?>
|
||||||
<button class="plus_one" hidden>+1 Episode</button>
|
<button class="plus_one" hidden>+1 Episode</button>
|
||||||
<?php endif*/ ?>
|
<?php endif ?>
|
||||||
<?= $helper->img($item['anime']['image']); ?>
|
<?= $helper->img($item['anime']['image']); ?>
|
||||||
<div class="name">
|
<div class="name">
|
||||||
<a href="<?= $escape->attr($item['anime']['url']) ?>">
|
<a href="<?= $escape->attr($item['anime']['url']) ?>">
|
||||||
@ -39,6 +39,6 @@
|
|||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</main>
|
</main>
|
||||||
<?php /*if (is_logged_in()): ?>
|
<?php if ($auth->is_authenticated()): ?>
|
||||||
<script src="<?= $config->asset_url('js.php?g=edit') ?>"></script>
|
<script src="<?= $urlGenerator->asset_url('js.php?g=edit') ?>"></script>
|
||||||
<?php endif*/ ?>
|
<?php endif ?>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<main>
|
<main>
|
||||||
<?= $message ?>
|
<?= $message ?>
|
||||||
<aside>
|
<aside>
|
||||||
<form method="post" action="<?= $urlGenerator->full_url('/login', $url_type) ?>">
|
<form method="post" action="<?= $urlGenerator->full_url($urlGenerator->path(), $url_type) ?>">
|
||||||
<dl>
|
<dl>
|
||||||
<?php /*<dt><label for="username">Username: </label></dt>
|
<?php /*<dt><label for="username">Username: </label></dt>
|
||||||
<dd><input type="text" id="username" name="username" required="required" /></dd>*/ ?>
|
<dd><input type="text" id="username" name="username" required="required" /></dd>*/ ?>
|
||||||
|
17
public/js/anime_edit.js
Normal file → Executable file
17
public/js/anime_edit.js
Normal file → Executable file
@ -1,7 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* Javascript for editing anime, if logged in
|
* Javascript for editing anime, if logged in
|
||||||
*/
|
*/
|
||||||
(function($, undefined){
|
(function($){
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
if (CONTROLLER !== "anime") return;
|
if (CONTROLLER !== "anime") return;
|
||||||
|
|
||||||
@ -12,7 +14,6 @@
|
|||||||
var self = this;
|
var self = this;
|
||||||
var this_sel = $(this);
|
var this_sel = $(this);
|
||||||
var parent_sel = $(this).closest("article");
|
var parent_sel = $(this).closest("article");
|
||||||
var self = this;
|
|
||||||
|
|
||||||
var watched_count = parseInt(parent_sel.find('.completed_number').text(), 10);
|
var watched_count = parseInt(parent_sel.find('.completed_number').text(), 10);
|
||||||
var total_count = parseInt(parent_sel.find('.total_number').text(), 10);
|
var total_count = parseInt(parent_sel.find('.total_number').text(), 10);
|
||||||
@ -20,7 +21,7 @@
|
|||||||
|
|
||||||
// Setup the update data
|
// Setup the update data
|
||||||
var data = {
|
var data = {
|
||||||
id: this_sel.parent('article').attr('id').replace('a-', ''),
|
id: this_sel.parent('article').attr('id'),
|
||||||
increment_episodes: true
|
increment_episodes: true
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -39,7 +40,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// okay, lets actually make some changes!
|
// okay, lets actually make some changes!
|
||||||
$.post(BASE_URL + 'update', data, function(res) {
|
$.ajax({
|
||||||
|
data: data,
|
||||||
|
dataType: 'json',
|
||||||
|
method: 'POST',
|
||||||
|
mimeType: 'application/json',
|
||||||
|
url: BASE_URL + CONTROLLER + '/update'
|
||||||
|
}).done(function(res) {
|
||||||
if (res.status === 'completed')
|
if (res.status === 'completed')
|
||||||
{
|
{
|
||||||
$(self).closest('article').hide();
|
$(self).closest('article').hide();
|
||||||
@ -47,6 +54,8 @@
|
|||||||
|
|
||||||
add_message('success', "Sucessfully updated " + title);
|
add_message('success', "Sucessfully updated " + title);
|
||||||
parent_sel.find('.completed_number').text(++watched_count);
|
parent_sel.find('.completed_number').text(++watched_count);
|
||||||
|
}).fail(function() {
|
||||||
|
add_message('error', "Failed to updated " + title);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class HummingbirdAuth {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function log_out()
|
public function logout()
|
||||||
{
|
{
|
||||||
$this->segment->clear();
|
$this->segment->clear();
|
||||||
}
|
}
|
||||||
|
@ -176,6 +176,49 @@ class Controller {
|
|||||||
], $view);
|
], $view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt login authentication
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function login_action()
|
||||||
|
{
|
||||||
|
$auth = $this->container->get('auth');
|
||||||
|
if ($auth->authenticate($this->request->post->get('password')))
|
||||||
|
{
|
||||||
|
$this->response->redirect->afterPost(
|
||||||
|
$this->urlGenerator->full_url('', $this->base_data['url_type'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->login("Invalid username or password.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deauthorize the current user
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function logout()
|
||||||
|
{
|
||||||
|
$auth = $this->container->get('auth');
|
||||||
|
$auth->logout();
|
||||||
|
|
||||||
|
$this->redirect_to_default();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 404 action
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function not_found()
|
||||||
|
{
|
||||||
|
$this->outputHTML('404', [
|
||||||
|
'title' => 'Sorry, page not found'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a message box to the page
|
* Add a message box to the page
|
||||||
*
|
*
|
||||||
|
@ -54,26 +54,48 @@ class Dispatcher extends RoutingBase {
|
|||||||
*/
|
*/
|
||||||
protected function generate_convention_routes()
|
protected function generate_convention_routes()
|
||||||
{
|
{
|
||||||
$this->output_routes[] = $this->router->add('index_redirect', '/')
|
$default_controller = $this->routes['convention']['default_controller'];
|
||||||
->setValues([
|
|
||||||
'controller' => 'Aviat\\AnimeClient\\Controller',
|
|
||||||
'action' => 'redirect_to_default'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->output_routes[] = $this->router->add('login', '/{controller}/login')
|
$this->output_routes[] = $this->router->addGet('login', '/{controller}/login')
|
||||||
->setValues([
|
->setValues([
|
||||||
'controller' => $this->routes['convention']['default_controller'],
|
'controller' => $default_controller,
|
||||||
'action' => 'login'
|
'action' => 'login'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->output_routes[] = $this->router->add('list', '/{controller}/{type}{/view}')
|
$this->output_routes[] = $this->router->addPost('login_post', '/{controller}/login')
|
||||||
->setValues([
|
->setValues([
|
||||||
'controller' => $this->routes['convention']['default_controller'],
|
'controller' => $default_controller,
|
||||||
|
'action' => 'login_action'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->output_routes[] = $this->router->addGet('logout', '/{controller}/logout')
|
||||||
|
->setValues([
|
||||||
|
'controller' => $default_controller,
|
||||||
|
'action' => 'logout'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->output_routes[] = $this->router->addPost('update', '/{controller}/update')
|
||||||
|
->setValues([
|
||||||
|
'controller' => $default_controller,
|
||||||
|
'action' => 'update'
|
||||||
|
])->setTokens([
|
||||||
|
'controller' => '[a-z_]+'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->output_routes[] = $this->router->addGet('list', '/{controller}/{type}{/view}')
|
||||||
|
->setValues([
|
||||||
|
'controller' => $default_controller,
|
||||||
'action' => $this->routes['convention']['default_method'],
|
'action' => $this->routes['convention']['default_method'],
|
||||||
])->setTokens([
|
])->setTokens([
|
||||||
'type' => '[a-z_]+',
|
'type' => '[a-z_]+',
|
||||||
'view' => '[a-z_]+'
|
'view' => '[a-z_]+'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->output_routes[] = $this->router->addGet('index_redirect', '/')
|
||||||
|
->setValues([
|
||||||
|
'controller' => 'Aviat\\AnimeClient\\Controller',
|
||||||
|
'action' => 'redirect_to_default'
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,6 +137,9 @@ class Dispatcher extends RoutingBase {
|
|||||||
public function __invoke($route = NULL)
|
public function __invoke($route = NULL)
|
||||||
{
|
{
|
||||||
$error_handler = $this->container->get('error-handler');
|
$error_handler = $this->container->get('error-handler');
|
||||||
|
$controller_name = $this->routes['convention']['default_controller'];
|
||||||
|
$action_method = $this->routes['convention']['404_method'];
|
||||||
|
$params = [];
|
||||||
|
|
||||||
if (is_null($route))
|
if (is_null($route))
|
||||||
{
|
{
|
||||||
@ -129,8 +154,15 @@ class Dispatcher extends RoutingBase {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$controller_name = $route->params['controller'];
|
if (isset($route->params['controller']))
|
||||||
$action_method = $route->params['action'];
|
{
|
||||||
|
$controller_name = $route->params['controller'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($route->params['action']))
|
||||||
|
{
|
||||||
|
$action_method = $route->params['action'];
|
||||||
|
}
|
||||||
|
|
||||||
if (is_null($controller_name))
|
if (is_null($controller_name))
|
||||||
{
|
{
|
||||||
@ -242,7 +274,14 @@ class Dispatcher extends RoutingBase {
|
|||||||
unset($route['path']);
|
unset($route['path']);
|
||||||
|
|
||||||
$controller_map = $this->get_controller_list();
|
$controller_map = $this->get_controller_list();
|
||||||
$controller_class = $controller_map[$route_type];
|
if (array_key_exists($route_type, $controller_map))
|
||||||
|
{
|
||||||
|
$controller_class = $controller_map[$route_type];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$controller_class = $this->routes['convention']['default_controller'];
|
||||||
|
}
|
||||||
|
|
||||||
// Prepend the controller to the route parameters
|
// Prepend the controller to the route parameters
|
||||||
$route['controller'] = $controller_class;
|
$route['controller'] = $controller_class;
|
||||||
|
@ -55,7 +55,7 @@ class Anime extends API {
|
|||||||
$data['auth_token'] = $auth->get_auth_token();
|
$data['auth_token'] = $auth->get_auth_token();
|
||||||
|
|
||||||
$response = $this->client->post("libraries/{$data['id']}", [
|
$response = $this->client->post("libraries/{$data['id']}", [
|
||||||
'body' => $data
|
'form_params' => $data
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return json_decode($response->getBody(), TRUE);
|
return json_decode($response->getBody(), TRUE);
|
||||||
|
@ -9,15 +9,15 @@ use Aviat\Ion\Friend;
|
|||||||
use Aviat\AnimeClient\Auth\HummingbirdAuth;
|
use Aviat\AnimeClient\Auth\HummingbirdAuth;
|
||||||
|
|
||||||
class HummingbirdAuthTest extends AnimeClient_TestCase {
|
class HummingbirdAuthTest extends AnimeClient_TestCase {
|
||||||
|
|
||||||
static $session;
|
static $session;
|
||||||
static $sessionHandler;
|
static $sessionHandler;
|
||||||
|
|
||||||
public static function setUpBeforeClass()
|
public static function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
self::$session = (new SessionFactory)->newInstance([]);
|
self::$session = (new SessionFactory)->newInstance([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@ -26,11 +26,11 @@ class HummingbirdAuthTest extends AnimeClient_TestCase {
|
|||||||
$this->auth = $friend;
|
$this->auth = $friend;
|
||||||
$this->container->set('session', self::$session);
|
$this->container->set('session', self::$session);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataAuthenticate()
|
public function dataAuthenticate()
|
||||||
{
|
{
|
||||||
$testToken = 'notReallyAValidTokenButThisIsATest';
|
$testToken = 'notReallyAValidTokenButThisIsATest';
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'successful auth call' => [
|
'successful auth call' => [
|
||||||
'username' => 'timw4mailtest',
|
'username' => 'timw4mailtest',
|
||||||
@ -54,7 +54,7 @@ class HummingbirdAuthTest extends AnimeClient_TestCase {
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataAuthenticate
|
* @dataProvider dataAuthenticate
|
||||||
*/
|
*/
|
||||||
@ -73,17 +73,17 @@ class HummingbirdAuthTest extends AnimeClient_TestCase {
|
|||||||
]);
|
]);
|
||||||
$model->__set('client', $client);
|
$model->__set('client', $client);
|
||||||
$this->auth->__set('model', $model);
|
$this->auth->__set('model', $model);
|
||||||
|
|
||||||
$actual = $this->auth->authenticate($password);
|
$actual = $this->auth->authenticate($password);
|
||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsAuthenticated()
|
public function testIsAuthenticated()
|
||||||
{
|
{
|
||||||
$data = $this->dataAuthenticate();
|
$data = $this->dataAuthenticate();
|
||||||
call_user_func_array([$this, 'testAuthenticate'], $data['successful auth call']);
|
call_user_func_array([$this, 'testAuthenticate'], $data['successful auth call']);
|
||||||
$this->assertTrue($this->auth->is_authenticated());
|
$this->assertTrue($this->auth->is_authenticated());
|
||||||
$this->auth->log_out();
|
$this->auth->logout();
|
||||||
$this->assertFalse($this->auth->is_authenticated());
|
$this->assertFalse($this->auth->is_authenticated());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user