Migrate to Laravel 5.3

This commit is contained in:
Jonny Barnes 2016-09-06 16:40:39 +01:00
parent 579aee7a12
commit 577fae0540
33 changed files with 424 additions and 297 deletions

View file

@ -1,33 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
class Inspire extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'inspire';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Display an inspiring quote';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->comment(PHP_EOL.Inspiring::quote().PHP_EOL);
}
}

View file

@ -13,7 +13,7 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
// Commands\Inspire::class,
//
];
/**
@ -27,4 +27,14 @@ class Kernel extends ConsoleKernel
// $schedule->command('inspire')
// ->hourly();
}
/**
* Register the Closure based commands for the application.
*
* @return void
*/
protected function commands()
{
require base_path('routes/console.php');
}
}

View file

@ -1,8 +0,0 @@
<?php
namespace App\Events;
abstract class Event
{
//
}

View file

@ -3,12 +3,8 @@
namespace App\Exceptions;
use Exception;
use Illuminate\Validation\ValidationException;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException;
use Symfony\Component\Debug\Exception\FlattenException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
@ -19,10 +15,12 @@ class Handler extends ExceptionHandler
* @var array
*/
protected $dontReport = [
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
\Illuminate\Auth\AuthenticationException::class,
\Illuminate\Auth\Access\AuthorizationException::class,
\Symfony\Component\HttpKernel\Exception\HttpException::class,
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
\Illuminate\Session\TokenMismatchException::class,
\Illuminate\Validation\ValidationException::class,
];
/**
@ -30,38 +28,39 @@ class Handler extends ExceptionHandler
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exc
* @param \Exception $exception
* @return void
*/
public function report(Exception $exc)
public function report(Exception $exception)
{
parent::report($exc);
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exc
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exc)
public function render($request, Exception $exception)
{
if (config('app.debug')) {
return $this->renderExceptionWithWhoops($exc);
}
return parent::render($request, $exception);
}
if ($exc instanceof ModelNotFoundException) {
$exc = new NotFoundHttpException($exc->getMessage(), $exc);
/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
if ($exc instanceof TokenMismatchException) {
return redirect()->back()
->withInput($request->except('password', '_token'))
->withErrors('Validation Token has expired. Please try again', 'csrf');
}
return parent::render($request, $exc);
return redirect()->guest('login');
}
/**
@ -70,7 +69,7 @@ class Handler extends ExceptionHandler
* @param \Exception $exc
* @return \Illuminate\Http\Response
*/
protected function renderExceptionWithWhoops(Exception $exc)
protected function renderExceptionWithWhoops(Exception $exception)
{
$whoops = new \Whoops\Run;
$handler = new \Whoops\Handler\PrettyPageHandler();
@ -79,7 +78,7 @@ class Handler extends ExceptionHandler
});
$whoops->pushHandler($handler);
$flattened = FlattenException::create($exc);
$flattened = FlattenException::create($exception);
return new \Illuminate\Http\Response(
$whoops->handleException($exc),

View file

@ -0,0 +1,32 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
}

View file

@ -5,39 +5,38 @@ namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Illuminate\Foundation\Auth\RegistersUsers;
class AuthController extends Controller
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
use RegistersUsers;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/';
protected $redirectTo = '/home';
/**
* Create a new authentication controller instance.
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
$this->middleware('guest');
}
/**

View file

@ -5,7 +5,7 @@ namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class PasswordController extends Controller
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
@ -21,12 +21,12 @@ class PasswordController extends Controller
use ResetsPasswords;
/**
* Create a new password controller instance.
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware());
$this->middleware('guest');
}
}

View file

@ -6,9 +6,8 @@ use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
class Controller extends BaseController
{
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

View file

@ -29,11 +29,13 @@ class Kernel extends HttpKernel
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\LinkHeadersMiddleware::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
@ -47,7 +49,7 @@ class Kernel extends HttpKernel
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'myauth' => \App\Http\Middleware\MyAuthMiddleware::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,

View file

@ -1,30 +0,0 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class Authenticate
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->guest()) {
if ($request->ajax() || $request->wantsJson()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('login');
}
}
return $next($request);
}
}

View file

@ -1,10 +0,0 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
abstract class Request extends FormRequest
{
//
}

View file

@ -1,150 +0,0 @@
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::group(['domain' => config('url.longurl')], function () {
//Static homepage
Route::get('/', function () {
return view('homepage');
});
//Static project page
Route::get('projects', function () {
return view('projects');
});
//The login routes to get authe'd for admin
Route::get('login', ['as' => 'login', function () {
return view('login');
}]);
Route::post('login', 'AuthController@login');
//Admin pages grouped for filter
Route::group(['middleware' => 'myauth'], function () {
Route::get('admin', 'AdminController@showWelcome');
//Articles
Route::get('admin/blog/new', 'ArticlesAdminController@newArticle');
Route::get('admin/blog/edit', 'ArticlesAdminController@listArticles');
Route::get('admin/blog/edit/{id}', 'ArticlesAdminController@editArticle');
Route::get('admin/blog/delete/{id}', 'ArticlesAdminController@deleteArticle');
Route::post('admin/blog/new', 'ArticlesAdminController@postNewArticle');
Route::post('admin/blog/edit/{id}', 'ArticlesAdminController@postEditArticle');
Route::post('admin/blog/delete/{id}', 'ArticlesAdminController@postDeleteArticle');
//Notes
Route::get('admin/note/new', 'NotesAdminController@newNotePage');
Route::get('admin/note/edit', 'NotesAdminController@listNotesPage');
Route::get('admin/note/edit/{id}', 'NotesAdminController@editNotePage');
Route::post('admin/note/new', 'NotesAdminController@createNote');
Route::post('admin/note/edit/{id}', 'NotesAdminController@editNote');
//Tokens
Route::get('admin/tokens', 'TokensController@showTokens');
Route::get('admin/tokens/delete/{id}', 'TokensController@deleteToken');
Route::post('admin/tokens/delete/{id}', 'TokensController@postDeleteToken');
//Micropub Clients
Route::get('admin/clients', 'ClientsAdminController@listClients');
Route::get('admin/clients/new', 'ClientsAdminController@newClient');
Route::get('admin/clients/edit/{id}', 'ClientsAdminController@editClient');
Route::post('admin/clients/new', 'ClientsAdminController@postNewClient');
Route::post('admin/clients/edit/{id}', 'ClientsAdminController@postEditClient');
//Contacts
Route::get('admin/contacts/new', 'ContactsAdminController@newContact');
Route::get('admin/contacts/edit', 'ContactsAdminController@listContacts');
Route::get('admin/contacts/edit/{id}', 'ContactsAdminController@editContact');
Route::get('admin/contacts/edit/{id}/getavatar', 'ContactsAdminController@getAvatar');
Route::get('admin/contacts/delete/{id}', 'ContactsAdminController@deleteContact');
Route::post('admin/contacts/new', 'ContactsAdminController@postNewContact');
Route::post('admin/contacts/edit/{id}', 'ContactsAdminController@postEditContact');
Route::post('admin/contacts/delete/{id}', 'ContactsAdminController@postDeleteContact');
//Places
Route::get('admin/places/new', 'PlacesAdminController@newPlacePage');
Route::get('admin/places/edit', 'PlacesAdminController@listPlacesPage');
Route::get('admin/places/edit/{id}', 'PlacesAdminController@editPlacePage');
Route::post('admin/places/new', 'PlacesAdminController@createPlace');
Route::post('admin/places/edit/{id}', 'PlacesAdminController@editPlace');
});
//Blog pages using ArticlesController
Route::get('blog/s/{id}', 'ArticlesController@onlyIdInURL');
Route::get('blog/{year?}/{month?}', 'ArticlesController@showAllArticles');
Route::get('blog/{year}/{month}/{slug}', 'ArticlesController@singleArticle');
//micropub new notes page
//this needs to be first so `notes/new` doesn't match `notes/{id}`
Route::get('notes/new', 'MicropubClientController@newNotePage');
Route::post('notes/new', 'MicropubClientController@postNewNote');
//Notes pages using NotesController
Route::get('notes', 'NotesController@showNotes');
Route::get('note/{id}', 'NotesController@singleNoteRedirect');
Route::get('notes/{id}', 'NotesController@singleNote');
Route::get('notes/tagged/{tag}', 'NotesController@taggedNotes');
//indieauth
Route::any('beginauth', 'IndieAuthController@beginauth');
Route::get('indieauth', 'IndieAuthController@indieauth');
Route::post('api/token', 'IndieAuthController@tokenEndpoint');
Route::get('logout', 'IndieAuthController@indieauthLogout');
//micropub endoints
Route::post('api/post', 'MicropubController@post');
Route::get('api/post', 'MicropubController@getEndpoint');
//micropub refresh syndication targets
Route::get('refresh-syndication-targets', 'MicropubClientController@refreshSyndicationTargets');
//webmention
Route::get('webmention', function () {
return view('webmention-endpoint');
});
Route::post('webmention', 'WebMentionsController@receive');
//Contacts
Route::get('contacts', 'ContactsController@showAll');
Route::get('contacts/{nick}', 'ContactsController@showSingle');
//Places
Route::get('places', 'PlacesController@index');
Route::get('places/{slug}', 'PlacesController@show');
//Places micropub
Route::get('places/near/{lat}/{lng}', 'MicropubClientController@nearbyPlaces');
Route::post('places/new', 'MicropubClientController@postNewPlace');
Route::get('feed', 'ArticlesController@makeRSS');
});
//Short URL
Route::group(['domain' => config('url.shorturl')], function () {
Route::get('/', 'ShortURLsController@baseURL');
Route::get('@', 'ShortURLsController@twitter');
Route::get('+', 'ShortURLsController@googlePlus');
Route::get('α', 'ShortURLsController@appNet');
Route::get('{type}/{id}', 'ShortURLsController@expandType')->where(
[
'type' => '[bt]',
'id' => '[0-9A-HJ-NP-Z_a-km-z]+',
]
);
Route::get('h/{id}', 'ShortURLsController@redirect');
Route::get('{id}', 'ShortURLsController@oldRedirect')->where(
[
'id' => '[0-9A-HJ-NP-Z_a-km-z]{4}',
]
);
});

View file

@ -1 +0,0 @@

View file

@ -1 +0,0 @@

View file

@ -2,7 +2,7 @@
namespace App\Providers;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
@ -19,12 +19,11 @@ class AuthServiceProvider extends ServiceProvider
/**
* Register any application authentication / authorization services.
*
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
* @return void
*/
public function boot(GateContract $gate)
public function boot()
{
$this->registerPolicies($gate);
$this->registerPolicies();
//
}

View file

@ -0,0 +1,26 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes();
/*
* Authenticate the user's personal channel...
*/
Broadcast::channel('App.User.*', function ($user, $userId) {
return (int) $user->id === (int) $userId;
});
}
}

View file

@ -2,7 +2,7 @@
namespace App\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
@ -21,12 +21,11 @@ class EventServiceProvider extends ServiceProvider
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function boot(DispatcherContract $events)
public function boot()
{
parent::boot($events);
parent::boot();
//
}

View file

@ -2,7 +2,7 @@
namespace App\Providers;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
@ -22,22 +22,23 @@ class RouteServiceProvider extends ServiceProvider
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
public function boot()
{
//
parent::boot($router);
parent::boot();
}
/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function map(Router $router)
public function map()
{
$this->mapWebRoutes($router);
$this->mapWebRoutes();
$this->mapApiRoutes();
//
}
@ -47,15 +48,33 @@ class RouteServiceProvider extends ServiceProvider
*
* These routes all receive session state, CSRF protection, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
protected function mapWebRoutes(Router $router)
protected function mapWebRoutes()
{
$router->group([
'namespace' => $this->namespace, 'middleware' => 'web',
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require app_path('Http/routes.php');
require base_path('routes/web.php');
});
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::group([
'middleware' => 'api',
'namespace' => $this->namespace,
'prefix' => 'api'
], function ($router) {
require base_path('routes/api.php');
});
}
}

View file

@ -2,10 +2,13 @@
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*