Hey!
I have a User Reset Password page that lets an authenticated user reset their password by entering the following inputs:
*current password, new password, and confirm new password
When entering the inputs accordingly, the password changes and everything is good. But whenever I enter something wrong, I still get the success message and no error messages. Fortunately, the password remains the same and nothing is changed in the back-end.
Here is my VueJS component:
<template>
<div class="row">
<h1>Account Authentication</h1>
<a href="/dashboard/account">Account Profile</a>
<a href="account/authentication">Account Authentication</a>
<form class="form col-md-4 col-md-offset-4" role="form" @submit.prevent="onSubmit">
<div class="form-group">
<label for="password">{{ $t('form.old_password') }}</label>
<input type="password" class="form-control" id="old_password" :placeholder="$t('form.old_password')" name="old_password" v-model="new_password.old_password">
</div>
<div class="form-group">
<label for="password">{{ $t('form.new_password') }}</label>
<input type="password" class="form-control" id="password" :placeholder="$t('form.new_password')" name="password" v-model="new_password.password">
</div>
<div class="form-group">
<label for="new_password_confirmation">{{ $t('form.new_confirm_password') }}</label>
<input type="password" class="form-control" id="new_password_confirmation" :placeholder="$t('form.new_confirm_password')" name="password_confirmation" v-model="new_password.password_confirmation">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">{{ $t('form.update') }}</button>
</div>
</form>
</div>
</template>
<script>
import { stack_error } from 'config/helper'
export default {
data() {
return {
errors: [],
new_password: {
old_password: '',
password: '',
password_confirmation: ''
}
}
},
methods: {
onSubmit() {
let url = 'password/change'
let method = 'post'
this.$http[method](url, this.new_password)
.then((response) => {
this.new_password = {
old_password: '',
password: '',
password_confirmation: ''
};
swal({
title: 'Password Reset Successful!',
type: 'success',
});
}).catch((response) => {
stack_error(response);
});
}
},
}
</script>
Here is my UserController changePassword method:
public function changePassword(Request $request)
{
// Check if Current Password input field matches password in db
if (! Hash::check($request->get('old_password'), Auth::user()->password)) {
return redirect()->back()->withErrors(['old_password' => 'The password must match the current password.']);
}
Validator::make($request->all(), [
'old_password' => 'required|max:255',
'password' => 'required|min:6|confirmed',
])->validate();
// Call to UserRepository changPassword method
$this->user->changePassword(Auth::user(), $request->get('password'));
return redirect()->to('/dashboard/account');
}
The call to stack_error sends response to a swal error template. But for some reason, the invalid response that should include errors still passes through then.
If anyone could help me figure out why the invalid response still passes through then and why non of the errors don't show up it'll be greatly appreciated!
Please let me know if any more info is needed.