#84 - fix remembering user (#89)

* #84 - fix remembering user

* #84 - ecs fix

* #84 - fix

* #84 - fix test

* #84 - wip

* #84 - add comment to observer

* #84 - cr fix

* Apply suggestions from code review

Co-authored-by: Krzysztof Rewak <krzysztof.rewak@blumilk.pl>

* #84 - cr fix

Co-authored-by: Krzysztof Rewak <krzysztof.rewak@blumilk.pl>
This commit is contained in:
Adrian Hopek 2022-03-21 14:36:18 +01:00 committed by GitHub
parent a0e60a3160
commit d8ac2bd61f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -4,11 +4,26 @@ declare(strict_types=1);
namespace Toby\Eloquent\Observers;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Support\Str;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\YearPeriod;
class UserObserver
{
public function __construct(
protected Hasher $hash,
) {}
public function creating(User $user): void
{
/**
* A random password for user is generated because AuthenticateSession middleware needs a user's password
* for some checks. Users use Google to login, so they don't need to know the password (GitHub issue #84)
*/
$user->password = $this->hash->make(Str::random(40));
}
public function created(User $user): void
{
$yearPeriods = YearPeriod::all();

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class() extends Migration {
public function up(): void
{
Schema::table("users", function (Blueprint $table): void {
$table->string("password")->nullable();
});
}
public function down(): void
{
Schema::table("users", function (Blueprint $table): void {
$table->dropColumn("password");
});
}
};