Skip to content

Commit

Permalink
migrate from Lumen to Laravel !
Browse files Browse the repository at this point in the history
  • Loading branch information
fr0tt committed Dec 20, 2022
1 parent a2b6c11 commit 377ed2c
Show file tree
Hide file tree
Showing 108 changed files with 13,452 additions and 4,932 deletions.
6 changes: 3 additions & 3 deletions app/Console/Commands/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Validator;
use App\User;
use App\Collection;
use App\Post;
use App\Models\User;
use App\Models\Collection;
use App\Models\Post;

class ExportCommand extends Command
{
Expand Down
8 changes: 3 additions & 5 deletions app/Console/Commands/FixPositionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\User;
use App\Post;
use App\Collection;
use App\Models\User;
use App\Models\Post;
use App\Models\Collection;
use stdClass;

class FixPositionCommand extends Command
Expand Down Expand Up @@ -60,7 +60,5 @@ public function handle()
}

$this->info('completed.');

}

}
15 changes: 7 additions & 8 deletions app/Console/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Hash;
use App\User;
use App\Models\User;
use App\Models\Post;

class InstallCommand extends Command
{
Expand Down Expand Up @@ -34,12 +35,13 @@ public function handle()
$createOnlyUser = $this->option('only-user');

$this->line('Initiate installation...');
$this->line(PHP_EOL);

if (!$createOnlyUser) {

$bar = $this->output->createProgressBar(3);
$bar->start();

// jwt secret
$this->call('jwt:secret');
$bar->advance();
Expand All @@ -48,10 +50,9 @@ public function handle()
$this->call('migrate');
$bar->advance();
$this->line(PHP_EOL);

}

// database seeding
// database seeding
$this->info('Create your Admin account:');
$username = $this->ask('Username', 'Admin');
$email = $this->ask('Email');
Expand Down Expand Up @@ -79,16 +80,14 @@ public function handle()
$user->permission = User::ADMIN;
$user->save();

(new \App\Post())->seedIntroData($user->id);
(new Post())->seedIntroData($user->id);

if (!$createOnlyUser) {

$bar->finish();

}

$this->line(PHP_EOL);
$this->info('Installation complete.');
}

}
111 changes: 0 additions & 111 deletions app/Console/Commands/KeyGenerateCommand.php

This file was deleted.

27 changes: 13 additions & 14 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,10 @@
namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\InstallCommand::class,
Commands\ExportCommand::class,
Commands\FixPositionCommand::class,
Commands\KeyGenerateCommand::class,
Commands\RunBackupCommand::class,
];

/**
* Define the application's command schedule.
*
Expand All @@ -30,4 +17,16 @@ protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run')->cron(config('benotes.backup_interval'));
}

/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');

require base_path('routes/console.php');
}
}
10 changes: 0 additions & 10 deletions app/Events/Event.php

This file was deleted.

16 changes: 0 additions & 16 deletions app/Events/ExampleEvent.php

This file was deleted.

34 changes: 20 additions & 14 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

namespace App\Exceptions;

use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Validation\ValidationException;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
* A list of the exception types that are not reported.
*
* @var array
* @var array<int, class-string<Throwable>>
*/
protected $dontReport = [
AuthorizationException::class,
Expand All @@ -24,18 +20,27 @@ class Handler extends ExceptionHandler
];

/**
* Report or log an exception.
* A list of the inputs that are never flashed for validation exceptions.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];


/**
* Register the exception handling callbacks for the application.
*
* @param \Throwable $exception
* @return void
*
* @throws \Exception
*/
public function report(Throwable $exception)
public function register()
{
parent::report($exception);
$this->reportable(function (Throwable $e) {
//
});
}

/**
Expand Down Expand Up @@ -66,4 +71,5 @@ public function render($request, Throwable $exception)

return parent::render($request, $exception);
}

}
13 changes: 7 additions & 6 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ class AuthController extends Controller

public function login(Request $request)
{

$token = Auth::attempt($request->only('email', 'password'));

if(!$token) {
if (!$token) {
return response()->json('Invalid login credentials', 400);
}

$data = [
"token" => [
"access_token" => $token,
"token_type" => 'Bearer',
"expire" => (int) Auth::guard()->factory()->getTTL()
"expire" => (int) config('jwt.ttl')
]
];
return response()->json(compact('data'));
Expand All @@ -39,7 +40,7 @@ public function refresh()
"token" => [
"access_token" => Auth::refresh(),
"token_type" => 'Bearer',
"expire" => (int) Auth::guard()->factory()->getTTL()
"expire" => (int) config('jwt.ttl')
]
];
return response()->json(compact('data'));
Expand All @@ -48,6 +49,7 @@ public function refresh()
public function logout()
{
Auth::logout();
// Auth::user()->tokens()->where('id', 'device_name')->delete();
return response()->json('', 204);
}

Expand All @@ -56,7 +58,7 @@ public function sendReset(Request $request)
$this->validate($request, [
'email' => 'required|email'
]);

$response = Password::broker()->sendResetLink(
$request->only('email')
);
Expand All @@ -79,7 +81,7 @@ public function reset(Request $request)
]);

$response = Password::broker()->reset(
$request->only('email', 'password', 'password_confirmation', 'token'),
$request->only('email', 'password', 'password_confirmation', 'token'),
function ($user, $password) {
$user->password = Hash::make($password);
$user->save();
Expand All @@ -94,5 +96,4 @@ function ($user, $password) {
return response()->json(['error' => $response], 500);
}
}

}
Loading

0 comments on commit 377ed2c

Please sign in to comment.