diff --git a/app/Http/Controllers/Auth/ChangePasswordController.php b/app/Http/Controllers/Auth/ChangePasswordController.php new file mode 100644 index 0000000..e5f7309 --- /dev/null +++ b/app/Http/Controllers/Auth/ChangePasswordController.php @@ -0,0 +1,56 @@ +middleware('auth'); + } + + public function getChangePassword() + { + return view('auth.passwords.change'); + } + + protected function postChangePassword(Request $req) + { + $this->validate($req, [ + 'old_password' => 'required', + 'password' => 'required|between:6,15|confirmed', + 'password_confirmation' => 'required', + ], [ + '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.', + ]); + + $input = $req->except('_token'); + + if (app('hash')->check($input['old_password'], auth()->user()->password)) + { + $user = auth()->user(); + $user->password = $input['password']; + $user->save(); + + flash()->success(trans('auth.old_password_success')); + return back(); + } + + flash()->error(trans('auth.old_password_failed')); + return back(); + + } + +} diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php deleted file mode 100644 index 17c0a64..0000000 --- a/app/Http/Controllers/Auth/RegisterController.php +++ /dev/null @@ -1,73 +0,0 @@ -middleware('guest'); - } - - /** - * Get a validator for an incoming registration request. - * - * @param array $data - * - * @return \Illuminate\Contracts\Validation\Validator - */ - protected function validator(array $data) - { - return Validator::make($data, [ - 'name' => 'required|string|max:255', - 'email' => 'required|string|email|max:255|unique:users', - 'password' => 'required|string|min:6|confirmed', - ]); - } - - /** - * Create a new user instance after a valid registration. - * - * @param array $data - * - * @return User - */ - protected function create(array $data) - { - return User::create([ - 'name' => $data['name'], - 'email' => $data['email'], - 'password' => bcrypt($data['password']), - ]); - } -} diff --git a/resources/views/auth/passwords/change.blade.php b/resources/views/auth/passwords/change.blade.php new file mode 100644 index 0000000..f687d38 --- /dev/null +++ b/resources/views/auth/passwords/change.blade.php @@ -0,0 +1,22 @@ +@extends('layouts.app') + +@section('title', trans('auth.change_password')) + +@section('content') +
+
+

{{ trans('auth.change_password') }}

+ {!! Form::open(['route'=>'change-password']) !!} +
+ {!! FormField::password('old_password', ['label'=> trans('auth.old_password')]) !!} + {!! FormField::password('password', ['label'=>trans('auth.new_password')]) !!} + {!! FormField::password('password_confirmation', ['label'=>trans('auth.new_password_confirmation')]) !!} +
+ + {!! Form::close() !!} +
+
+@endsection diff --git a/resources/views/layouts/partials/top-nav.blade.php b/resources/views/layouts/partials/top-nav.blade.php index dc2d61f..1877403 100644 --- a/resources/views/layouts/partials/top-nav.blade.php +++ b/resources/views/layouts/partials/top-nav.blade.php @@ -55,6 +55,7 @@