108 lines
2.6 KiB
PHP
Executable File
108 lines
2.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Livewire\Component;
|
|
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
|
use Livewire\WithFileUploads;
|
|
|
|
|
|
class ShowPerfil extends Component
|
|
{
|
|
use LivewireAlert;
|
|
use WithFileUploads;
|
|
|
|
|
|
public $nombre;
|
|
public $email;
|
|
public $celular;
|
|
public $cedula;
|
|
public $rol;
|
|
public $url_imagen;
|
|
public $url_imagen_d;
|
|
public $url;
|
|
|
|
public $modalPassword = false;
|
|
|
|
public $newPassword;
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
{
|
|
if (empty($this->nombre)) {
|
|
|
|
$consulta_perfil = User::with('rol')->where('id', Auth()->user()->id)->first();
|
|
|
|
$this->nombre = $consulta_perfil->name;
|
|
$this->email = $consulta_perfil->email;
|
|
$this->celular = $consulta_perfil->celular;
|
|
$this->cedula = $consulta_perfil->cedula;
|
|
$this->rol = $consulta_perfil->rol->nombre;
|
|
$this->url_imagen_d = $consulta_perfil->img_perfil;
|
|
}
|
|
|
|
return view('livewire.show-perfil');
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
if ($this->url_imagen) {
|
|
$this->url = $this->url_imagen->store('photos');
|
|
} else {
|
|
$this->url = null;
|
|
}
|
|
|
|
if (!empty($this->nombre) && !empty($this->email) && !empty($this->celular) && !empty($this->cedula)) {
|
|
|
|
User::where('id', Auth()->user()->id)->update([
|
|
'name' => $this->nombre,
|
|
'email' => $this->email,
|
|
'celular' => $this->celular,
|
|
'cedula' => $this->cedula,
|
|
'img_perfil' => $this->url
|
|
]);
|
|
|
|
$this->alert('success', 'La informacion se actualizo correctamente!', [
|
|
'position' => 'top'
|
|
]);
|
|
} else {
|
|
$this->alert('warning', 'Llene todos los campos!', [
|
|
'position' => 'top'
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function cambiar_password()
|
|
{
|
|
$this->modalPassword = true;
|
|
}
|
|
|
|
public function confirmar()
|
|
{
|
|
$validatedData = $this->validate([
|
|
'newPassword' => 'required'
|
|
]);
|
|
|
|
$user = User::findOrFail(Auth()->user()->id);
|
|
$user->password = Hash::make($this->newPassword);
|
|
$user->save();
|
|
|
|
$this->alert('success', 'Contraseña actualizada correctamente!', [
|
|
'position' => 'top'
|
|
]);
|
|
|
|
$this->limpiarContra();
|
|
}
|
|
|
|
public function limpiarContra()
|
|
{
|
|
$this->newPassword = '';
|
|
$this->modalPassword = false;
|
|
}
|
|
|
|
}
|