mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-10 05:42:58 +00:00
add name change support & adjust profile list view
This commit is contained in:
parent
c7c621b086
commit
33d4ff5fb4
6 changed files with 74 additions and 26 deletions
|
|
@ -18,12 +18,16 @@ class AuthController extends Controller
|
|||
$user = Socialite::driver('authentik')->user();
|
||||
|
||||
$authUser = User::updateOrCreate(
|
||||
[ 'email' => $user->getEmail() ],
|
||||
[ 'name' => $user->getName() ]
|
||||
[ 'email' => $user->getEmail() ]
|
||||
);
|
||||
|
||||
if ($authUser)
|
||||
{
|
||||
if ($authUser->name == '')
|
||||
{
|
||||
$authUser->name = $user->getName();
|
||||
$authUser->save();
|
||||
}
|
||||
Auth::login($authUser);
|
||||
return redirect('/');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace App\Livewire\Pages;
|
|||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
|
|
@ -14,15 +15,39 @@ class Profile extends Component
|
|||
|
||||
public User $user;
|
||||
|
||||
#[Validate('image|max:10240')]
|
||||
public $avatar = null;
|
||||
public string $name = '';
|
||||
|
||||
public function mount(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->name = $user->name;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
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:80',
|
||||
Rule::unique('users', 'name')->ignore($this->user),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function updated($name, $value)
|
||||
{
|
||||
if (Auth::id() != $this->user->id)
|
||||
{
|
||||
|
|
@ -31,10 +56,16 @@ class Profile extends Component
|
|||
|
||||
$this->validate();
|
||||
|
||||
$this->user->avatarExt = $this->avatar->getClientOriginalExtension();
|
||||
$this->user->save();
|
||||
$this->user->update([$name => $value]);
|
||||
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue