Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 9.x Shift #96

Merged
merged 22 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=database
SESSION_LIFETIME=720
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.2-cli-alpine
FROM php:8.1-cli-alpine

WORKDIR /var/www/html

Expand Down
10 changes: 0 additions & 10 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,9 @@

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
Expand Down
15 changes: 12 additions & 3 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,28 @@

class Handler extends ExceptionHandler
{
/**
* A list of exception types with their corresponding custom log levels.
*
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
*/
protected $levels = [
//
];

/**
* A list of the exception types that are not reported.
*
* @var array
* @var array<int, class-string<\Throwable>>
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
* A list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
Expand Down
11 changes: 1 addition & 10 deletions app/Http/Controllers/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

use App\Models\Person;
use App\Utils\Telegram;
use Inertia\Inertia;
use Illuminate\Http\Request;

use Inertia\Inertia;

class AppController extends Controller
{
Expand All @@ -26,10 +25,6 @@ public function index()

/**
* logout and destroy all sessions
*
* @param Request $request
*
* @return
*/
public function logout(Request $request)
{
Expand All @@ -44,10 +39,6 @@ public function logout(Request $request)

/**
* error page
*
* @param Request $request
*
* @return
*/
public function error(Request $request)
{
Expand Down
40 changes: 22 additions & 18 deletions app/Http/Controllers/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,38 @@

use App\Models\ArticleActionLog;
use App\Models\Person;
use Illuminate\Http\Request;

class ExportController extends Controller
{
public function validateRequest(string $password){
public function validateRequest(string $password)
{
return $password == env('CSV_EXPORT_PW');
}

public function createCsv(){
public function createCsv()
{
$fileName = 'strichlisten_export.csv';
$persons = Person::all();

$headers = array(
$headers = [
'Content-type' => 'text/csv; charset=UTF-8',
'Content-Encoding' => 'UTF-8',
'Content-Disposition' => "attachment; filename=$fileName",
'Pragma' => 'no-cache',
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
'Expires' => '0'
);
'Expires' => '0',
];

$columns = array(
$columns = [
'Nachname',
'Vorname',
'Anz_Bier',
'Anz_Radler',
'Anz_Softdrinks',
'Anz_Wasser'
);
'Anz_Wasser',
];

$callback = function() use($persons, $columns){
$callback = function () use ($persons, $columns) {
$file = fopen('php://output', 'w');
fputcsv($file, $columns, ';');

Expand All @@ -44,22 +45,22 @@ public function createCsv(){
$row['Email'] = $person->email;
$row['Anz_Bier'] = ArticleActionLog::where([
['person_id', '=', $person->id],
['article_id', '=', 1]
['article_id', '=', 1],
])->count();
$row['Anz_Radler'] = ArticleActionLog::where([
['person_id', '=', $person->id],
['article_id', '=', 2]
['article_id', '=', 2],
])->count();
$row['Anz_Softdrink'] = ArticleActionLog::where([
['person_id', '=', $person->id],
['article_id', '=', 3]
['article_id', '=', 3],
])->count();
$row['Anz_Wasser'] = ArticleActionLog::where([
['person_id', '=', $person->id],
['article_id', '=', 4]
['article_id', '=', 4],
])->count();
$array = array($row['Nachname'], $row['Vorname'], $row['Anz_Bier'], $row['Anz_Radler'], $row['Anz_Softdrink'], $row['Anz_Wasser']);
$array = array_map("utf8_decode", $array);
$array = [$row['Nachname'], $row['Vorname'], $row['Anz_Bier'], $row['Anz_Radler'], $row['Anz_Softdrink'], $row['Anz_Wasser']];
$array = array_map('utf8_decode', $array);
fputcsv($file, $array, ';');
}
fclose($file);
Expand All @@ -68,8 +69,11 @@ public function createCsv(){
return response()->stream($callback, 200, $headers);
}

public function exportCsv(string $password){
if (!$this->validateRequest($password)) return "Incorrect Password!";
public function exportCsv(string $password)
{
if (! $this->validateRequest($password)) {
return 'Incorrect Password!';
}

return $this->createCsv();
}
Expand Down
49 changes: 16 additions & 33 deletions app/Http/Controllers/PersonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@
use App\Models\ArticleActionLog;
use App\Models\Person;
use App\Utils\Telegram;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;
use Illuminate\Http\Request;


class PersonController extends Controller
{
/**
* validate auth token
*
* @param Request $request
* @param Person $person
* @param bool $enableLog
*
*
* @return null|\Illuminate\Http\RedirectResponse
*/
public function validateAuthToken(Request $request, Person $person, bool $enableLog = true)
Expand All @@ -32,7 +28,7 @@ public function validateAuthToken(Request $request, Person $person, bool $enable

if ($person->id != $authTokenPerson->id) {
if ($enableLog) {
Telegram::warning('Try to access "*' . $person->fullname . '*"\'s (ID: `' . $person->id . '`) page with an invalid auth token', $request, $authTokenPerson);
Telegram::warning('Try to access "*'.$person->fullname.'*"\'s (ID: `'.$person->id.'`) page with an invalid auth token', $request, $authTokenPerson);
}

return Redirect::route('error');
Expand All @@ -42,9 +38,7 @@ public function validateAuthToken(Request $request, Person $person, bool $enable
/**
* show specific person
*
* @param Request $request
* @param int $id
*
*
* @return \Inertia\Response
*/
public function show(Request $request, int $id)
Expand All @@ -68,10 +62,7 @@ public function show(Request $request, int $id)
/**
* buy an article for a user
*
* @param Request $request
* @param int $id
* @param int $articleID
*
*
* @return \Illuminate\Http\RedirectResponse
*/
public function buy(Request $request, int $id, int $articleID)
Expand All @@ -84,22 +75,22 @@ public function buy(Request $request, int $id, int $articleID)
$article = Article::findOrFail($articleID);

$amount = $request['amount'];
if (!is_numeric($amount) || $amount < 1 || $amount > env('MIX_APP_MAX_ORDER_COUNT')) {
if (! is_numeric($amount) || $amount < 1 || $amount > env('MIX_APP_MAX_ORDER_COUNT')) {
return Redirect::route('person.show', ['id' => $id]);
}

for ($i = 0; $i < $amount; $i++) {
$person->buyArticle($article, $request->ip());
}

Telegram::info('Bought the article "*' . $article->name . '*" (' . $amount . 'x) (ID: `' . $article->id . '`)', $request, $person);
Telegram::info('Bought the article "*'.$article->name.'*" ('.$amount.'x) (ID: `'.$article->id.'`)', $request, $person);

$count = ArticleActionLog::where('person_id', $person->id)
->where('created_at', '>=', now()->subMinutes(5))
->count();

if ($count >= 6) {
Telegram::warning('Bought *' . $count . '* articles in the last 5 minutes', $request, $person);
Telegram::warning('Bought *'.$count.'* articles in the last 5 minutes', $request, $person);
}

return Redirect::route('person.show', ['id' => $id]);
Expand All @@ -108,10 +99,7 @@ public function buy(Request $request, int $id, int $articleID)
/**
* cancel an article for a user by article log id
*
* @param Request $request
* @param int $id
* @param int $articleActionLogId
*
*
* @return \Illuminate\Http\RedirectResponse
*/
public function cancel(Request $request, int $id, int $articleActionLogId)
Expand All @@ -126,14 +114,14 @@ public function cancel(Request $request, int $id, int $articleActionLogId)
if ($person->id == $articleActionLog->person_id) {
$person->cancelArticle($articleActionLog);

Telegram::info('Cancel the article "*' . $articleActionLog->article->name . '*" (ID: `' . $articleActionLog->article->id . '`). Bought at "' . $articleActionLog->created_at . '" and canceld at "' . $articleActionLog->deleted_at . '". Could have cancelled by "' . $articleActionLog->cancelUntil . '" (ID: `' . $articleActionLog->id . '`)', $request, $person);
Telegram::info('Cancel the article "*'.$articleActionLog->article->name.'*" (ID: `'.$articleActionLog->article->id.'`). Bought at "'.$articleActionLog->created_at.'" and canceld at "'.$articleActionLog->deleted_at.'". Could have cancelled by "'.$articleActionLog->cancelUntil.'" (ID: `'.$articleActionLog->id.'`)', $request, $person);

$count = ArticleActionLog::withTrashed()->where('person_id', $person->id)
->where('deleted_at', '>=', now()->subMinutes(5))
->count();

if ($count >= 3) {
Telegram::warning('Cancel *' . $count . '* articles in the last 5 minutes', $request, $person);
Telegram::warning('Cancel *'.$count.'* articles in the last 5 minutes', $request, $person);
}
}

Expand All @@ -143,9 +131,7 @@ public function cancel(Request $request, int $id, int $articleActionLogId)
/**
* create new auth link for a person
*
* @param Request $request
* @param int $id
*
*
* @return \Illuminate\Http\JsonResponse
*/
public function generateAuthLink(Request $request, int $id)
Expand All @@ -155,20 +141,17 @@ public function generateAuthLink(Request $request, int $id)
return $this->validateAuthToken($request, $person, false);
}

Telegram::info('Generate an auth link for "*' . $person->fullname . '*" (ID: `' . $person->id . '`)', $request, $person);
Telegram::info('Generate an auth link for "*'.$person->fullname.'*" (ID: `'.$person->id.'`)', $request, $person);

return response()->json([
'authLink' => $person->createAuthLink()
'authLink' => $person->createAuthLink(),
]);
}

/**
* auth a person with token
*
* @param Request $request
* @param int $id
* @param string $token
*
*
* @return \Illuminate\Http\RedirectResponse
*/
public function authWithToken(Request $request, int $id, string $token)
Expand All @@ -181,7 +164,7 @@ public function authWithToken(Request $request, int $id, string $token)

$request->session()->put('authToken', $person->auth_token);

Telegram::info('Auth "*' . $person->fullname . '*" (ID: `' . $person->id . '`)', $request, $person);
Telegram::info('Auth "*'.$person->fullname.'*" (ID: `'.$person->id.'`)', $request, $person);

return Redirect::route('person.show', ['id' => $id]);
}
Expand Down
Loading
Loading