2019-04-25 16:06:19 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
<template>
|
2019-07-09 16:04:51 +01:00
|
|
|
<div class="change-password-popup-container">
|
|
|
|
<div class="change-password-popup">
|
|
|
|
<div class="change-password-popup__form-container">
|
|
|
|
<div class="change-password-row-container">
|
2019-10-23 13:26:39 +01:00
|
|
|
<ChangePasswordIcon class="change-password-popup__form-container__svg"/>
|
2019-07-09 16:04:51 +01:00
|
|
|
<h2 class="change-password-popup__form-container__main-label-text">Change Password</h2>
|
|
|
|
</div>
|
|
|
|
<HeaderlessInput
|
|
|
|
class="full-input"
|
|
|
|
label="Old Password"
|
|
|
|
placeholder ="Enter Old Password"
|
|
|
|
width="100%"
|
2019-09-23 12:31:42 +01:00
|
|
|
is-password="true"
|
2019-07-09 16:04:51 +01:00
|
|
|
ref="oldPasswordInput"
|
|
|
|
:error="oldPasswordError"
|
2019-10-02 10:42:12 +01:00
|
|
|
@setData="setOldPassword"
|
|
|
|
/>
|
2019-12-26 13:46:33 +00:00
|
|
|
<div class="password-input">
|
|
|
|
<HeaderlessInput
|
|
|
|
class="full-input"
|
|
|
|
label="New Password"
|
|
|
|
placeholder ="Enter New Password"
|
|
|
|
width="100%"
|
|
|
|
ref="newPasswordInput"
|
|
|
|
is-password="true"
|
|
|
|
:error="newPasswordError"
|
|
|
|
@setData="setNewPassword"
|
|
|
|
@showPasswordStrength="showPasswordStrength"
|
|
|
|
@hidePasswordStrength="hidePasswordStrength"
|
|
|
|
/>
|
|
|
|
<PasswordStrength
|
|
|
|
:password-string="newPassword"
|
|
|
|
:is-shown="isPasswordStrengthShown"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-07-09 16:04:51 +01:00
|
|
|
<HeaderlessInput
|
2019-12-26 13:46:33 +00:00
|
|
|
class="full-input"
|
2019-10-11 11:08:13 +01:00
|
|
|
label="Confirm Password"
|
|
|
|
placeholder="Confirm Password"
|
2019-07-09 16:04:51 +01:00
|
|
|
width="100%"
|
|
|
|
ref="confirmPasswordInput"
|
2019-09-23 12:31:42 +01:00
|
|
|
is-password="true"
|
2019-07-09 16:04:51 +01:00
|
|
|
:error="confirmationPasswordError"
|
2019-10-02 10:42:12 +01:00
|
|
|
@setData="setPasswordConfirmation"
|
|
|
|
/>
|
2019-07-09 16:04:51 +01:00
|
|
|
<div class="change-password-popup__form-container__button-container">
|
2019-09-26 14:36:12 +01:00
|
|
|
<VButton
|
|
|
|
label="Cancel"
|
|
|
|
width="205px"
|
|
|
|
height="48px"
|
|
|
|
:on-press="onCloseClick"
|
2019-10-02 10:42:12 +01:00
|
|
|
is-white="true"
|
|
|
|
/>
|
2019-09-26 14:36:12 +01:00
|
|
|
<VButton
|
|
|
|
label="Update"
|
|
|
|
width="205px"
|
|
|
|
height="48px"
|
2019-10-02 10:42:12 +01:00
|
|
|
:on-press="onUpdateClick"
|
|
|
|
/>
|
2019-07-09 16:04:51 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="change-password-popup__close-cross-container" @click="onCloseClick">
|
2019-10-23 13:26:39 +01:00
|
|
|
<CloseCrossIcon/>
|
2019-07-09 16:04:51 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-04-25 16:06:19 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-09-09 11:33:39 +01:00
|
|
|
import { Component, Vue } from 'vue-property-decorator';
|
|
|
|
|
|
|
|
import HeaderlessInput from '@/components/common/HeaderlessInput.vue';
|
2019-12-26 13:46:33 +00:00
|
|
|
import PasswordStrength from '@/components/common/PasswordStrength.vue';
|
2019-09-26 14:36:12 +01:00
|
|
|
import VButton from '@/components/common/VButton.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-10-23 13:26:39 +01:00
|
|
|
import ChangePasswordIcon from '@/../static/images/account/changePasswordPopup/changePassword.svg';
|
|
|
|
import CloseCrossIcon from '@/../static/images/common/closeCross.svg';
|
|
|
|
|
2019-10-29 14:24:16 +00:00
|
|
|
import { AuthHttpApi } from '@/api/auth';
|
2019-12-26 13:46:33 +00:00
|
|
|
import { APP_STATE_ACTIONS } from '@/utils/constants/actionNames';
|
2020-06-02 15:08:20 +01:00
|
|
|
import { Validator } from '@/utils/validation';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
2019-10-23 13:26:39 +01:00
|
|
|
ChangePasswordIcon,
|
|
|
|
CloseCrossIcon,
|
2019-09-09 11:33:39 +01:00
|
|
|
HeaderlessInput,
|
2019-09-26 14:36:12 +01:00
|
|
|
VButton,
|
2019-12-26 13:46:33 +00:00
|
|
|
PasswordStrength,
|
2019-09-13 15:58:18 +01:00
|
|
|
},
|
2019-09-09 11:33:39 +01:00
|
|
|
})
|
|
|
|
export default class ChangePasswordPopup extends Vue {
|
|
|
|
private oldPassword: string = '';
|
|
|
|
private newPassword: string = '';
|
|
|
|
private confirmationPassword: string = '';
|
2020-02-14 15:35:10 +00:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
private oldPasswordError: string = '';
|
|
|
|
private newPasswordError: string = '';
|
|
|
|
private confirmationPasswordError: string = '';
|
|
|
|
|
2019-10-29 14:24:16 +00:00
|
|
|
private readonly auth: AuthHttpApi = new AuthHttpApi();
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2020-02-14 15:35:10 +00:00
|
|
|
/**
|
|
|
|
* Indicates if hint popup needs to be shown while creating new password.
|
|
|
|
*/
|
2019-12-26 13:46:33 +00:00
|
|
|
public isPasswordStrengthShown: boolean = false;
|
|
|
|
|
|
|
|
public showPasswordStrength(): void {
|
|
|
|
this.isPasswordStrengthShown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public hidePasswordStrength(): void {
|
|
|
|
this.isPasswordStrengthShown = false;
|
|
|
|
}
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
public setOldPassword(value: string): void {
|
|
|
|
this.oldPassword = value;
|
|
|
|
this.oldPasswordError = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public setNewPassword(value: string): void {
|
|
|
|
this.newPassword = value;
|
|
|
|
this.newPasswordError = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public setPasswordConfirmation(value: string): void {
|
|
|
|
this.confirmationPassword = value;
|
|
|
|
this.confirmationPasswordError = '';
|
|
|
|
}
|
|
|
|
|
2020-02-14 15:35:10 +00:00
|
|
|
/**
|
|
|
|
* Validates inputs and if everything are correct tries to change password and close popup.
|
|
|
|
*/
|
2019-09-09 11:33:39 +01:00
|
|
|
public async onUpdateClick(): Promise<void> {
|
|
|
|
let hasError = false;
|
2019-10-17 11:34:45 +01:00
|
|
|
if (this.oldPassword.length < 6) {
|
|
|
|
this.oldPasswordError = 'Invalid old password. Must be 6 or more characters';
|
2019-09-09 11:33:39 +01:00
|
|
|
hasError = true;
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2020-06-02 15:08:20 +01:00
|
|
|
if (!Validator.password(this.newPassword)) {
|
2019-09-09 11:33:39 +01:00
|
|
|
this.newPasswordError = 'Invalid password. Use 6 or more characters';
|
|
|
|
hasError = true;
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
2019-07-08 14:45:25 +01:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
if (!this.confirmationPassword) {
|
|
|
|
this.confirmationPasswordError = 'Password required';
|
|
|
|
hasError = true;
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
2019-07-08 14:45:25 +01:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
if (this.newPassword !== this.confirmationPassword) {
|
|
|
|
this.confirmationPasswordError = 'Password not match to new one';
|
|
|
|
hasError = true;
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
2019-07-08 14:45:25 +01:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
if (hasError) {
|
|
|
|
return;
|
2019-04-25 16:06:19 +01:00
|
|
|
}
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
try {
|
|
|
|
await this.auth.changePassword(this.oldPassword, this.newPassword);
|
|
|
|
} catch (error) {
|
2019-10-28 17:33:06 +00:00
|
|
|
await this.$notify.error(error.message);
|
2019-09-09 11:33:39 +01:00
|
|
|
|
|
|
|
return;
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-10-28 17:33:06 +00:00
|
|
|
await this.$notify.success('Password successfully changed!');
|
2019-09-09 11:33:39 +01:00
|
|
|
this.$store.dispatch(APP_STATE_ACTIONS.TOGGLE_CHANGE_PASSWORD_POPUP);
|
|
|
|
}
|
|
|
|
|
2020-02-14 15:35:10 +00:00
|
|
|
/**
|
|
|
|
* Closes popup.
|
|
|
|
*/
|
2019-09-09 11:33:39 +01:00
|
|
|
public onCloseClick(): void {
|
|
|
|
this.$store.dispatch(APP_STATE_ACTIONS.TOGGLE_CHANGE_PASSWORD_POPUP);
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
2019-09-09 11:33:39 +01:00
|
|
|
}
|
2019-04-25 16:06:19 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
2019-07-10 10:55:40 +01:00
|
|
|
.change-password-popup-container {
|
|
|
|
position: fixed;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
bottom: 0;
|
|
|
|
background-color: rgba(134, 134, 148, 0.4);
|
|
|
|
z-index: 1000;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2019-10-28 15:59:19 +00:00
|
|
|
font-family: 'font_regular', sans-serif;
|
2019-07-10 10:55:40 +01:00
|
|
|
}
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
.input-container.full-input {
|
|
|
|
width: 100%;
|
|
|
|
}
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
.change-password-row-container {
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-content: center;
|
|
|
|
justify-content: flex-start;
|
|
|
|
margin-bottom: 20px;
|
|
|
|
}
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
.change-password-popup {
|
|
|
|
width: 100%;
|
|
|
|
max-width: 440px;
|
|
|
|
max-height: 470px;
|
2019-10-28 15:59:19 +00:00
|
|
|
background-color: #fff;
|
2019-07-10 10:55:40 +01:00
|
|
|
border-radius: 6px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: flex-start;
|
|
|
|
position: relative;
|
|
|
|
justify-content: center;
|
|
|
|
padding: 80px;
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
&__info-panel-container {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: center;
|
|
|
|
margin-right: 100px;
|
|
|
|
margin-top: 20px;
|
|
|
|
}
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
&__form-container {
|
|
|
|
width: 100%;
|
|
|
|
max-width: 440px;
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
&__main-label-text {
|
2019-10-28 15:59:19 +00:00
|
|
|
font-family: 'font_bold', sans-serif;
|
2019-07-10 10:55:40 +01:00
|
|
|
font-size: 32px;
|
|
|
|
line-height: 60px;
|
2019-10-28 15:59:19 +00:00
|
|
|
color: #384b65;
|
2019-07-10 10:55:40 +01:00
|
|
|
margin-bottom: 0;
|
|
|
|
margin-top: 0;
|
|
|
|
margin-left: 32px;
|
|
|
|
}
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
&__button-container {
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
margin-top: 32px;
|
|
|
|
}
|
|
|
|
}
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
&__close-cross-container {
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
position: absolute;
|
|
|
|
right: 30px;
|
|
|
|
top: 40px;
|
|
|
|
height: 24px;
|
|
|
|
width: 24px;
|
|
|
|
cursor: pointer;
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-09-26 14:36:12 +01:00
|
|
|
&:hover .close-cross-svg-path {
|
2019-10-28 15:59:19 +00:00
|
|
|
fill: #2683ff;
|
2019-07-10 10:55:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-25 16:06:19 +01:00
|
|
|
|
2019-12-26 13:46:33 +00:00
|
|
|
.password-input {
|
|
|
|
position: relative;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
@media screen and (max-width: 720px) {
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
.change-password-popup {
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
&__info-panel-container {
|
|
|
|
display: none;
|
|
|
|
}
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
&__form-container {
|
2019-10-28 15:59:19 +00:00
|
|
|
|
2019-07-10 10:55:40 +01:00
|
|
|
&__button-container {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-25 16:06:19 +01:00
|
|
|
</style>
|