Browse Source

Revert "Apply fixes from StyleCI (pull request #6)"

This reverts pull request #6.

> This pull request applies code style fixes from an analysis carried out by [StyleCI](https://bitbucket.styleci.io).
> 
> For more information, click [here](https://bitbucket.styleci.io/analyses/a2Jl7D).
master
Miguel N. 7 months ago
parent
commit
4eb115d165
  1. 28
      app/Application.php
  2. 25
      app/Appointment.php
  3. 25
      app/Ban.php
  4. 23
      app/Comment.php
  5. 79
      app/Console/Commands/CountVotes.php
  6. 159
      app/Console/Commands/Install.php
  7. 43
      app/Console/Commands/SetEnv.php
  8. 21
      app/Console/Kernel.php
  9. 45
      app/CustomFacades/IP.php
  10. 25
      app/Events/ApplicationApprovedEvent.php
  11. 24
      app/Events/ApplicationDeniedEvent.php
  12. 22
      app/Events/NewApplicationEvent.php
  13. 30
      app/Events/UserBannedEvent.php
  14. 19
      app/Exceptions/Handler.php
  15. 30
      app/Facades/ContextAwareValidation.php
  16. 19
      app/Facades/IP.php
  17. 21
      app/Facades/Options.php
  18. 23
      app/Facades/UUID.php
  19. 21
      app/Form.php
  20. 185
      app/Helpers/ContextAwareValidator.php
  21. 63
      app/Helpers/Options.php
  22. 143
      app/Http/Controllers/ApplicationController.php
  23. 51
      app/Http/Controllers/AppointmentController.php
  24. 20
      app/Http/Controllers/Auth/ConfirmPasswordController.php
  25. 19
      app/Http/Controllers/Auth/ForgotPasswordController.php
  26. 35
      app/Http/Controllers/Auth/LoginController.php
  27. 33
      app/Http/Controllers/Auth/RegisterController.php
  28. 20
      app/Http/Controllers/Auth/ResetPasswordController.php
  29. 26
      app/Http/Controllers/Auth/TwofaController.php
  30. 20
      app/Http/Controllers/Auth/VerificationController.php
  31. 61
      app/Http/Controllers/BanController.php
  32. 42
      app/Http/Controllers/CommentController.php
  33. 55
      app/Http/Controllers/ContactController.php
  34. 19
      app/Http/Controllers/Controller.php
  35. 38
      app/Http/Controllers/DashboardController.php
  36. 36
      app/Http/Controllers/DevToolsController.php
  37. 92
      app/Http/Controllers/FormController.php
  38. 23
      app/Http/Controllers/HomeController.php
  39. 102
      app/Http/Controllers/OptionsController.php
  40. 76
      app/Http/Controllers/ProfileController.php
  41. 21
      app/Http/Controllers/ResponseController.php
  42. 21
      app/Http/Controllers/StaffProfileController.php
  43. 239
      app/Http/Controllers/UserController.php
  44. 108
      app/Http/Controllers/VacancyController.php
  45. 27
      app/Http/Controllers/VoteController.php
  46. 21
      app/Http/Kernel.php
  47. 39
      app/Http/Middleware/ApplicationEligibility.php
  48. 19
      app/Http/Middleware/Authenticate.php
  49. 31
      app/Http/Middleware/Bancheck.php
  50. 19
      app/Http/Middleware/CheckForMaintenanceMode.php
  51. 19
      app/Http/Middleware/EncryptCookies.php
  52. 23
      app/Http/Middleware/ForceLogoutMiddleware.php
  53. 19
      app/Http/Middleware/RedirectIfAuthenticated.php
  54. 19
      app/Http/Middleware/TrimStrings.php
  55. 21
      app/Http/Middleware/TrustProxies.php
  56. 40
      app/Http/Middleware/UsernameUUID.php
  57. 19
      app/Http/Middleware/VerifyCsrfToken.php
  58. 23
      app/Http/Requests/Add2FASecretRequest.php
  59. 22
      app/Http/Requests/BanUserRequest.php
  60. 21
      app/Http/Requests/ChangeEmailRequest.php
  61. 21
      app/Http/Requests/ChangePasswordRequest.php
  62. 21
      app/Http/Requests/DeleteUserRequest.php
  63. 21
      app/Http/Requests/FlushSessionsRequest.php
  64. 22
      app/Http/Requests/NewCommentRequest.php
  65. 22
      app/Http/Requests/ProfileSave.php
  66. 21
      app/Http/Requests/Remove2FASecretRequest.php
  67. 21
      app/Http/Requests/SaveNotesRequest.php
  68. 21
      app/Http/Requests/SearchPlayerRequest.php
  69. 21
      app/Http/Requests/UpdateUserRequest.php
  70. 22
      app/Http/Requests/VacancyEditRequest.php
  71. 21
      app/Http/Requests/VacancyRequest.php
  72. 21
      app/Http/Requests/VoteRequest.php
  73. 49
      app/Jobs/CleanBans.php
  74. 24
      app/Listeners/DenyUser.php
  75. 26
      app/Listeners/LogAuthenticationFailure.php
  76. 21
      app/Listeners/LogAuthenticationSuccess.php
  77. 39
      app/Listeners/OnUserBanned.php
  78. 36
      app/Listeners/OnUserRegistration.php
  79. 31
      app/Listeners/PromoteUser.php
  80. 20
      app/Mail/NewContactSubmission.php
  81. 29
      app/Notifications/ApplicationApproved.php
  82. 36
      app/Notifications/ApplicationDenied.php
  83. 25
      app/Notifications/ApplicationMoved.php
  84. 21
      app/Notifications/AppointmentFinished.php
  85. 31
      app/Notifications/AppointmentScheduled.php
  86. 21
      app/Notifications/ChangedPassword.php
  87. 21
      app/Notifications/EmailChanged.php
  88. 48
      app/Notifications/NewApplicant.php
  89. 30
      app/Notifications/NewComment.php
  90. 35
      app/Notifications/NewContact.php
  91. 58
      app/Notifications/NewUser.php
  92. 29
      app/Notifications/UserBanned.php
  93. 32
      app/Notifications/VacancyClosed.php
  94. 33
      app/Observers/ApplicationObserver.php
  95. 30
      app/Observers/UserObserver.php
  96. 20
      app/Observers/VacancyObserver.php
  97. 21
      app/Options.php
  98. 43
      app/Policies/ApplicationPolicy.php
  99. 19
      app/Policies/AppointmentPolicy.php
  100. 24
      app/Policies/BanPolicy.php

28
app/Application.php

@ -1,24 +1,5 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App;
use Illuminate\Database\Eloquent\Model;
@ -29,10 +10,13 @@ class Application extends Model
'applicantUserID',
'applicantFormResponseID',
'applicationStatus',
'applicationStatus'
];
public function user()
{
return $this->belongsTo('App\User', 'applicantUserID', 'id');
@ -53,6 +37,7 @@ class Application extends Model
return $this->belongsToMany('App\Vote', 'votes_has_application');
}
public function comments()
{
return $this->hasMany('App\Comment', 'applicationID', 'id');
@ -61,7 +46,8 @@ class Application extends Model
public function setStatus($status)
{
return $this->update([
'applicationStatus' => $status,
'applicationStatus' => $status
]);
}
}

25
app/Appointment.php

@ -1,24 +1,5 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App;
use Illuminate\Database\Eloquent\Model;
@ -32,19 +13,19 @@ class Appointment extends Model
'appointmentStatus',
'appointmentLocation',
'meetingNotes',
'userAccepted',
'userAccepted'
];
public function application()
{
// FIXME: Possible bug here, where laravel looks for the wrong column in the applications table.
// FIXME: Possible bug here, where laravel looks for the wrong column in the applications table.
return $this->belongsTo('App\Application', 'id', 'applicationID');
}
public function setStatus($status)
{
$this->update([
'appointmentStatus' => $status,
'appointmentStatus' => $status
]);
}
}

25
app/Ban.php

@ -1,46 +1,29 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App;
use Illuminate\Database\Eloquent\Model;
class Ban extends Model
{
public $fillable = [
'userID',
'reason',
'bannedUntil',
'userAgent',
'authorUserID',
'authorUserID'
];
public $dates = [
'bannedUntil',
'bannedUntil'
];
public function user()
{
return $this->belongsTo('App\User', 'userID', 'id');
}
}

23
app/Comment.php

@ -1,34 +1,16 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
protected $fillable = [
'authorID',
'applicationID',
'text',
'text'
];
public function application()
@ -40,4 +22,5 @@ class Comment extends Model
{
return $this->belongsTo('App\User', 'authorID', 'id');
}
}

79
app/Console/Commands/CountVotes.php

@ -1,24 +1,5 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Console\Commands;
use App\Application;
@ -62,23 +43,28 @@ class CountVotes extends Command
$eligibleApps = Application::where('applicationStatus', 'STAGE_PEERAPPROVAL')->get();
$pbar = $this->output->createProgressBar($eligibleApps->count());
if ($eligibleApps->isEmpty()) {
if($eligibleApps->isEmpty())
{
$this->error('𐄂 There are no applications that need to be processed.');
return false;
}
foreach ($eligibleApps as $application) {
foreach ($eligibleApps as $application)
{
$votes = $application->votes;
$voteCount = $application->votes->count();
$positiveVotes = 0;
$negativeVotes = 0;
if ($voteCount > 5) {
$this->info('Counting votes for application ID '.$application->id);
foreach ($votes as $vote) {
switch ($vote->allowedVoteType) {
if ($voteCount > 5)
{
$this->info('Counting votes for application ID ' . $application->id);
foreach ($votes as $vote)
{
switch ($vote->allowedVoteType)
{
case 'VOTE_APPROVE':
$positiveVotes++;
break;
@ -88,7 +74,7 @@ class CountVotes extends Command
}
}
$this->info('Total votes for application ID '.$application->id.': '.$voteCount);
$this->info('Total votes for application ID ' . $application->id . ': ' . $voteCount);
$this->info('Calculating criteria...');
$negativeVotePercent = floor(($negativeVotes / $voteCount) * 100);
$positiveVotePercent = floor(($positiveVotes / $voteCount) * 100);
@ -97,43 +83,54 @@ class CountVotes extends Command
$this->table([
'% of approval votes',
'% of denial votes',
'% of denial votes'
], [ // array of arrays, e.g. rows
[
$positiveVotePercent.'%',
$negativeVotePercent.'%',
],
$positiveVotePercent . "%",
$negativeVotePercent . "%"
]
]);
if ($pollResult) {
$this->info('✓ Dispatched promotion event for applicant '.$application->user->name);
if (! $this->option('dryrun')) {
if ($pollResult)
{
$this->info('✓ Dispatched promotion event for applicant ' . $application->user->name);
if (!$this->option('dryrun'))
{
$application->response->vacancy->vacancyCount -= 1;
$application->response->vacancy->save();
event(new ApplicationApprovedEvent(Application::find($application->id)));
} else {
}
else
{
$this->warn('Dry run: Event won\'t be dispatched');
}
$pbar->advance();
} else {
if (! $this->option('dryrun')) {
}
else {
if (!$this->option('dryrun'))
{
event(new ApplicationDeniedEvent(Application::find($application->id)));
} else {
}
else {
$this->warn('Dry run: Event won\'t be dispatched');
}
$pbar->advance();
$this->error('𐄂 Applicant '.$application->user->name.' does not meet vote criteria (Majority)');
$this->error('𐄂 Applicant ' . $application->user->name . ' does not meet vote criteria (Majority)');
}
} else {
$this->warn('Application ID'.$application->id.' did not have enough votes for processing (min 5)');
}
else
{
$this->warn("Application ID" . $application->id . " did not have enough votes for processing (min 5)");
}
}
$pbar->finish();
return true;
}
}

159
app/Console/Commands/Install.php

@ -1,24 +1,5 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Console\Commands;
use Illuminate\Console\Command;
@ -58,89 +39,103 @@ class Install extends Command
public function handle()
{
$basePath = base_path();
if (Storage::disk('local')->missing('INSTALLED')) {
$this->info('[!! Welcome to Rasberry Teams !!]');
$this->info('>> Installing...');
$this->call('down', [
'--message' => 'Down for maintenance. We\'ll be right back!',
]);
if (Storage::disk('local')->missing('INSTALLED'))
{
$this->info('[!! Welcome to Rasberry Teams !!]');
$this->info('>> Installing...');
$this->call('down', [
'--message' => 'Down for maintenance. We\'ll be right back!'
]);
copy($basePath . '/.env.example', $basePath . '/.env');
$this->call('key:generate');
$this->info('>> Installing and preparing dependencies. This may take a while, depending on your computer.');
copy($basePath.'/.env.example', $basePath.'/.env');
$this->call('key:generate');
$npmOut = 0;
$npmMessages = [];
$this->info('>> Installing and preparing dependencies. This may take a while, depending on your computer.');
$npmBuildOut = 0;
$npmBuildMessages = [];
$npmOut = 0;
$npmMessages = [];
exec('cd ' . $basePath . ' && npm install --silent', $npmBuildOut, $npmOut);
exec('cd ' . $basePath . '&& npm run dev --silent', $npmBuildMessages, $npmBuildOut);
$npmBuildOut = 0;
$npmBuildMessages = [];
exec('cd '.$basePath.' && npm install --silent', $npmBuildOut, $npmOut);
exec('cd '.$basePath.'&& npm run dev --silent', $npmBuildMessages, $npmBuildOut);
if($npmOut !== 0 && $npmBuildOut !== 0)
{
$this->error('[!] One or more errors have ocurred whilst attempting to install dependencies.');
$this->error('[!] It is recommended to run this command again, and report a bug if it keeps happening.');
if ($npmOut !== 0 && $npmBuildOut !== 0) {
$this->error('[!] One or more errors have ocurred whilst attempting to install dependencies.');
$this->error('[!] It is recommended to run this command again, and report a bug if it keeps happening.');
return false;
}
return false;
}
$settings = [];
$this->info('>> Configuring application - We\'re going to ask a few questions here!');
do {
$this->info('== Database Settings (1/6) ==');
$settings = [];
$settings['DB_USERNAME'] = $this->ask('Database username');
$settings['DB_PASSWORD'] = $this->secret('Database password (Input won\'t be seen)');
$settings['DB_DATABASE'] = $this->ask('Database name');
$settings['DB_PORT'] = $this->ask('Database port');
$settings['DB_HOST'] = $this->ask('Database hostname');
$this->info('>> Configuring application - We\'re going to ask a few questions here!');
do
{
$this->info('== Database Settings (1/6) ==');
$this->info('== Antispam Settings (2/6) (Recaptcha v2) ==');
$settings['RECAPTCHA_SITE_KEY'] = $this->ask('Site key');
$settings['RECAPTCHA_PRIVATE_KEY'] = $this->ask('Private site key');
$settings['DB_USERNAME'] = $this->ask('Database username');
$settings['DB_PASSWORD'] = $this->secret('Database password (Input won\'t be seen)');
$settings['DB_DATABASE'] = $this->ask('Database name');
$settings['DB_PORT'] = $this->ask('Database port');
$settings['DB_HOST'] = $this->ask('Database hostname');
$this->info('== IP Geolocation Settings (3/6) (refer to README.md) ==');
$settings['IPGEO_API_KEY'] = $this->ask('API Key');
$this->info('== Antispam Settings (2/6) (Recaptcha v2) ==');
$settings['RECAPTCHA_SITE_KEY'] = $this->ask('Site key');
$settings['RECAPTCHA_PRIVATE_KEY'] = $this->ask('Private site key');
$this->info('== Notification Settings (4/6) (Email) ==');
$settings['MAIL_USERNAME'] = $this->ask('SMTP Username');
$settings['MAIL_PASSWORD'] = $this->secret('SMTP Password (Input won\'t be seen)');
$settings['MAIL_PORT'] = $this->ask('SMTP Server Port');
$settings['MAIL_HOST'] = $this->ask('SMTP Server Hostname');
$settings['MAIL_FROM'] = $this->ask('E-mail address to send from: ');
$this->info('== IP Geolocation Settings (3/6) (refer to README.md) ==');
$settings['IPGEO_API_KEY'] = $this->ask('API Key');
$this->info('== Notification Settings (5/6) (Slack) ==');
$settings['SLACK_INTEGRATION_WEBHOOK'] = $this->ask('Integration webhook URL');
$this->info('== Notification Settings (4/6) (Email) ==');
$settings['MAIL_USERNAME'] = $this->ask('SMTP Username');
$settings['MAIL_PASSWORD'] = $this->secret('SMTP Password (Input won\'t be seen)');
$settings['MAIL_PORT'] = $this->ask('SMTP Server Port');
$settings['MAIL_HOST'] = $this->ask('SMTP Server Hostname');
$settings['MAIL_FROM'] = $this->ask('E-mail address to send from: ');
$this->info('== Web Settings (6/6) ==');
$settings['APP_URL'] = $this->ask('Application\'s URL (ex. https://where.you.installed.theapp.com): ');
$settings['APP_LOGO'] = $this->ask('App logo (Link to an image): ');
$settings['APP_SITEHOMEPAGE'] = $this->ask('Site homepage (appears in the main header): ');
} while (! $this->confirm('Are you sure you want to save these settings? You can always go back and try again.'));
$this->info('== Notification Settings (5/6) (Slack) ==');
$settings['SLACK_INTEGRATION_WEBHOOK'] = $this->ask('Integration webhook URL');
foreach ($settings as $keyname => $value) {
$this->call('environment:modify', [
'key' => $keyname,
'value' => $value,
]);
}
$this->info('== Web Settings (6/6) ==');
$settings['APP_URL'] = $this->ask('Application\'s URL (ex. https://where.you.installed.theapp.com): ');
$settings['APP_LOGO'] = $this->ask('App logo (Link to an image): ');
$settings['APP_SITEHOMEPAGE'] = $this->ask('Site homepage (appears in the main header): ');
$this->info('>> Saved configuration settings!');
$this->info('>> Preparing database...');
$this->callSilent('config:cache');
$this->call('migrate');
$this->call('db:seed');
} while(!$this->confirm('Are you sure you want to save these settings? You can always go back and try again.'));
touch($basePath.'/INSTALLED');
foreach($settings as $keyname => $value)
{
$this->call('environment:modify', [
'key' => $keyname,
'value' => $value
]);
}
$this->call('up');
$this->info('>> All done! Visit '.$basePath.' to start using your brand new installation of Raspberry Teams!');
} else {
$this->error('[!] The application is already installed!');
$this->info('>> Saved configuration settings!');
$this->info('>> Preparing database...');
$this->callSilent('config:cache');
$this->call('migrate');
$this->call('db:seed');
touch($basePath . '/INSTALLED');
$this->call('up');
$this->info('>> All done! Visit ' . $basePath . ' to start using your brand new installation of Raspberry Teams!');
}
else
{
$this->error('[!] The application is already installed!');
}
}
}

43
app/Console/Commands/SetEnv.php

@ -1,28 +1,9 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Console\Commands;
use GeoSot\EnvEditor\Facades\EnvEditor;
use Illuminate\Console\Command;
use GeoSot\EnvEditor\Facades\EnvEditor;
class SetEnv extends Command
{
@ -56,16 +37,20 @@ class SetEnv extends Command
*/
public function handle()
{
$path = base_path('/.env');
$key = $this->argument('key');
$value = $this->argument('value');
$path = base_path('/.env');
$key = $this->argument('key');
$value = $this->argument('value');
if (file_exists($path)) {
EnvEditor::editKey($key, $value);
} else {
$this->error('Cannot update a file that doesn\'t exist! Please create .env first.');
return false;
}
if (file_exists($path))
{
EnvEditor::editKey($key, $value);
}
else
{
$this->error('Cannot update a file that doesn\'t exist! Please create .env first.');
return false;
}
}
}

21
app/Console/Kernel.php

@ -1,29 +1,10 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Console;
use App\Jobs\CleanBans;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Jobs\CleanBans;
class Kernel extends ConsoleKernel
{

45
app/CustomFacades/IP.php

@ -1,24 +1,5 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\CustomFacades;
use Illuminate\Support\Facades\Cache;
@ -26,6 +7,7 @@ use Illuminate\Support\Facades\Http;
class IP
{
/**
* Looks up information on a specified IP address. Caches results automatically.
* @param string $IP IP address to lookup
@ -33,18 +15,23 @@ class IP
*/
public function lookup(string $IP): object
{
$params = [
$params = [
'apiKey' => config('general.keys.ipapi.apikey'),
'ip' => $IP
];
// TODO: Maybe unwrap this? Methods are chained here
return json_decode(Cache::remember($IP, 3600, function() use ($IP)
{
return Http::get(config('general.urls.ipapi.ipcheck'), [
'apiKey' => config('general.keys.ipapi.apikey'),
'ip' => $IP,
];
'ip' => $IP
])->body();
}));
// TODO: Maybe unwrap this? Methods are chained here
return json_decode(Cache::remember($IP, 3600, function () use ($IP) {
return Http::get(config('general.urls.ipapi.ipcheck'), [
'apiKey' => config('general.keys.ipapi.apikey'),
'ip' => $IP,
])->body();
}));
}
}

25
app/Events/ApplicationApprovedEvent.php

@ -1,28 +1,13 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Events;
use App\Application;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
@ -41,4 +26,6 @@ class ApplicationApprovedEvent
{
$this->application = $application;
}
}

24
app/Events/ApplicationDeniedEvent.php

@ -1,28 +1,13 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Events;
use App\Application;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
@ -41,4 +26,5 @@ class ApplicationDeniedEvent
{
$this->application = $application;
}
}

22
app/Events/NewApplicationEvent.php

@ -1,28 +1,12 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

30
app/Events/UserBannedEvent.php

@ -1,36 +1,23 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Events;
use App\Ban;
use App\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use App\User;
use App\Ban;
class UserBannedEvent
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user;
public $ban;
@ -45,4 +32,5 @@ class UserBannedEvent
$this->user = $user;
$this->ban = $ban;
}
}

19
app/Exceptions/Handler.php

@ -1,24 +1,5 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

30
app/Facades/ContextAwareValidation.php

@ -1,32 +1,14 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class ContextAwareValidation extends Facade
{
protected static function getFacadeAccessor()
{
return 'contextAwareValidator';
}
protected static function getFacadeAccessor()
{
return 'contextAwareValidator';
}
}

19
app/Facades/IP.php

@ -1,24 +1,5 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Facades;
use Illuminate\Support\Facades\Facade;

21
app/Facades/Options.php

@ -1,27 +1,8 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
use \Illuminate\Support\Facades\Facade;
class Options extends Facade
{

23
app/Facades/UUID.php

@ -1,32 +1,13 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class UUID extends Facade
class UUID extends Facade
{
protected static function getFacadeAccessor()
{
return 'uuidConversionFacade';
}
}
}

21
app/Form.php

@ -1,24 +1,5 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App;
use Illuminate\Database\Eloquent\Model;
@ -29,7 +10,7 @@ class Form extends Model
'formName',
'formStructure',
'formStatus',
'formStatus'
];

185
app/Helpers/ContextAwareValidator.php

@ -1,141 +1,138 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Helpers;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Collection;
class ContextAwareValidator
{
/**
* The excludedNames array will make the validator ignore any of these names when including names into the rules.
* @var array
*/
* The excludedNames array will make the validator ignore any of these names when including names into the rules.
* @var array
*/
private $excludedNames = [
'_token',
'_method',
'formName',
'_token',
'_method',
'formName'
];
/**
* Utility wrapper for json_encode.
*
* @param array $value The array to be converted.
* @return string The JSON representation of $value
*/
private function encode(array $value): string
* Utility wrapper for json_encode.
*
* @param array $value The array to be converted.
* @return string The JSON representation of $value
*/
private function encode(array $value) : string
{
return json_encode($value);
return json_encode($value);
}
/**
* The getValidator() method will take an array of fields from the request body, iterates through them,
* and dynamically adds validation rules for them. Depending on parameters, it may or may not generate
* a form structure for rendering purposes.
*
* This method is mostly meant by internal use by means of static proxies (Facades), in order to reduce code repetition;
* Using it outside it's directed scope may cause unexpected results; For instance, the method expects inputs to be in array format, e.g. myFieldNameID1[],
* myFieldNameID2[], and so on and so forth.
*
* This isn't checked by the code yet, but if you're implementing it this way in the HTML markup, make sure it's consistent (e.g. use a loop).
*
* P.S This method automatically ignores the CSRF token for validation.
*
* @param array $fields The request form fields
* @param bool $generateStructure Whether to incldue a JSON-ready form structure for rendering
* @param bool $includeFormName Whether to include formName in the list of validation rules
* @return Validator|Collection A validator instance you can use to check for validity, or a Collection with a validator and structure (validator, structure)
*/
* The getValidator() method will take an array of fields from the request body, iterates through them,
* and dynamically adds validation rules for them. Depending on parameters, it may or may not generate
* a form structure for rendering purposes.
*
* This method is mostly meant by internal use by means of static proxies (Facades), in order to reduce code repetition;
* Using it outside it's directed scope may cause unexpected results; For instance, the method expects inputs to be in array format, e.g. myFieldNameID1[],
* myFieldNameID2[], and so on and so forth.
*
* This isn't checked by the code yet, but if you're implementing it this way in the HTML markup, make sure it's consistent (e.g. use a loop).
*
* P.S This method automatically ignores the CSRF token for validation.
*
* @param array $fields The request form fields
* @param bool $generateStructure Whether to incldue a JSON-ready form structure for rendering
* @param bool $includeFormName Whether to include formName in the list of validation rules
* @return Validator|Collection A validator instance you can use to check for validity, or a Collection with a validator and structure (validator, structure)
*/
public function getValidator(array $fields, bool $generateStructure = false, bool $includeFormName = false)
{
$formStructure = [];
$validator = [];
if ($includeFormName) {
if ($includeFormName)
{
$validator['formName'] = 'required|string|max:100';
}
}
foreach ($fields as $fieldName => $field) {
if (! in_array($fieldName, $this->excludedNames)) {
$validator[$fieldName.'.0'] = 'required|string';
$validator[$fieldName.'.1'] = 'required|string';
foreach ($fields as $fieldName => $field)
{
if(!in_array($fieldName, $this->excludedNames))
{
$validator[$fieldName . ".0"] = 'required|string';
$validator[$fieldName . ".1"] = 'required|string';
if ($generateStructure) {
if ($generateStructure)
{
$formStructure['fields'][$fieldName]['title'] = $field[0];
$formStructure['fields'][$fieldName]['type'] = $field[1];
}
}
}
}
}
}
$validatorInstance = Validator::make($fields, $validator);
$validatorInstance = Validator::make($fields, $validator);
return ($generateStructure) ?
return ($generateStructure) ?
collect([
'validator' => $validatorInstance,
'structure' => $this->encode($formStructure),
'validator' => $validatorInstance,
'structure' => $this->encode($formStructure)
])
: $validatorInstance;
}
/**
* The getResponseValidator method is similar to the getValidator method; It basically takes
* an array of fields from a previous form (that probably went through the other method) and adds validation
* to the field names.
*
* Also generates the storable response structure if you tell it to.
*
* @param array $fields The received fields
* @param array $formStructure The form structure - You must supply this if you want the response structure
* @param bool $generateResponseStructure Whether to generate the response structure
* @return Validator|Collection A collection or a validator, depending on the args. Will return validatior if only fields are supplied.
*/
* The getResponseValidator method is similar to the getValidator method; It basically takes
* an array of fields from a previous form (that probably went through the other method) and adds validation
* to the field names.
*
* Also generates the storable response structure if you tell it to.
*
* @param array $fields The received fields
* @param array $formStructure The form structure - You must supply this if you want the response structure
* @param bool $generateResponseStructure Whether to generate the response structure
* @return Validator|Collection A collection or a validator, depending on the args. Will return validatior if only fields are supplied.
*/
public function getResponseValidator(array $fields, array $formStructure = [], bool $generateResponseStructure = true)
{
$responseStructure = [];
$validator = [];
if (empty($formStructure) && $generateResponseStructure) {
throw new \InvalidArgumentException('Illegal combination of arguments supplied! Please check the method\'s documentation.');
}
$responseStructure = [];
$validator = [];
foreach ($fields as $fieldName => $value) {
if (! in_array($fieldName, $this->excludedNames)) {
$validator[$fieldName] = 'required|string';
if (empty($formStructure) && $generateResponseStructure)
{
throw new \InvalidArgumentException('Illegal combination of arguments supplied! Please check the method\'s documentation.');
}
if ($generateResponseStructure) {
$responseStructure['responses'][$fieldName]['type'] = $formStructure['fields'][$fieldName]['type'] ?? 'Unavailable';
$responseStructure['responses'][$fieldName]['title'] = $formStructure['fields'][$fieldName]['title'];
$responseStructure['responses'][$fieldName]['response'] = $value;
}
}
}
foreach($fields as $fieldName => $value)
{
if(!in_array($fieldName, $this->excludedNames))
{
$validator[$fieldName] = 'required|string';
$validatorInstance = Validator::make($fields, $validator);
if ($generateResponseStructure)
{
$responseStructure['responses'][$fieldName]['type'] = $formStructure['fields'][$fieldName]['type'] ?? 'Unavailable';
$responseStructure['responses'][$fieldName]['title'] = $formStructure['fields'][$fieldName]['title'];
$responseStructure['responses'][$fieldName]['response'] = $value;
}
}
}
return ($generateResponseStructure) ?
$validatorInstance = Validator::make($fields, $validator);
return ($generateResponseStructure) ?
collect([
'validator' => $validatorInstance,
'responseStructure' => $this->encode($responseStructure),
'validator' => $validatorInstance,
'responseStructure' => $this->encode($responseStructure)
])
: $validatorInstance;
}
}

63
app/Helpers/Options.php

@ -1,23 +1,5 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Helpers;
@ -27,18 +9,20 @@ use Illuminate\Support\Facades\Log;
class Options
{
public function getOption(string $option): string
{
$value = Cache::get($option);
if (is_null($value)) {
Log::debug('Option '.$option.'not found in cache, refreshing from database');
if (is_null($value))
{
Log::debug('Option ' . $option . 'not found in cache, refreshing from database');
$value = Option::where('option_name', $option)->first();
if (is_null($value)) {
if (is_null($value))
throw new \Exception('This option does not exist.');
}
Cache::put($option, $value);
Cache::put($option.'_desc', 'Undefined description');
Cache::put($option . '_desc', 'Undefined description');
}
return $value->option_value;
@ -46,14 +30,14 @@ class Options
public function setOption(string $option, string $value, string $description)
{
Option::create([
'option_name' => $option,
'option_value' => $value,
'friendly_name' => $description,
]);
Cache::put($option, $value, now()->addDay());
Cache::put($option.'_desc', $description, now()->addDay());
Option::create([
'option_name' => $option,
'option_value' => $value,
'friendly_name' => $description
]);
Cache::put($option, $value, now()->addDay());
Cache::put($option . '_desc', $description, now()->addDay());
}
public function pullOption($option): array
@ -64,7 +48,7 @@ class Options
// putMany is overkill here
return [
Cache::pull($option),
Cache::pull($option.'_desc'),
Cache::pull($option . '_desc')
];
}
@ -72,13 +56,14 @@ class Options
{
$dbOption = Option::where('option_name', $option);
if ($dbOption->first()) {
if ($dbOption->first())
{
$dbOptionInstance = Option::find($dbOption->first()->id);
Cache::forget($option);
Log::debug('Changing db configuration option', [
'old_value' => $dbOptionInstance->option_value,
'new_value' => $newValue,
'new_value' => $newValue
]);
$dbOptionInstance->option_value = $newValue;
@ -86,20 +71,24 @@ class Options
Log::debug('New db configuration option saved',
[
'option' => $dbOptionInstance->option_value,
'option' => $dbOptionInstance->option_value