aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCamil Staps2015-05-17 16:44:43 +0200
committerCamil Staps2015-05-17 16:44:43 +0200
commit1a115cfc53782fd51e55ed86671d10c7c2bb08b2 (patch)
treea880bcd98ed231dafcac199c57a8b4f2927de3a6 /src
parentSupport array as config.allowed_origin (diff)
First attempt
Diffstat (limited to 'src')
-rw-r--r--src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php83
-rw-r--r--src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php2
-rw-r--r--src/CamilStaps/BotleaguesApi/Database/User.php14
-rw-r--r--src/config/botleaguesapi.php (renamed from src/config/config.php)2
-rw-r--r--src/routes.php58
5 files changed, 86 insertions, 73 deletions
diff --git a/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php b/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php
index 76167e2..35826b9 100644
--- a/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php
+++ b/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php
@@ -5,7 +5,7 @@ use \Illuminate\Support\Facades\Request;
use \Illuminate\Support\ServiceProvider;
use \Illuminate\Support\Facades\App;
use \Illuminate\Support\Facades\Config;
-use \Dingo\Api\Facade\API;
+#use \Dingo\Api\Facade\API;
use Redirect;
use Response;
@@ -25,13 +25,21 @@ class BotleaguesApiServiceProvider extends ServiceProvider {
*/
public function boot()
{
- $this->package('camil-staps/botleagues-api', null, __DIR__.'/../..');
+ #$this->package('camil-staps/botleagues-api', null, __DIR__.'/../..');
+ #$this->loadAutoloader(base_path('vendor'));
+
+ $this->loadViewsFrom(__DIR__ . '/../../views', 'botleagues-api');
+ $this->publishes([ __DIR__ . '/../../views' => base_path('resources/view/vendor/botleagues-api')], 'views');
+
+ $this->publishes([ __DIR__ . '/../../config/botleaguesapi.php' => config_path('botleaguesapi.php')], 'config');
include __DIR__ . '/../../filters.php';
+
+ $api = app('api.router');
include __DIR__ . '/../../routes.php';
- // To allow loading API requests from the specified domain
- $allowed_origin = Config::get('config.allowed_origin');
+ // To allow loading API requests from the specified domain
+ $allowed_origin = config('botleaguesapi.allowed_origin');
if (is_array($allowed_origin)) {
$origin = Request::header('Origin');
if (in_array($origin, $allowed_origin)) {
@@ -44,9 +52,11 @@ class BotleaguesApiServiceProvider extends ServiceProvider {
}
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
header('Access-Control-Allow-Headers: Authorization');
+
+ var_dump(true);
$this->setupErrorHandlers();
- }
+ }
/**
* Register the service provider.
@@ -55,8 +65,7 @@ class BotleaguesApiServiceProvider extends ServiceProvider {
*/
public function register()
{
- $this->app->register('Dingo\Api\Provider\ApiServiceProvider');
- }
+ }
/**
* Get the services provided by the provider.
@@ -65,43 +74,43 @@ class BotleaguesApiServiceProvider extends ServiceProvider {
*/
public function provides()
{
- return array();
+ return array('CamilStaps\BotleaguesApi\BotleaguesApiServiceProvider');
}
/**
* Setup nice error handlers for exceptions and fatal errors
*/
private function setupErrorHandlers() {
- App::fatal(function($e) {
- return Response::make(
- ['error' => Config::get('app.debug') ? $e->getMessage() : "Internal error"],
- 500);
- });
+// App::fatal(function($e) {
+// return Response::make(
+// ['error' => config('app.debug') ? $e->getMessage() : "Internal error"],
+// 500);
+// });
- API::error(function(\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
- return Response::make(
- ['error' => 'Resource not found'],
- 404);
- });
- API::error(function(\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException $e) {
- return Response::make(
- ['error' => !Config::get('app.debug') || empty($e->getMessage()) ? 'Access denied' : $e->getMessage()],
- 404);
- });
- API::error(function(Exception\ValidationException $e) {
- return Response::make(
- [
- 'error' => $e->getMessage(),
- 'errors' => $e->errors
- ],
- 500);
- });
-
- API::error(function(\Exception $e) {
- return Response::make(
- ['error' => Config::get('app.debug') ? $e->getMessage() : "Internal error"],
- 500);
- });
+// API::error(function(\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
+// return Response::make(
+// ['error' => 'Resource not found'],
+// 404);
+// });
+// API::error(function(\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException $e) {
+// return Response::make(
+// ['error' => !config('app.debug') || empty($e->getMessage()) ? 'Access denied' : $e->getMessage()],
+// 404);
+// });
+// API::error(function(Exception\ValidationException $e) {
+// return Response::make(
+// [
+// 'error' => $e->getMessage(),
+// 'errors' => $e->errors
+// ],
+// 500);
+// });
+//
+// API::error(function(\Exception $e) {
+// return Response::make(
+// ['error' => Config::get('app.debug') ? $e->getMessage() : "Internal error"],
+// 500);
+// });
}
}
diff --git a/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php b/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php
index 40bc578..204df90 100644
--- a/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php
+++ b/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php
@@ -23,7 +23,7 @@ class PasswordReminder extends Model {
$this->valid_till = date("Y-m-d H:i:s", time() + 3600);
$user = User::find($this->userId);
- Mail::send('packages.camil-staps.botleagues-api.emails.auth.reminder', ['token' => $this->token], function($message) use ($user) {
+ Mail::send('botleagues-api::emails.auth.reminder', ['token' => $this->token], function($message) use ($user) {
$message->to($user->email, "User " . $user->id);
});
diff --git a/src/CamilStaps/BotleaguesApi/Database/User.php b/src/CamilStaps/BotleaguesApi/Database/User.php
index 383cc38..0af91c3 100644
--- a/src/CamilStaps/BotleaguesApi/Database/User.php
+++ b/src/CamilStaps/BotleaguesApi/Database/User.php
@@ -1,10 +1,14 @@
<?php
namespace CamilStaps\BotleaguesApi\Database;
-use Illuminate\Auth\Reminders\RemindableInterface;
-use Illuminate\Auth\UserInterface;
+use Illuminate\Auth\Authenticatable;
+use Illuminate\Auth\Passwords\CanResetPassword;
+use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
+use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
-class User extends Model implements UserInterface, RemindableInterface {
+class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
+
+ use Authenticatable, CanResetPassword;
protected $table = 'users';
protected $hidden = ['password', 'remember_token', 'api_key'];
@@ -65,11 +69,11 @@ class User extends Model implements UserInterface, RemindableInterface {
}
/**
- * Get the e-mail address where password reminders are sent.
+ * Get the e-mail address where password reset links are sent.
*
* @return string
*/
- public function getReminderEmail() {
+ public function getEmailForPasswordReset() {
return $this->email;
}
} \ No newline at end of file
diff --git a/src/config/config.php b/src/config/botleaguesapi.php
index cba8c73..1df9c5a 100644
--- a/src/config/config.php
+++ b/src/config/botleaguesapi.php
@@ -10,6 +10,6 @@ return [
],
- 'allowed_origin' => 'http://local.botleagues.camilstaps.nl'
+ 'allowed_origin' => ['http://botleagues.camilstaps.nl', 'https://botleagues.camilstaps.nl']
];
diff --git a/src/routes.php b/src/routes.php
index 6885443..def14d1 100644
--- a/src/routes.php
+++ b/src/routes.php
@@ -1,56 +1,56 @@
<?php
-Route::group(array('https'), function() {
+Route::group(array('https'), function() use ($api) {
- Route::api(['version' => 'v1', 'protected' => false], function () {
+ $api->version('v1', ['protected' => false], function ($api) {
- Route::resource('bot', 'CamilStaps\BotleaguesApi\Controllers\BotController',
+ $api->resource('bot', 'CamilStaps\BotleaguesApi\Controllers\BotController',
['only' => ['index','show']]);
-
- Route::resource('competition', 'CamilStaps\BotleaguesApi\Controllers\CompetitionController',
+
+ $api->resource('competition', 'CamilStaps\BotleaguesApi\Controllers\CompetitionController',
['only' => ['index','show']]);
-
- Route::resource('competition_type', 'CamilStaps\BotleaguesApi\Controllers\CompetitionTypeController',
+
+ $api->resource('competition_type', 'CamilStaps\BotleaguesApi\Controllers\CompetitionTypeController',
['only' => ['index','show']]);
-
- Route::resource('game', 'CamilStaps\BotleaguesApi\Controllers\GameController',
+
+ $api->resource('game', 'CamilStaps\BotleaguesApi\Controllers\GameController',
['only' => ['index','show']]);
-
- Route::resource('participant', 'CamilStaps\BotleaguesApi\Controllers\ParticipantController',
+
+ $api->resource('participant', 'CamilStaps\BotleaguesApi\Controllers\ParticipantController',
['only' => ['index','show']]);
-
- Route::resource('user', 'CamilStaps\BotleaguesApi\Controllers\UserController',
+
+ $api->resource('user', 'CamilStaps\BotleaguesApi\Controllers\UserController',
['only' => ['index','show','store']]);
- Route::resource('password_reminder', 'CamilStaps\BotleaguesApi\Controllers\PasswordReminderController',
+ $api->resource('password_reminder', 'CamilStaps\BotleaguesApi\Controllers\PasswordReminderController',
['only' => ['store']]);
});
- Route::api(['version' => 'v1', 'protected' => true, 'providers' => 'basic'], function () {
- Route::resource('user_token', 'CamilStaps\BotleaguesApi\Controllers\UserTokenController',
+ $api->version('v1', ['protected' => true, 'providers' => 'basic'], function ($api) {
+ $api->resource('user_token', 'CamilStaps\BotleaguesApi\Controllers\UserTokenController',
['only' => ['store']]);
});
- Route::api(['version' => 'v1', 'protected' => true, 'providers' => 'token'], function () {
-
- Route::resource('bot', 'CamilStaps\BotleaguesApi\Controllers\BotController',
+ $api->version('v1', ['protected' => true, 'providers' => 'token'], function ($api) {
+
+ $api->resource('bot', 'CamilStaps\BotleaguesApi\Controllers\BotController',
['except' => ['index', 'show', 'create','edit']]);
- Route::resource('user', 'CamilStaps\BotleaguesApi\Controllers\UserController',
+ $api->resource('user', 'CamilStaps\BotleaguesApi\Controllers\UserController',
['except' => ['index', 'show', 'create','edit','store']]);
-
- Route::resource('user_token', 'CamilStaps\BotleaguesApi\Controllers\UserTokenController',
+
+ $api->resource('user_token', 'CamilStaps\BotleaguesApi\Controllers\UserTokenController',
['only' => ['index', 'show']]);
- Route::group(array('before' => 'administrator'), function() {
-
- Route::resource('competition', 'CamilStaps\BotleaguesApi\Controllers\CompetitionController',
+ $api->group(array('before' => 'administrator'), function() use ($api) {
+
+ $api->resource('competition', 'CamilStaps\BotleaguesApi\Controllers\CompetitionController',
['except' => ['index', 'show', 'create', 'edit']]);
-
- Route::resource('competition_type', 'CamilStaps\BotleaguesApi\Controllers\CompetitionTypeController',
+
+ $api->resource('competition_type', 'CamilStaps\BotleaguesApi\Controllers\CompetitionTypeController',
['except' => ['index', 'show', 'create', 'edit']]);
-
- Route::resource('game', 'CamilStaps\BotleaguesApi\Controllers\GameController',
+
+ $api->resource('game', 'CamilStaps\BotleaguesApi\Controllers\GameController',
['except' => ['index', 'show', 'create','edit']]);
});