mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-10 05:42:58 +00:00
add profile pictures & (attempt) fix uploads
This commit is contained in:
parent
2aa0689720
commit
bb15fc96b4
8 changed files with 92 additions and 9 deletions
20
app/Livewire/App/Pfp.php
Normal file
20
app/Livewire/App/Pfp.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\App;
|
||||
|
||||
use App\Models\User;
|
||||
use Livewire\Component;
|
||||
|
||||
class Pfp extends Component
|
||||
{
|
||||
public User $user;
|
||||
public string $size = '3rem';
|
||||
public string $shape = 'circle';
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.app.pfp', [
|
||||
'pfp' => $this->user->getAvatarBase64()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,14 +3,38 @@
|
|||
namespace App\Livewire\Pages;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
class Profile extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public User $user;
|
||||
|
||||
#[Validate('image|max:10240')]
|
||||
public $avatar = null;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.pages.profile')->title($this->user->name);
|
||||
}
|
||||
|
||||
public function updated($name, $value)
|
||||
{
|
||||
if (Auth::id() != $this->user->id)
|
||||
{
|
||||
abort(401);
|
||||
}
|
||||
|
||||
$this->validateOnly($name);
|
||||
|
||||
$this->user->avatarExt = $this->avatar->getClientOriginalExtension();
|
||||
$this->user->save();
|
||||
|
||||
$this->avatar->storeAs('avatars', $this->user->id);
|
||||
return $this->redirect("/profiles/{$this->user->id}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace App\Models;
|
|||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use MongoDB\Laravel\Auth\User as Authenticatable;
|
||||
use MongoDB\Laravel\Relations\HasMany;
|
||||
|
|
@ -21,6 +22,7 @@ class User extends Authenticatable implements Searchable
|
|||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'avatarExt',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
|
|
@ -55,4 +57,12 @@ class User extends Authenticatable implements Searchable
|
|||
$url
|
||||
);
|
||||
}
|
||||
|
||||
public function getAvatarBase64(): string
|
||||
{
|
||||
$ext = $this->avatarExt;
|
||||
$file = Storage::get("avatars/$this->id");
|
||||
$data = base64_encode($file);
|
||||
return "data:image/$ext;base64,$data";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue