diff --git a/src/Aviat/AnimeClient/Auth/HummingbirdAuth.php b/src/Aviat/AnimeClient/Auth/HummingbirdAuth.php index 2e24e643..9f3a6d1d 100644 --- a/src/Aviat/AnimeClient/Auth/HummingbirdAuth.php +++ b/src/Aviat/AnimeClient/Auth/HummingbirdAuth.php @@ -3,7 +3,7 @@ namespace Aviat\AnimeClient\Auth; use Aviat\Ion\Di\ContainerInterface; -use Aviat\AnimeClient\Model\Anime as AnimeModel; +use Aviat\AnimeClient\Model\API; /** * Hummingbird API Authentication @@ -24,7 +24,7 @@ class HummingbirdAuth { * * @var Aura\Session\Segment */ - protected $session; + protected $segment; /** * Constructor @@ -34,32 +34,60 @@ class HummingbirdAuth { public function __construct(ContainerInterface $container) { $this->setContainer($container); - $this->session = $container->get('session') + $this->segment = $container->get('session') ->getSegment(__NAMESPACE__); - $this->model = new AnimeModel($container); + $this->model = new API($container); } /** * Make the appropriate authentication call, * and save the resulting auth token if successful * - * @param string $username * @param string $password * @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 * - * @return string + * @return string|false */ public function get_auth_token() { - return $this->session->get('auth_token'); + return $this->segment->get('auth_token', FALSE); } } diff --git a/src/Aviat/AnimeClient/Controller/Anime.php b/src/Aviat/AnimeClient/Controller/Anime.php index 163c8788..1b718bb8 100644 --- a/src/Aviat/AnimeClient/Controller/Anime.php +++ b/src/Aviat/AnimeClient/Controller/Anime.php @@ -136,4 +136,4 @@ class Anime extends BaseController { $this->outputJSON($this->model->update($this->request->post->get())); } } -// End of AnimeController.php +// End of AnimeController.php \ No newline at end of file diff --git a/src/Aviat/AnimeClient/Helper/Menu.php b/src/Aviat/AnimeClient/Helper/Menu.php index c68e0492..9fb6b3a4 100644 --- a/src/Aviat/AnimeClient/Helper/Menu.php +++ b/src/Aviat/AnimeClient/Helper/Menu.php @@ -4,10 +4,19 @@ namespace Aviat\AnimeClient\Helper; use Aviat\AnimeClient\MenuGenerator; +/** + * MenuGenerator helper wrapper + */ class Menu { use \Aviat\Ion\Di\ContainerAware; + /** + * Create the html for the selected menu + * + * @param string $menu_name + * @return string + */ public function __invoke($menu_name) { $generator = new MenuGenerator($this->container); diff --git a/src/Aviat/AnimeClient/Model/API.php b/src/Aviat/AnimeClient/Model/API.php index 127d69b5..cb53aba1 100644 --- a/src/Aviat/AnimeClient/Model/API.php +++ b/src/Aviat/AnimeClient/Model/API.php @@ -64,7 +64,7 @@ class API extends BaseModel { * @codeCoverageIgnore * @param string $username * @param string $password - * @return bool + * @return string|false */ public function authenticate($username, $password) { @@ -77,8 +77,7 @@ class API extends BaseModel { if ($result->getStatusCode() === 201) { - $_SESSION['hummingbird_anime_token'] = $result->json(); - return TRUE; + return json_decode($result->getBody(), TRUE); } return FALSE; diff --git a/src/Aviat/AnimeClient/Model/Manga.php b/src/Aviat/AnimeClient/Model/Manga.php index d4b0bc44..da84888d 100644 --- a/src/Aviat/AnimeClient/Model/Manga.php +++ b/src/Aviat/AnimeClient/Model/Manga.php @@ -88,6 +88,12 @@ class Manga extends API { return $data; } + /** + * Retrieve the list from the hummingbird api + * + * @param string $status + * @return array + */ private function _get_list_from_api($status = "All") { diff --git a/src/Aviat/Ion/ArrayWrapper.php b/src/Aviat/Ion/ArrayWrapper.php index 2550b9af..bda13be2 100644 --- a/src/Aviat/Ion/ArrayWrapper.php +++ b/src/Aviat/Ion/ArrayWrapper.php @@ -4,6 +4,9 @@ namespace Aviat\Ion; use Aviat\Ion\Type\ArrayType; +/** + * Wrapper to shortcut creating ArrayType objects + */ trait ArrayWrapper { /** diff --git a/src/Aviat/Ion/Di/ContainerAware.php b/src/Aviat/Ion/Di/ContainerAware.php index 9b1d8784..7f02e7a6 100644 --- a/src/Aviat/Ion/Di/ContainerAware.php +++ b/src/Aviat/Ion/Di/ContainerAware.php @@ -2,6 +2,9 @@ namespace Aviat\Ion\Di; +/** + * Trait implementation of ContainerAwareInterface + */ trait ContainerAware { /** diff --git a/src/Aviat/Ion/Di/ContainerAwareInterface.php b/src/Aviat/Ion/Di/ContainerAwareInterface.php index b2a8f4fb..ae128681 100644 --- a/src/Aviat/Ion/Di/ContainerAwareInterface.php +++ b/src/Aviat/Ion/Di/ContainerAwareInterface.php @@ -2,6 +2,9 @@ namespace Aviat\Ion\Di; +/** + * Interface for a class that is aware of the Di Container + */ interface ContainerAwareInterface { /** diff --git a/src/Aviat/Ion/Di/Exception/ContainerException.php b/src/Aviat/Ion/Di/Exception/ContainerException.php index 39cf8b66..1e06911d 100644 --- a/src/Aviat/Ion/Di/Exception/ContainerException.php +++ b/src/Aviat/Ion/Di/Exception/ContainerException.php @@ -2,6 +2,9 @@ namespace Aviat\Ion\Di\Exception; +/** + * Generic exception for Di Container + */ class ContainerException extends \Exception implements \Interop\Container\Exception\ContainerException { diff --git a/src/Aviat/Ion/Di/Exception/NotFoundException.php b/src/Aviat/Ion/Di/Exception/NotFoundException.php index 1e33ba21..d8fe795a 100644 --- a/src/Aviat/Ion/Di/Exception/NotFoundException.php +++ b/src/Aviat/Ion/Di/Exception/NotFoundException.php @@ -2,6 +2,10 @@ namespace Aviat\Ion\Di\Exception; +/** + * Exception for Di Container when trying to access a + * key that doesn't exist in the container + */ class NotFoundException extends ContainerException implements \Interop\Container\Exception\NotFoundException { diff --git a/src/Aviat/Ion/Type/StringType.php b/src/Aviat/Ion/Type/StringType.php index e9bc4d1b..fb1af0fa 100644 --- a/src/Aviat/Ion/Type/StringType.php +++ b/src/Aviat/Ion/Type/StringType.php @@ -4,6 +4,9 @@ namespace Aviat\Ion\Type; use Stringy\Stringy; +/** + * Wrapper around Stringy + */ class StringType extends Stringy { }