-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfd3aad
commit 46a8468
Showing
25 changed files
with
1,093 additions
and
54 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Actions\Fortify; | ||
|
||
use Illuminate\Validation\Rules\Password; | ||
|
||
trait PasswordValidationRules | ||
{ | ||
/** | ||
* Get the validation rules used to validate passwords. | ||
* | ||
* @return array<int, \Illuminate\Contracts\Validation\Rule|array|string> | ||
*/ | ||
protected function passwordRules(): array | ||
{ | ||
return ["required", "string", Password::default(), "confirmed"]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Actions\Fortify; | ||
|
||
use App\Models\User; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Facades\Validator; | ||
use Illuminate\Validation\ValidationException; | ||
use Laravel\Fortify\Contracts\UpdatesUserPasswords; | ||
|
||
class UpdateUserPassword implements UpdatesUserPasswords | ||
{ | ||
use PasswordValidationRules; | ||
|
||
/** | ||
* Validate and update the user's password. | ||
* | ||
* @param array<string, string> $input | ||
* @throws ValidationException | ||
*/ | ||
public function update(User $user, array $input): void | ||
{ | ||
Validator::make( | ||
$input, | ||
[ | ||
"current_password" => ["required", "string", "current_password:web"], | ||
"password" => $this->passwordRules(), | ||
], | ||
[ | ||
"current_password.current_password" => __("The provided password does not match your current password."), | ||
] | ||
) | ||
->validateWithBag("updatePassword"); | ||
|
||
$user->forceFill(["password" => Hash::make($input["password"])])->save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
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; | ||
|
||
class UpdateUserProfileInformation implements UpdatesUserProfileInformation | ||
{ | ||
/** | ||
* Validate and update the given user's profile information. | ||
* | ||
* @param array<string, string> $input | ||
*/ | ||
public function update(User $user, array $input): void | ||
{ | ||
Validator::make($input, | ||
[ | ||
"name" => ["required", "string", "max:255"], | ||
|
||
"username" => [ | ||
"required", | ||
"string", | ||
"max:255", | ||
Rule::unique("users")->ignore($user->id), | ||
], | ||
] | ||
) | ||
->validateWithBag("updateProfileInformation"); | ||
|
||
$user->forceFill([ | ||
"name" => $input["name"], | ||
"email" => $input["email"], | ||
]) | ||
->save(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Response; | ||
use Jdenticon\Identicon; | ||
|
||
class UserController | ||
{ | ||
public function identicon(string $username): Response | ||
{ | ||
$icon = new Identicon(); | ||
$icon->setValue($username); | ||
$icon->setSize(100); | ||
|
||
return response($icon->getImageData("svg"), 200) | ||
->header("Cache-Control", "max-age=604800") | ||
->header("Content-Type", "image/svg+xml"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Foundation\Auth\User as Authenticatable; | ||
/** | ||
* | ||
* | ||
* @property int $id | ||
* @property string $name | ||
* @property string $username | ||
* @property string $password | ||
* @property string|null $remember_token | ||
* @property \Illuminate\Support\Carbon|null $created_at | ||
* @property \Illuminate\Support\Carbon|null $updated_at | ||
* @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|User newQuery() | ||
* @method static \Illuminate\Database\Eloquent\Builder|User query() | ||
* @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedAt($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|User whereId($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|User whereName($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|User wherePassword($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|User whereRememberToken($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value) | ||
* @method static \Illuminate\Database\Eloquent\Builder|User whereUsername($value) | ||
* @mixin \Eloquent | ||
*/ | ||
class User extends Authenticatable | ||
{ | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = "users"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use App\Actions\Fortify\UpdateUserPassword; | ||
use App\Actions\Fortify\UpdateUserProfileInformation; | ||
use App\Models\User; | ||
use Illuminate\Cache\RateLimiting\Limit; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Hash; | ||
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. | ||
*/ | ||
public function register(): void | ||
{ | ||
} | ||
|
||
/** | ||
* Bootstrap any application services. | ||
*/ | ||
public function boot(): void | ||
{ | ||
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class); | ||
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class); | ||
|
||
Fortify::authenticateUsing(function (Request $request) { | ||
$user = User::whereUsername($request->username)->first(); | ||
|
||
if ($user && Hash::check($request->password, $user->password)) { | ||
return $user; | ||
} | ||
|
||
return null; | ||
}); | ||
|
||
Fortify::loginView(fn () => view("login")); | ||
|
||
RateLimiter::for("login", function (Request $request) { | ||
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())) . "|" . $request->ip()); | ||
|
||
return Limit::perMinute(5)->by($throttleKey); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\View\Components; | ||
|
||
use Closure; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\View\Component; | ||
|
||
class Layout extends Component | ||
{ | ||
/** | ||
* Create a new component instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Get the view / contents that represent the component. | ||
*/ | ||
public function render(): View|Closure|string | ||
{ | ||
return view('components.layout'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
|
||
return [ | ||
App\Providers\AppServiceProvider::class, | ||
App\Providers\FortifyServiceProvider::class, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.