5 changed files with 55 additions and 84 deletions
-
47app/Http/Controllers/Auth/ChangePasswordController.php
-
41app/Http/Controllers/AuthController.php
-
43app/Http/Requests/Accounts/ChangePasswordRequest.php
-
2resources/views/auth/passwords/change.blade.php
-
6routes/web/account.php
@ -0,0 +1,47 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Http\Controllers\Auth; |
||||
|
|
||||
|
use App\Http\Controllers\Controller; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class ChangePasswordController extends Controller |
||||
|
{ |
||||
|
/** |
||||
|
* Create a new controller instance. |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
$this->middleware('auth'); |
||||
|
} |
||||
|
|
||||
|
public function show() |
||||
|
{ |
||||
|
return view('auth.passwords.change'); |
||||
|
} |
||||
|
|
||||
|
public function update(Request $request) |
||||
|
{ |
||||
|
$input = $request->validate([ |
||||
|
'old_password' => 'required', |
||||
|
'password' => 'required|between:6,15|confirmed', |
||||
|
'password_confirmation' => 'required', |
||||
|
]); |
||||
|
|
||||
|
if (app('hash')->check($input['old_password'], auth()->user()->password)) |
||||
|
{ |
||||
|
$user = auth()->user(); |
||||
|
$user->password = $input['password']; |
||||
|
$user->save(); |
||||
|
|
||||
|
flash(trans('auth.password_changed'), 'success'); |
||||
|
return back(); |
||||
|
} |
||||
|
|
||||
|
flash(trans('auth.old_password_failed'), 'danger'); |
||||
|
return back(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -1,43 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Http\Requests\Accounts; |
|
||||
|
|
||||
use App\Http\Requests\Request; |
|
||||
|
|
||||
class ChangePasswordRequest extends Request |
|
||||
{ |
|
||||
/** |
|
||||
* Determine if the user is authorized to make this request. |
|
||||
* |
|
||||
* @return bool |
|
||||
*/ |
|
||||
public function authorize() |
|
||||
{ |
|
||||
return auth()->check(); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Get the validation rules that apply to the request. |
|
||||
* |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function rules() |
|
||||
{ |
|
||||
return [ |
|
||||
'old_password' => 'required', |
|
||||
'password' => 'required|between:6,15|confirmed', |
|
||||
'password_confirmation' => 'required', |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
public function messages() |
|
||||
{ |
|
||||
return [ |
|
||||
'old_password.required' => 'Password lama harus diisi.', |
|
||||
'password.required' => 'Password baru harus diisi.', |
|
||||
'password.between' => 'Password baru harus antara 6 - 15 karakter.', |
|
||||
'password.confirmed' => 'Konfirmasi password baru tidak sesuai.', |
|
||||
'password_confirmation.required' => 'Konfirmasi password baru harus diisi.', |
|
||||
]; |
|
||||
} |
|
||||
} |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue