Added api_token column to user table
Updated Authentication middleware to L5.2
This commit is contained in:
parent
a5a94790e7
commit
2df5d86a14
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddApiKeyUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('api_token', 60)->unique()->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('api_token');
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue