Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
11 changed files with 74 additions and 13 deletions
Showing only changes of commit 3cf753a707 - Show all commits

View File

@ -3,7 +3,7 @@
namespace Aviat\AnimeClient\Auth; namespace Aviat\AnimeClient\Auth;
use Aviat\Ion\Di\ContainerInterface; use Aviat\Ion\Di\ContainerInterface;
use Aviat\AnimeClient\Model\Anime as AnimeModel; use Aviat\AnimeClient\Model\API;
/** /**
* Hummingbird API Authentication * Hummingbird API Authentication
@ -24,7 +24,7 @@ class HummingbirdAuth {
* *
* @var Aura\Session\Segment * @var Aura\Session\Segment
*/ */
protected $session; protected $segment;
/** /**
* Constructor * Constructor
@ -34,32 +34,60 @@ class HummingbirdAuth {
public function __construct(ContainerInterface $container) public function __construct(ContainerInterface $container)
{ {
$this->setContainer($container); $this->setContainer($container);
$this->session = $container->get('session') $this->segment = $container->get('session')
->getSegment(__NAMESPACE__); ->getSegment(__NAMESPACE__);
$this->model = new AnimeModel($container); $this->model = new API($container);
} }
/** /**
* Make the appropriate authentication call, * Make the appropriate authentication call,
* and save the resulting auth token if successful * and save the resulting auth token if successful
* *
* @param string $username
* @param string $password * @param string $password
* @return boolean * @return boolean
*/ */
public function authenticate($username, $password) public function authenticate($password)
{ {
return $this->model->authenticate(); $username = $this->config->get('hummingbird_username');
$auth_token = $this->model->authenticate($username, $password);
if (FALSE !== $auth_token)
{
$this->segment->set('auth_token', $auth_token);
return TRUE;
}
return FALSE;
}
/**
* Check whether the current user is authenticated
*
* @return boolean
*/
public function is_authenticated()
{
return ($this->get_auth_token() !== FALSE);
}
/**
* Clear authentication values
*
* @return void
*/
public function log_out()
{
$this->segment->clear();
} }
/** /**
* Retrieve the authentication token from the session * Retrieve the authentication token from the session
* *
* @return string * @return string|false
*/ */
public function get_auth_token() public function get_auth_token()
{ {
return $this->session->get('auth_token'); return $this->segment->get('auth_token', FALSE);
} }
} }

View File

@ -136,4 +136,4 @@ class Anime extends BaseController {
$this->outputJSON($this->model->update($this->request->post->get())); $this->outputJSON($this->model->update($this->request->post->get()));
} }
} }
// End of AnimeController.php // End of AnimeController.php

View File

@ -4,10 +4,19 @@ namespace Aviat\AnimeClient\Helper;
use Aviat\AnimeClient\MenuGenerator; use Aviat\AnimeClient\MenuGenerator;
/**
* MenuGenerator helper wrapper
*/
class Menu { class Menu {
use \Aviat\Ion\Di\ContainerAware; use \Aviat\Ion\Di\ContainerAware;
/**
* Create the html for the selected menu
*
* @param string $menu_name
* @return string
*/
public function __invoke($menu_name) public function __invoke($menu_name)
{ {
$generator = new MenuGenerator($this->container); $generator = new MenuGenerator($this->container);

View File

@ -64,7 +64,7 @@ class API extends BaseModel {
* @codeCoverageIgnore * @codeCoverageIgnore
* @param string $username * @param string $username
* @param string $password * @param string $password
* @return bool * @return string|false
*/ */
public function authenticate($username, $password) public function authenticate($username, $password)
{ {
@ -77,8 +77,7 @@ class API extends BaseModel {
if ($result->getStatusCode() === 201) if ($result->getStatusCode() === 201)
{ {
$_SESSION['hummingbird_anime_token'] = $result->json(); return json_decode($result->getBody(), TRUE);
return TRUE;
} }
return FALSE; return FALSE;

View File

@ -88,6 +88,12 @@ class Manga extends API {
return $data; return $data;
} }
/**
* Retrieve the list from the hummingbird api
*
* @param string $status
* @return array
*/
private function _get_list_from_api($status = "All") private function _get_list_from_api($status = "All")
{ {

View File

@ -4,6 +4,9 @@ namespace Aviat\Ion;
use Aviat\Ion\Type\ArrayType; use Aviat\Ion\Type\ArrayType;
/**
* Wrapper to shortcut creating ArrayType objects
*/
trait ArrayWrapper { trait ArrayWrapper {
/** /**

View File

@ -2,6 +2,9 @@
namespace Aviat\Ion\Di; namespace Aviat\Ion\Di;
/**
* Trait implementation of ContainerAwareInterface
*/
trait ContainerAware { trait ContainerAware {
/** /**

View File

@ -2,6 +2,9 @@
namespace Aviat\Ion\Di; namespace Aviat\Ion\Di;
/**
* Interface for a class that is aware of the Di Container
*/
interface ContainerAwareInterface { interface ContainerAwareInterface {
/** /**

View File

@ -2,6 +2,9 @@
namespace Aviat\Ion\Di\Exception; namespace Aviat\Ion\Di\Exception;
/**
* Generic exception for Di Container
*/
class ContainerException class ContainerException
extends \Exception extends \Exception
implements \Interop\Container\Exception\ContainerException { implements \Interop\Container\Exception\ContainerException {

View File

@ -2,6 +2,10 @@
namespace Aviat\Ion\Di\Exception; namespace Aviat\Ion\Di\Exception;
/**
* Exception for Di Container when trying to access a
* key that doesn't exist in the container
*/
class NotFoundException class NotFoundException
extends ContainerException extends ContainerException
implements \Interop\Container\Exception\NotFoundException { implements \Interop\Container\Exception\NotFoundException {

View File

@ -4,6 +4,9 @@ namespace Aviat\Ion\Type;
use Stringy\Stringy; use Stringy\Stringy;
/**
* Wrapper around Stringy
*/
class StringType extends Stringy { class StringType extends Stringy {
} }