* #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:
parent
a0e60a3160
commit
d8ac2bd61f
@ -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();
|
||||
|
@ -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");
|
||||
});
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user