2019-08-14 09:48:44 +00:00
|
|
|
<template>
|
2020-02-16 11:50:38 +00:00
|
|
|
<form
|
|
|
|
class="login-box medium-4 column align-self-middle"
|
|
|
|
@submit.prevent="login()"
|
|
|
|
>
|
2019-08-14 09:48:44 +00:00
|
|
|
<div class="column log-in-form">
|
2020-02-16 11:50:38 +00:00
|
|
|
<h4>{{ $t('SET_NEW_PASSWORD.TITLE') }}</h4>
|
|
|
|
<label :class="{ error: $v.credentials.password.$error }">
|
|
|
|
{{ $t('LOGIN.PASSWORD.LABEL') }}
|
|
|
|
<input
|
|
|
|
v-model.trim="credentials.password"
|
|
|
|
type="password"
|
|
|
|
:placeholder="$t('SET_NEW_PASSWORD.PASSWORD.PLACEHOLDER')"
|
|
|
|
@input="$v.credentials.password.$touch"
|
|
|
|
/>
|
|
|
|
<span v-if="$v.credentials.password.$error" class="message">
|
|
|
|
{{ $t('SET_NEW_PASSWORD.PASSWORD.ERROR') }}
|
2019-08-14 09:48:44 +00:00
|
|
|
</span>
|
|
|
|
</label>
|
2020-02-16 11:50:38 +00:00
|
|
|
<label :class="{ error: $v.credentials.confirmPassword.$error }">
|
|
|
|
{{ $t('SET_NEW_PASSWORD.CONFIRM_PASSWORD.LABEL') }}
|
|
|
|
<input
|
|
|
|
v-model.trim="credentials.confirmPassword"
|
|
|
|
type="password"
|
|
|
|
:placeholder="$t('SET_NEW_PASSWORD.CONFIRM_PASSWORD.PLACEHOLDER')"
|
|
|
|
@input="$v.credentials.confirmPassword.$touch"
|
|
|
|
/>
|
|
|
|
<span v-if="$v.credentials.confirmPassword.$error" class="message">
|
|
|
|
{{ $t('SET_NEW_PASSWORD.CONFIRM_PASSWORD.ERROR') }}
|
2019-08-14 09:48:44 +00:00
|
|
|
</span>
|
|
|
|
</label>
|
|
|
|
<woot-submit-button
|
2020-02-16 11:50:38 +00:00
|
|
|
:disabled="
|
|
|
|
$v.credentials.password.$invalid ||
|
|
|
|
$v.credentials.confirmPassword.$invalid ||
|
|
|
|
newPasswordAPI.showLoading
|
|
|
|
"
|
2019-08-14 09:48:44 +00:00
|
|
|
:button-text="$t('SET_NEW_PASSWORD.SUBMIT')"
|
|
|
|
:loading="newPasswordAPI.showLoading"
|
|
|
|
button-class="expanded"
|
2022-06-10 13:59:52 +00:00
|
|
|
/>
|
2019-08-14 09:48:44 +00:00
|
|
|
<!-- <input type="submit" class="button " v-on:click.prevent="login()" v-bind:value="" > -->
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { required, minLength } from 'vuelidate/lib/validators';
|
|
|
|
import Auth from '../../api/auth';
|
|
|
|
|
|
|
|
import WootSubmitButton from '../../components/buttons/FormSubmitButton';
|
2021-05-28 13:51:16 +00:00
|
|
|
import { DEFAULT_REDIRECT_URL } from '../../constants';
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
WootSubmitButton,
|
|
|
|
},
|
|
|
|
props: {
|
2021-12-27 08:19:31 +00:00
|
|
|
resetPasswordToken: { type: String, default: '' },
|
|
|
|
redirectUrl: { type: String, default: '' },
|
|
|
|
config: { type: String, default: '' },
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
// We need to initialize the component with any
|
|
|
|
// properties that will be used in it
|
|
|
|
credentials: {
|
|
|
|
confirmPassword: '',
|
|
|
|
password: '',
|
|
|
|
},
|
|
|
|
newPasswordAPI: {
|
|
|
|
message: '',
|
|
|
|
showLoading: false,
|
|
|
|
},
|
|
|
|
error: '',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
// If url opened without token
|
|
|
|
// redirect to login
|
|
|
|
if (!this.resetPasswordToken) {
|
2021-05-28 13:51:16 +00:00
|
|
|
window.location = DEFAULT_REDIRECT_URL;
|
2019-08-14 09:48:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
validations: {
|
|
|
|
credentials: {
|
|
|
|
password: {
|
|
|
|
required,
|
|
|
|
minLength: minLength(6),
|
|
|
|
},
|
|
|
|
confirmPassword: {
|
|
|
|
required,
|
|
|
|
minLength: minLength(6),
|
|
|
|
isEqPassword(value) {
|
|
|
|
if (value !== this.credentials.password) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
showAlert(message) {
|
|
|
|
// Reset loading, current selected agent
|
|
|
|
this.newPasswordAPI.showLoading = false;
|
|
|
|
bus.$emit('newToastMessage', message);
|
|
|
|
},
|
|
|
|
login() {
|
|
|
|
this.newPasswordAPI.showLoading = true;
|
|
|
|
const credentials = {
|
|
|
|
confirmPassword: this.credentials.confirmPassword,
|
|
|
|
password: this.credentials.password,
|
|
|
|
resetPasswordToken: this.resetPasswordToken,
|
|
|
|
};
|
|
|
|
Auth.setNewPassword(credentials)
|
2020-02-16 11:50:38 +00:00
|
|
|
.then(res => {
|
2019-08-14 09:48:44 +00:00
|
|
|
if (res.status === 200) {
|
2021-05-28 13:51:16 +00:00
|
|
|
window.location = DEFAULT_REDIRECT_URL;
|
2019-08-14 09:48:44 +00:00
|
|
|
}
|
|
|
|
})
|
2021-06-07 11:56:08 +00:00
|
|
|
.catch(error => {
|
|
|
|
let errorMessage = this.$t('SET_NEW_PASSWORD.API.ERROR_MESSAGE');
|
|
|
|
if (error?.data?.message) {
|
|
|
|
errorMessage = error.data.message;
|
|
|
|
}
|
|
|
|
this.showAlert(errorMessage);
|
2019-08-14 09:48:44 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|