diff --git a/app/Http/Controllers/ChangePasswordController.php b/app/Http/Controllers/ChangePasswordController.php new file mode 100644 index 0000000..245883c --- /dev/null +++ b/app/Http/Controllers/ChangePasswordController.php @@ -0,0 +1,25 @@ +password = bcrypt($request->new_password); + + if ($user->save()) $updateResponse = array('success' => trans('auth.change_password_success')); + else $updateResponse = array('error' => trans('auth.change_password_error')); + + return redirect()->back()->with($updateResponse); + } +} diff --git a/app/Http/Requests/Users/UpdatePasswordRequest.php b/app/Http/Requests/Users/UpdatePasswordRequest.php new file mode 100644 index 0000000..dddc5ea --- /dev/null +++ b/app/Http/Requests/Users/UpdatePasswordRequest.php @@ -0,0 +1,39 @@ + 'min:6|max:15|current_password', + 'new_password' => 'min:6|max:15|same_password|confirmed', + ]; + } + + public function messages() + { + return [ + 'old_password.current_password' => trans('passwords.old_password'), + 'new_password.same_password' => trans('passwords.same_password'), + ]; + } +} diff --git a/app/Http/Requests/Users/UpdateRequest.php b/app/Http/Requests/Users/UpdateRequest.php index 6120915..e82c2b7 100644 --- a/app/Http/Requests/Users/UpdateRequest.php +++ b/app/Http/Requests/Users/UpdateRequest.php @@ -39,4 +39,12 @@ class UpdateRequest extends FormRequest 'password' => 'nullable|min:6|max:15', ]; } + + public function messages() + { + return [ + 'password.current_password' => trans('passwords.old_password'), + 'new_password.same_password' => trans('passwords.same_password'), + ]; + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 3a88480..d1e26f7 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -19,6 +19,18 @@ class AppServiceProvider extends ServiceProvider if($this->app->environment() === 'production') { $this->app['request']->server->set('HTTPS', true); } + + \Validator::extend('current_password', function ($attribute, $value, $parameters, $validator) { + $user = \Auth::user(); + + return $user && \Hash::check($value, $user->password); + }); + + \Validator::extend('same_password', function ($attribute, $value, $parameters, $validator) { + $user = \Auth::user(); + + return $user && !\Hash::check($value, $user->password); + }); } /** diff --git a/resources/lang/en/auth.php b/resources/lang/en/auth.php index 619bcaa..c97edf2 100644 --- a/resources/lang/en/auth.php +++ b/resources/lang/en/auth.php @@ -19,6 +19,7 @@ return [ 'password' => 'Password', 'login' => 'Login', 'logout' => 'Logout', + 'back' => 'Back', 'register' => 'Create new Account', 'have_an_account' => 'I have an Account', 'need_account' => 'Need an Account?', @@ -30,4 +31,6 @@ return [ 'new_password' => 'New Password', 'new_password_confirmation' => 'Repeat New Password', 'send_reset_password_link' => 'Send Reset Password Link', + 'change_password_success' => 'Your password has changed', + 'change_password_error' => 'Uh-oh, change password failed', ]; diff --git a/resources/lang/en/passwords.php b/resources/lang/en/passwords.php index ffa19ba..58420ea 100644 --- a/resources/lang/en/passwords.php +++ b/resources/lang/en/passwords.php @@ -18,5 +18,6 @@ return [ 'sent' => 'We have e-mailed your password reset link!', 'token' => 'This password reset token is invalid.', 'user' => "We can't find a user with that e-mail address.", - + "old_password" => "Your current password does not matches with the password you provided. Please try again.", + "same_password" => "New password cannot be same as your current password. Please choose a different password." ]; diff --git a/resources/lang/id/auth.php b/resources/lang/id/auth.php index ced9b61..eb08388 100644 --- a/resources/lang/id/auth.php +++ b/resources/lang/id/auth.php @@ -19,6 +19,7 @@ return [ 'password' => 'Password', 'login' => 'Login', 'logout' => 'Keluar', + 'back' => 'Kembali', 'register' => 'Buat Akun Baru', 'have_an_account' => 'Saya sudah punya Akun', 'need_account' => 'Belum punya Akun?', @@ -30,4 +31,6 @@ return [ 'new_password' => 'Password Baru', 'new_password_confirmation' => 'Ulangi Password Baru', 'send_reset_password_link' => 'Kirim Link Reset Password', + 'change_password_success' => 'Password Anda sudah berhasil di ubah.', + 'change_password_error' => 'Awww, sistem gagal merubah password Anda', ]; diff --git a/resources/lang/id/passwords.php b/resources/lang/id/passwords.php index 537a674..2682785 100644 --- a/resources/lang/id/passwords.php +++ b/resources/lang/id/passwords.php @@ -18,5 +18,7 @@ return [ "sent" => "Kami sudah mengirim email yang berisi tautan untuk mereset Password Anda!", "token" => "Token Reset Password tidak sah.", "user" => "Kami tidak dapat menemukan pengguna dengan email tersebut.", + "old_password" => "Password yang Anda masukan tidak sesuai dengan password yang tersimpan. Silahkan coba kembali.", + "same_password" => "Password baru Anda tidak boleh sama dengan password lama. Silahkan pilih password yang berbeda." ]; diff --git a/resources/views/layouts/partials/nav.blade.php b/resources/views/layouts/partials/nav.blade.php index 116cf73..e8727d6 100644 --- a/resources/views/layouts/partials/nav.blade.php +++ b/resources/views/layouts/partials/nav.blade.php @@ -40,6 +40,7 @@