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

Upgrade #102

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\CreatesNewUsers;
use Laravel\Jetstream\Jetstream;

class CreateNewUser implements CreatesNewUsers
{
Expand All @@ -14,15 +15,15 @@ class CreateNewUser implements CreatesNewUsers
/**
* Validate and create a newly registered user.
*
* @param array $input
* @return \App\Models\User
* @param array<string, string> $input
*/
public function create(array $input)
public function create(array $input): User
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => $this->passwordRules(),
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
])->validate();

return User::create([
Expand Down
8 changes: 4 additions & 4 deletions app/Actions/Fortify/PasswordValidationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace App\Actions\Fortify;

use Laravel\Fortify\Rules\Password;
use Illuminate\Validation\Rules\Password;

trait PasswordValidationRules
{
/**
* Get the validation rules used to validate passwords.
*
* @return array
* @return array<int, \Illuminate\Contracts\Validation\Rule|array|string>
*/
protected function passwordRules()
protected function passwordRules(): array
{
return ['required', 'string', new Password, 'confirmed'];
return ['required', 'string', Password::default(), 'confirmed'];
}
}
7 changes: 3 additions & 4 deletions app/Actions/Fortify/ResetUserPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Actions\Fortify;

use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\ResetsUserPasswords;
Expand All @@ -13,11 +14,9 @@ class ResetUserPassword implements ResetsUserPasswords
/**
* Validate and reset the user's forgotten password.
*
* @param mixed $user
* @param array $input
* @return void
* @param array<string, string> $input
*/
public function reset($user, array $input)
public function reset(User $user, array $input): void
{
Validator::make($input, [
'password' => $this->passwordRules(),
Expand Down
17 changes: 7 additions & 10 deletions app/Actions/Fortify/UpdateUserPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Actions\Fortify;

use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
Expand All @@ -13,20 +14,16 @@ class UpdateUserPassword implements UpdatesUserPasswords
/**
* Validate and update the user's password.
*
* @param mixed $user
* @param array $input
* @return void
* @param array<string, string> $input
*/
public function update($user, array $input)
public function update(User $user, array $input): void
{
Validator::make($input, [
'current_password' => ['required', 'string'],
'current_password' => ['required', 'string', 'current_password:web'],
'password' => $this->passwordRules(),
])->after(function ($validator) use ($user, $input) {
if (! Hash::check($input['current_password'], $user->password)) {
$validator->errors()->add('current_password', __('The provided password does not match your current password.'));
}
})->validateWithBag('updatePassword');
], [
'current_password.current_password' => __('The provided password does not match your current password.'),
])->validateWithBag('updatePassword');

$user->forceFill([
'password' => Hash::make($input['password']),
Expand Down
31 changes: 26 additions & 5 deletions app/Actions/Fortify/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Actions\Fortify;

use App\Models\User;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
Expand All @@ -11,25 +13,44 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation
/**
* Validate and update the given user's profile information.
*
* @param mixed $user
* @param array $input
* @return void
* @param array<string, mixed> $input
*/
public function update($user, array $input)
public function update(User $user, array $input): void
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
'photo' => ['nullable', 'image', 'max:1024'],
'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
])->validateWithBag('updateProfileInformation');

if (isset($input['photo'])) {
$user->updateProfilePhoto($input['photo']);
}

if ($input['email'] !== $user->email &&
$user instanceof MustVerifyEmail) {
$this->updateVerifiedUser($user, $input);
} else {
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
])->save();
}
}

/**
* Update the given verified user's profile information.
*
* @param array<string, string> $input
*/
protected function updateVerifiedUser(User $user, array $input): void
{
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'email_verified_at' => null,
])->save();

$user->sendEmailVerificationNotification();
}
}
8 changes: 4 additions & 4 deletions app/Actions/Jetstream/DeleteUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace App\Actions\Jetstream;

use App\Models\User;
use Laravel\Jetstream\Contracts\DeletesUsers;

class DeleteUser implements DeletesUsers
{
/**
* Delete the given user.
*
* @param mixed $user
* @return void
*/
public function delete($user)
public function delete(User $user): void
{
$user->deleteProfilePhoto();
$user->tokens->each->delete();
$user->delete();
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GroupController extends Controller
public function index()
{
$user = Auth::user();
$ids = $user->currentGroups->pluck('id')->toArray();
$ids = $user->currentGroups?->pluck('id')->toArray() ?? [];
$groups = Group::whereIn('id', $ids)
->get();
return view('dashboard')->with([
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/SendContactEmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __invoke(Request $request)
$subject = $firstName . " " . $lastName . " contacted My Daily Dozen";

Mail::send(
'contact',
'contact-email',
['subject' => $subject, 'body' => $body],
function ($message) use ($email, $subject) {
$message->from($email);
Expand Down
1 change: 0 additions & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class Kernel extends HttpKernel
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
Expand Down
9 changes: 7 additions & 2 deletions app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Middleware;

use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;

class TrustProxies extends Middleware
Expand All @@ -19,5 +19,10 @@ class TrustProxies extends Middleware
*
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_ALL;
protected $headers =
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
}
5 changes: 4 additions & 1 deletion app/Http/Livewire/Card.php → app/Livewire/Card.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Http\Livewire;
namespace App\Livewire;

use Livewire\Component;
use App\Models\Group;
Expand All @@ -10,11 +10,13 @@ class Card extends Component
{
public Group $group;
public $checkCount;
public $checkboxes = [];

public function mount(Group $group)
{
$this->group = $group;
$this->checkCount = auth()->user()->getCheckCountForGroupAndDate($this->group, Carbon::today());
$this->checkboxes = [...array_fill(0, $this->checkCount, true), ...array_fill(0, $group->per_day-$this->checkCount, false)];
}
public function render()
{
Expand All @@ -25,5 +27,6 @@ public function check($count)
{
$update = auth()->user()->setCheckCountForGroupAndDate($this->group, Carbon::today(), $count);
$this->checkCount = $update;
$this->checkboxes = [...array_fill(0, $this->checkCount, true), ...array_fill(0, $this->group->per_day-$this->checkCount, false)];
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Http\Livewire;
namespace App\Livewire;

use App\Models\Group;
use Livewire\Component;
Expand Down
22 changes: 16 additions & 6 deletions app/Providers/FortifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,41 @@
use App\Actions\Fortify\ResetUserPassword;
use App\Actions\Fortify\UpdateUserPassword;
use App\Actions\Fortify\UpdateUserProfileInformation;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Laravel\Fortify\Fortify;

class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
public function register(): void
{
//
}

/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
public function boot(): void
{
Fortify::createUsersUsing(CreateNewUser::class);
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);

RateLimiter::for('login', function (Request $request) {
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->ip());

return Limit::perMinute(5)->by($throttleKey);
});

RateLimiter::for('two-factor', function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
}
}
12 changes: 3 additions & 9 deletions app/Providers/JetstreamServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@ class JetstreamServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
public function register(): void
{
//
}

/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
public function boot(): void
{
$this->configurePermissions();

Expand All @@ -32,10 +28,8 @@ public function boot()

/**
* Configure the permissions that are available within the application.
*
* @return void
*/
protected function configurePermissions()
protected function configurePermissions(): void
{
Jetstream::defaultApiTokenPermissions(['read']);

Expand Down
5 changes: 2 additions & 3 deletions app/View/Components/AppLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
namespace App\View\Components;

use Illuminate\View\Component;
use Illuminate\View\View;

class AppLayout extends Component
{
/**
* Get the view / contents that represents the component.
*
* @return \Illuminate\View\View
*/
public function render()
public function render(): View
{
return view('layouts.app');
}
Expand Down
5 changes: 2 additions & 3 deletions app/View/Components/GuestLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
namespace App\View\Components;

use Illuminate\View\Component;
use Illuminate\View\View;

class GuestLayout extends Component
{
/**
* Get the view / contents that represents the component.
*
* @return \Illuminate\View\View
*/
public function render()
public function render(): View
{
return view('layouts.guest');
}
Expand Down
Loading
Loading