feat: redo user flow
This commit is contained in:
parent
a61f6cae81
commit
19f07b0068
123
app/Console/Commands/CreateUserCommand.php
Normal file
123
app/Console/Commands/CreateUserCommand.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Enums\UserStatus;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
use function Laravel\Prompts\password;
|
||||
use function Laravel\Prompts\select;
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
class CreateUserCommand extends Command
|
||||
{
|
||||
protected $signature = 'create:user';
|
||||
|
||||
protected $description = 'Command description';
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$firstName = text(
|
||||
label: 'What is your first name?',
|
||||
placeholder: 'E.g. Michael',
|
||||
required: 'Your first name is required.',
|
||||
);
|
||||
|
||||
$lastName = text(
|
||||
label: 'What is your last name?',
|
||||
placeholder: 'E.g. Price',
|
||||
required: 'Your last name is required.',
|
||||
);
|
||||
|
||||
$emailAddress = text(
|
||||
label: 'What is your email address?',
|
||||
placeholder: 'E.g. mprice@nexigen.digital',
|
||||
required: 'Your email is required.',
|
||||
validate: function (string $value) {
|
||||
$validator = Validator::make([
|
||||
'email' => $value,
|
||||
], [
|
||||
'email' => ['required', 'email:rfc', Rule::unique(User::class, 'email')]
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $validator->messages()->first();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$uuid = text(
|
||||
label: 'What is your uuid?',
|
||||
placeholder: 'E.g. U05ES1730UE',
|
||||
required: 'Your uuid is required.',
|
||||
validate: function (string $value) {
|
||||
$validator = Validator::make([
|
||||
'uuid' => $value,
|
||||
], [
|
||||
'uuid' => ['required', Rule::unique(User::class, 'uuid')]
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $validator->messages()->first();
|
||||
}
|
||||
},
|
||||
hint: 'This is your slack User ID.'
|
||||
);
|
||||
|
||||
$profilePic = text(
|
||||
label: 'What is your profile pic?',
|
||||
placeholder: 'E.g. https://secure.gravatar.com/avatar/f2ca68078ae3b3228b0307c20ae84dd2.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-512.png',
|
||||
required: 'Your url is required.',
|
||||
validate: function (string $value) {
|
||||
$validator = Validator::make([
|
||||
'url' => $value,
|
||||
], [
|
||||
'url' => ['required', 'url']
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $validator->messages()->first();
|
||||
}
|
||||
},
|
||||
hint: 'This is your slack profile url.'
|
||||
);
|
||||
|
||||
$isAdmin = select(
|
||||
label: 'Is your account an admin?',
|
||||
options: [
|
||||
true => 'Yes',
|
||||
false =>'No'
|
||||
],
|
||||
);
|
||||
|
||||
$password = password(
|
||||
label: 'What is your password?',
|
||||
placeholder: '**********',
|
||||
hint: 'One will be randomly generated if non is provided',
|
||||
);
|
||||
|
||||
if (empty($password)) {
|
||||
$password = Str::password(12);
|
||||
$this->info("Randomly Generated Password: $password");
|
||||
}
|
||||
|
||||
User::create([
|
||||
'firstname' => $firstName,
|
||||
'lastname' => $lastName,
|
||||
'email' => $emailAddress,
|
||||
'uuid' => $uuid,
|
||||
'profile' => $profilePic,
|
||||
'status' => UserStatus::ACTIVE,
|
||||
'is_admin' => $isAdmin,
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
$this->info('Complete!');
|
||||
}
|
||||
}
|
||||
15
app/Enums/UserStatus.php
Normal file
15
app/Enums/UserStatus.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\EnumOptions;
|
||||
use App\Traits\EnumValues;
|
||||
|
||||
enum UserStatus: int
|
||||
{
|
||||
use EnumValues;
|
||||
use EnumOptions;
|
||||
|
||||
case ACTIVE = 1;
|
||||
case INACTIVE = 0;
|
||||
}
|
||||
@ -17,8 +17,13 @@ class User extends Authenticatable
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'firstname',
|
||||
'lastname',
|
||||
'email',
|
||||
'uuid',
|
||||
'profile',
|
||||
'status',
|
||||
'is_admin',
|
||||
'password',
|
||||
];
|
||||
|
||||
@ -38,7 +43,6 @@ class User extends Authenticatable
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
26
app/Traits/EnumOptions.php
Normal file
26
app/Traits/EnumOptions.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait EnumOptions
|
||||
{
|
||||
public static function options(): array
|
||||
{
|
||||
$cases = static::cases();
|
||||
$options = [];
|
||||
foreach ($cases as $case) {
|
||||
$label = $case->name;
|
||||
if (Str::contains($label, '_')) {
|
||||
$label = Str::replace('_', ' ', $label);
|
||||
}
|
||||
$options[] = [
|
||||
'value' => $case->value,
|
||||
'label' => Str::title($label),
|
||||
];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
11
app/Traits/EnumValues.php
Normal file
11
app/Traits/EnumValues.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait EnumValues
|
||||
{
|
||||
public static function values(): array
|
||||
{
|
||||
return array_column(self::cases(), 'value');
|
||||
}
|
||||
}
|
||||
@ -13,9 +13,13 @@ return new class extends Migration
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('firstname');
|
||||
$table->string('lastname');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('uuid')->unique();
|
||||
$table->string('profile');
|
||||
$table->string('status');
|
||||
$table->string('is_admin');
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('personal_access_tokens', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->morphs('tokenable');
|
||||
$table->string('name');
|
||||
$table->string('token', 64)->unique();
|
||||
$table->text('abilities')->nullable();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamp('expires_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('personal_access_tokens');
|
||||
}
|
||||
};
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
<a {{ $attributes }} class="
|
||||
{{ Route::is($route)
|
||||
? 'text-nexi-red bg-gray-50 dark:text-nexi-purple dark:bg-zinc-800'
|
||||
: 'text-nexi-black dark:text-nexi-grey hover:text-nexi-red dark:hover:text-nexi-red hover:bg-gray-100 dark:hover:bg-zinc-500' }}
|
||||
? 'text-nexi-red bg-gray-50 dark:text-nexi-purple dark:bg-zinc-800 transition-colors duration-300'
|
||||
: 'text-nexi-black dark:text-nexi-grey hover:text-nexi-red dark:hover:text-nexi-red hover:bg-gray-100 dark:hover:bg-zinc-500 transition-colors duration-300' }}
|
||||
group flex items-center px-2 py-2 text-base font-medium rounded-md"
|
||||
>{{ $slot }}</a>
|
||||
|
||||
@ -44,9 +44,15 @@ new class extends Component
|
||||
aria-expanded="false"
|
||||
aria-haspopup="true">
|
||||
{{-- TODO: Add User Image URL here --}}
|
||||
<img class="h-8 w-8 rounded-full bg-gray-50" src="" alt="">
|
||||
<img class="h-8 w-8 rounded-full bg-gray-50" src="{{ auth()->user()->profile }}" alt="">
|
||||
<span class="hidden lg:flex lg:items-center">
|
||||
<span class="ml-4 text-base font-semibold leading-6 text-nexi-black dark:text-nexi-grey" aria-hidden="true" x-data="{ name: '{{ auth()->user()->name }}' }" x-text="name" x-on:profile-updated.window="name = $event.detail.name"></span>
|
||||
<span class="ml-4 text-base font-semibold leading-6 text-nexi-black dark:text-nexi-grey" aria-hidden="true"
|
||||
x-data="{ firstname: '{{ auth()->user()->firstname }}', lastname: '{{ auth()->user()->lastname }}' }"
|
||||
x-text="firstname + ' ' + lastname"
|
||||
x-on:profile-updated.window="
|
||||
firstname = $event.detail.firstname;
|
||||
lastname = $event.detail.lastname;
|
||||
"></span>
|
||||
<svg class="ml-2 h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
||||
<path fill-rule="evenodd" d="M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
|
||||
@ -8,12 +8,14 @@ use Livewire\Volt\Component;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
public string $name = '';
|
||||
public string $firstname = '';
|
||||
public string $lastname = '';
|
||||
public string $email = '';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->name = auth()->user()->name;
|
||||
$this->firstname = auth()->user()->firstname;
|
||||
$this->lastname = auth()->user()->lastname;
|
||||
$this->email = auth()->user()->email;
|
||||
}
|
||||
|
||||
@ -22,7 +24,8 @@ new class extends Component
|
||||
$user = auth()->user();
|
||||
|
||||
$validated = $this->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'firstname' => ['required', 'string', 'max:255'],
|
||||
'lastname' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'email', 'max:255', Rule::unique(User::class)->ignore($user->id)],
|
||||
]);
|
||||
|
||||
@ -36,23 +39,6 @@ new class extends Component
|
||||
|
||||
$this->dispatch('profile-updated', name: $user->name);
|
||||
}
|
||||
|
||||
public function sendVerification(): void
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->hasVerifiedEmail()) {
|
||||
$path = session('url.intended', RouteServiceProvider::HOME);
|
||||
|
||||
$this->redirect($path);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$user->sendEmailVerificationNotification();
|
||||
|
||||
session()->flash('status', 'verification-link-sent');
|
||||
}
|
||||
}; ?>
|
||||
|
||||
<section>
|
||||
@ -68,33 +54,21 @@ new class extends Component
|
||||
|
||||
<form wire:submit="updateProfileInformation" class="mt-6 space-y-6">
|
||||
<div>
|
||||
<x-input-label for="name" :value="__('Name')" />
|
||||
<x-text-input wire:model="name" id="name" name="name" type="text" class="mt-1 block w-full" required autofocus autocomplete="name" />
|
||||
<x-input-error class="mt-2" :messages="$errors->get('name')" />
|
||||
<x-input-label for="firstname" :value="__('FirstName')" />
|
||||
<x-text-input wire:model="firstname" id="firstname" name="firstname" type="text" class="mt-1 block w-full" required autofocus autocomplete="first" />
|
||||
<x-input-error class="mt-2" :messages="$errors->get('firstname')" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<x-input-label for="lastname" :value="__('lastname')" />
|
||||
<x-text-input wire:model="lastname" id="lastname" name="lastname" type="text" class="mt-1 block w-full" required autofocus autocomplete="last" />
|
||||
<x-input-error class="mt-2" :messages="$errors->get('lastname')" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<x-input-label for="email" :value="__('Email')" />
|
||||
<x-text-input wire:model="email" id="email" name="email" type="email" class="mt-1 block w-full" required autocomplete="username" />
|
||||
<x-input-error class="mt-2" :messages="$errors->get('email')" />
|
||||
|
||||
@if (auth()->user() instanceof MustVerifyEmail && ! auth()->user()->hasVerifiedEmail())
|
||||
<div>
|
||||
<p class="text-sm mt-2 text-nexi-black dark:text-gray-200">
|
||||
{{ __('Your email address is unverified.') }}
|
||||
|
||||
<button wire:click.prevent="sendVerification" class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-nexi-black dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-nexi-black">
|
||||
{{ __('Click here to re-send the verification email.') }}
|
||||
</button>
|
||||
</p>
|
||||
|
||||
@if (session('status') === 'verification-link-sent')
|
||||
<p class="mt-2 font-medium text-sm text-green-600 dark:text-green-400">
|
||||
{{ __('A new verification link has been sent to your email address.') }}
|
||||
</p>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
|
||||
Reference in New Issue
Block a user