diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index a9632879..6a670f71 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -3,47 +3,27 @@ namespace App\Http\Middleware; use Closure; -use Illuminate\Contracts\Auth\Guard; +use Illuminate\Support\Facades\Auth; class Authenticate { - /** - * The Guard implementation. - * - * @var Guard - */ - protected $auth; - - /** - * Create a new filter instance. - * - * @param Guard $auth - * - * @return void - */ - public function __construct(Guard $auth) - { - $this->auth = $auth; - } - /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * + * @param \Illuminate\Http\Request $request + * @param \Closure $next + * @param string|null $guard * @return mixed */ - public function handle($request, Closure $next) + public function handle($request, Closure $next, $guard = null) { - if ($this->auth->guest()) { - if ($request->ajax()) { + if (Auth::guard($guard)->guest()) { + if ($request->ajax() || $request->wantsJson()) { return response('Unauthorized.', 401); } else { return redirect()->guest('login'); } } - return $next($request); } -} +} \ No newline at end of file diff --git a/app/Http/routes.php b/app/Http/routes.php index 8c033c2e..43a9b9c0 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -652,20 +652,26 @@ Route::group(['middleware' => ['auth', 'first.run']], function () { }); }); -Route::post('queue/push', function () { - - // set_time_limit(300); - - return Queue::marshal(); -}); - Route::get('/', function () { - return Redirect::route('showSelectOrganiser'); }); Route::get('/terms_and_conditions', ['as' => 'termsAndConditions', function () { - -return 'TODO: add terms and cond'; -//return View::make('Public.Website.Terms_and_Cond'); + return 'TODO: add terms and cond'; }]); + +/* + * ------------------------------------- + * API Routes + * ------------------------------------- + */ +Route::group(['prefix' => 'api', 'middleware' => 'auth:api'], function () { + + Route::get('/', function() { + return response()->json([ + 'hello' => Auth::guard('api')->user()->full_name + ]); + }); + + +}); diff --git a/app/Models/User.php b/app/Models/User.php index b3505457..b353d5a2 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -152,6 +152,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon static::creating(function ($user) { $user->confirmation_code = str_random(); + $user->api_key = str_random(60); }); } } diff --git a/database/migrations/2016_04_13_151256_add_api_key_users_table.php b/database/migrations/2016_04_13_151256_add_api_key_users_table.php new file mode 100644 index 00000000..addbcb2a --- /dev/null +++ b/database/migrations/2016_04_13_151256_add_api_key_users_table.php @@ -0,0 +1,31 @@ +string('api_token', 60)->unique()->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('api_token'); + }); + } +}