You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.6 KiB
66 lines
2.6 KiB
1 year ago
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\Auth;
|
||
|
|
||
|
use App\Models\User;
|
||
|
use Illuminate\Http\Request;
|
||
|
use App\Http\Controllers\Controller;
|
||
|
use Illuminate\Support\Facades\Hash;
|
||
|
use App\Models\ExpirarContrasena;
|
||
|
use DB;
|
||
|
|
||
|
class ExpirarContrasenaController extends Controller
|
||
|
{
|
||
|
public function showPasswordExpirationForm(Request $request){
|
||
|
//dd/trewq 0($request->password_expired_id);
|
||
|
$password_expired_id = $request->password_expired_id;
|
||
|
if(!isset($password_expired_id)){
|
||
|
return redirect('/login');
|
||
|
}
|
||
|
return view('auth.passwordExpiration', ['password_expired_id' => $password_expired_id]);
|
||
|
}
|
||
|
public function postPasswordExpiration(Request $request){
|
||
|
|
||
|
$password_expired_id = $request->password_expired_id;
|
||
|
if(!isset($password_expired_id)){
|
||
|
return redirect('/login');
|
||
|
}
|
||
|
$user = User::find($password_expired_id);
|
||
|
|
||
|
if (!(Hash::check($request->get('current-password'), $user->password))) {
|
||
|
|
||
|
// The passwords matches
|
||
|
return redirect()->back()->with('message', ['type'=> 'error', 'text' => 'Su contraseña actual no coincide, favor de intentarlo de nuevo.', 'title' => '¡Error!']);
|
||
|
}
|
||
|
if(strcmp($request->get('current-password'), $request->get('new-password')) == 0){
|
||
|
//Current password and new password are same
|
||
|
|
||
|
return redirect()->back()->with('message', ['type'=> 'error', 'text' => 'Su nueva contraseña no debe ser igual a su contraseña actual, favor de intentarlo de nuevo.', 'title' => '¡Error!']);
|
||
|
}
|
||
|
if(strcmp($request->get('repeat-password'), $request->get('new-password')) != 0){
|
||
|
//Current password and new password are same
|
||
|
|
||
|
return redirect()->back()->with('message', ['type'=> 'error', 'text' => 'Favor de repetir la contraseña correctamente, intentalo de nuevo.', 'title' => '¡Error!']);
|
||
|
}
|
||
|
|
||
|
|
||
|
// $validatedData = $request->validate([
|
||
|
// 'current-password' => 'required',
|
||
|
// 'new-password' => 'required|string|min:6',
|
||
|
// 'repeat-password' => 'required|string|min:6',
|
||
|
// ]);
|
||
|
|
||
|
// dd($validatedData);
|
||
|
|
||
|
//Change Password
|
||
|
$user->password = Hash::make($request->get('new-password'));
|
||
|
$user->save();
|
||
|
//Update password updation timestamp
|
||
|
ExpirarContrasena::where('fk_id_users',$user->id)->update([
|
||
|
'ultima_actualizacion' => now(),
|
||
|
'dias_expiracion' =>365
|
||
|
]);
|
||
|
return redirect('/')->with('message', ['type'=> 'success', 'text' => 'Su contraseña ah sido actualizada correctamente.', 'title' => '¡Éxito!']);
|
||
|
}
|
||
|
}
|