user profile updates

This commit is contained in:
yuriko 🦊 2025-07-26 15:06:05 -04:00
parent c7c621b086
commit ea140671bc
9 changed files with 78 additions and 27 deletions

View file

@ -19,11 +19,15 @@ class AuthController extends Controller
$authUser = User::updateOrCreate( $authUser = User::updateOrCreate(
[ 'email' => $user->getEmail() ], [ 'email' => $user->getEmail() ],
[ 'name' => $user->getName() ]
); );
if ($authUser) if ($authUser)
{ {
if ($authUser->name == '')
{
$authUser->name = $user->getName();
$authUser->save();
}
Auth::login($authUser); Auth::login($authUser);
return redirect('/'); return redirect('/');
} }

View file

@ -6,6 +6,8 @@ use Livewire\Component;
class Icon extends Component class Icon extends Component
{ {
public string $family = 'classic';
public string $variant = 'light';
public string $name = 'paw-simple'; public string $name = 'paw-simple';
public string $label = ''; public string $label = '';
public string $style = ''; public string $style = '';

View file

@ -4,6 +4,7 @@ namespace App\Livewire\Pages;
use App\Models\User; use App\Models\User;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
use Livewire\Attributes\Validate; use Livewire\Attributes\Validate;
use Livewire\Component; use Livewire\Component;
use Livewire\WithFileUploads; use Livewire\WithFileUploads;
@ -14,15 +15,39 @@ class Profile extends Component
public User $user; public User $user;
#[Validate('image|max:10240')]
public $avatar = null; public $avatar = null;
public string $name = '';
public function mount(User $user)
{
$this->user = $user;
$this->name = $user->name;
}
public function render() public function render()
{ {
return view('livewire.pages.profile')->title($this->user->name); return view('livewire.pages.profile')->title($this->user->name);
} }
public function updated() public function rules()
{
return [
'avatar' => [
'nullable',
'image',
'max:10240',
],
'name' => [
'required',
'string',
'min:2',
'max:40',
Rule::unique('users', 'name')->ignore($this->user),
],
];
}
public function updated($name, $value)
{ {
if (Auth::id() != $this->user->id) if (Auth::id() != $this->user->id)
{ {
@ -31,10 +56,16 @@ class Profile extends Component
$this->validate(); $this->validate();
$this->user->avatarExt = $this->avatar->getClientOriginalExtension(); $this->user->update([ $name => $value ]);
$this->user->save();
if (isset($this->avatar))
{
$this->user->avatarExt = $this->avatar->getClientOriginalExtension();
$this->user->save();
$this->avatar->storeAs('avatars', $this->user->id);
return $this->redirect("/profiles/{$this->user->id}");
}
$this->avatar->storeAs('avatars', $this->user->id);
return $this->redirect("/profiles/{$this->user->id}");
} }
} }

2
package-lock.json generated
View file

@ -1,5 +1,5 @@
{ {
"name": "photos", "name": "nyaabooru",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {

View file

@ -7,6 +7,8 @@
<span class="wa-caption-l">&copy; 2025 <a href="https://nyaastudios.io" target="_blank">NyaaStudios</a>; All rights reserved.</span> <span class="wa-caption-l">&copy; 2025 <a href="https://nyaastudios.io" target="_blank">NyaaStudios</a>; All rights reserved.</span>
</div> </div>
<div class="wa-cluster wa-heading-m"> <div class="wa-cluster wa-heading-m">
<wa-icon-button family="brands" name="github" href="https://github.com/NyaaStudios/nyaabooru" target="_blank"></wa-icon-button> <a href="https://github.com/NyaaStudios/nyaabooru" class="wa-link-plain" target="_blank">
<livewire:app.icon family="brands" name="github" />
</a>
</div> </div>
</div> </div>

View file

@ -1,6 +1,7 @@
<wa-icon <wa-icon
name="{{ $name }}" name="{{ $name }}"
variant="light" family="{{ $family }}"
variant="{{ $variant }}"
label="{{ $label }}" label="{{ $label }}"
fixed-width fixed-width
@isset($slot) @isset($slot)

View file

@ -5,4 +5,6 @@
label="avatar for {{ $user->name }}" label="avatar for {{ $user->name }}"
shape="{{ $shape }}" shape="{{ $shape }}"
style="--size: {{ $size }}" style="--size: {{ $size }}"
></wa-avatar> >
<livewire:app.icon name="user" slot="icon" size="2.5rem" />
</wa-avatar>

View file

@ -1,13 +1,11 @@
<article class="wa-stack nyaabooru-pfp"> <wa-card>
<a class="wa-frame wa-border-radius-l" style="inline-size: 15rem;" href="{{ url("/profiles/$user->id") }}" wire:navigate.hover> <a class="wa-stack nyaabooru-pfp wa-link-plain" href="{{ url("/profiles/$user->id") }}" wire:navigate.hover>
@if (\Illuminate\Support\Facades\Storage::has("avatars/$user->id")) <div class="wa-frame wa-border-radius-l" style="inline-size: 10rem;" >
<img src="{{ $user->getAvatarBase64() }}"/> <livewire:app.pfp :$user size="10rem" />
@else </div>
<livewire:app.icon name="user" /> <div class="wa-stack wa-gap-3xs">
@endif <span class="wa-heading-s">{{ $user->name }}</span>
<span class="wa-caption-m">Joined <wa-format-date value="{{ $user->created_at }}"></wa-format-date></span>
</div>
</a> </a>
<div class="wa-stack wa-gap-3xs"> </wa-card>
<span class="wa-heading-s">{{ $user->name }}</span>
<span class="wa-caption-m">Joined <wa-format-date value="{{ $user->created_at }}"></wa-format-date></span>
</div>
</article>

View file

@ -23,10 +23,21 @@
<h2>User settings</h2> <h2>User settings</h2>
<form wire:submit> <form wire:submit>
<wa-card> <wa-card>
<div class="wa-stack"> <div class="wa-stack wa-gap-l">
<span class="wa-heading-m">Profile picture</span> <div class="wa-stack">
<input type="file" wire:model.live="avatar" wire:loading.attr="disabled" /> <span class="wa-heading-m">Profile picture</span>
@error('avatar') <input type="file" wire:model.live="avatar" wire:loading.attr="disabled" />
@error('avatar')
<span class="wa-caption-m">{{ $message }}</span>
@enderror
</div>
<wa-divider></wa-divider>
<wa-input wire:model.live="name" label="Display name">
<livewire:app.icon slot="start" name="user-tag" />
</wa-input>
@error('name')
<span class="wa-caption-m">{{ $message }}</span> <span class="wa-caption-m">{{ $message }}</span>
@enderror @enderror
</div> </div>