40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use Illuminate\Http\Request;
|
||
|
use App\Rules\ComparePasswords;
|
||
|
use Illuminate\Support\Facades\Hash;
|
||
|
use App\User;
|
||
|
|
||
|
class ChangePasswordController extends Controller
|
||
|
{
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->middleware('auth');
|
||
|
}
|
||
|
|
||
|
public function create()
|
||
|
{
|
||
|
return view('changePassword');
|
||
|
}
|
||
|
|
||
|
|
||
|
public function update(Request $request)
|
||
|
{
|
||
|
$request->validate([
|
||
|
'current_password' => new ComparePasswords,
|
||
|
'password' => 'required|confirmed|min:6|different:current_password',
|
||
|
],
|
||
|
[
|
||
|
'required' => 'Podaj nowe hasło.',
|
||
|
'confirmed' => 'Nowe hasło się nie zgadza.',
|
||
|
'min' => ':attribute musi mieć przynajmniej :min znaków.',
|
||
|
'different' => 'Stare i nowe hasło nie mogą być identyczne.'
|
||
|
]);
|
||
|
|
||
|
User::find(auth()->user()->id)->update(['password'=> $request-> password]);
|
||
|
|
||
|
return redirect()->to('/userprofile')->with('success','Hasło zostało zmienione');
|
||
|
}
|
||
|
}
|