Skip to content

Commit

Permalink
#166 Added a restore password form
Browse files Browse the repository at this point in the history
  • Loading branch information
simba77 committed Feb 18, 2024
1 parent e31991b commit e4fa87d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
6 changes: 4 additions & 2 deletions system/helpers.php
Expand Up @@ -192,12 +192,14 @@ function redirect(string $url)
* @param array $queryParams
* @return string
*/
function route(string $routeName, array $params = [], array $queryParams = []): string
function route(string $routeName, array $params = [], array $queryParams = [], bool $withHost = false): string
{
$router = di(Router::class);
$url = $router->getUrlGenerator()->generate($routeName, $params);
$queryString = http_build_query($queryParams);
return str_replace('//', '/', $url) . (! empty($queryString) ? '?' . $queryString : '');
$url = str_replace('//', '/', $url) . (! empty($queryString) ? '?' . $queryString : '');

return ($withHost ? rtrim(config('johncms.home_url', ''), '/') : '') . $url;
}

/**
Expand Down
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Capsule\Manager as Capsule;

return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
$schema = Capsule::schema();
$schema->table('users', function (Blueprint $table) {
$table->string('restore_password_code')->nullable();
$table->dateTime('restore_password_date')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
$schema = Capsule::schema();
$schema->table('users', function (Blueprint $table) {
$table->dropColumn(['restore_password_code', 'restore_password_date']);
});
}
};
11 changes: 5 additions & 6 deletions system/src/Users/User.php
Expand Up @@ -44,6 +44,8 @@
* @property int|null $gender
* @property Carbon|null $birthday
* @property UserConfig $settings
* @property string|null $restore_password_code
* @property Carbon|null $restore_password_date
*
* @property StoredAuth[] $storedAuth
*
Expand All @@ -66,6 +68,7 @@ class User extends Model
'phone' => SpecialChars::class,
'settings' => UserSettings::class,
'additional_fields' => AdditionalFieldsCast::class,
'birthday' => 'date',
];

protected $fillable = [
Expand All @@ -84,14 +87,12 @@ class User extends Model
'settings',
'additional_fields',
'avatar_id',
'restore_password_code',
'restore_password_date',
];

protected $attributes = [];

protected $dates = [
'birthday',
];

protected ?UserRoleChecker $userRoleChecker = null;
protected ?UserPermissionChecker $userPermissionChecker = null;
protected ?UserBanChecker $userBanChecker = null;
Expand All @@ -109,12 +110,10 @@ private function setUpModel(): void
$casts = $modelConfig['casts'] ?? [];
$fillable = $modelConfig['fillable'] ?? [];
$attributes = $modelConfig['attributes'] ?? [];
$dates = $modelConfig['dates'] ?? [];

$this->casts = array_merge($this->casts, $casts);
$this->fillable = array_merge($this->fillable, $fillable);
$this->attributes = array_merge($this->attributes, $attributes);
$this->dates = array_merge($this->dates, $dates);
}

/**
Expand Down

0 comments on commit e4fa87d

Please sign in to comment.