storj/web/satellite/src/components/account/ChangePasswordPopup.vue

263 lines
7.7 KiB
Vue
Raw Normal View History

// 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">
<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%"
is-password="true"
2019-07-09 16:04:51 +01:00
ref="oldPasswordInput"
:error="oldPasswordError"
@setData="setOldPassword"
/>
2019-07-09 16:04:51 +01:00
<HeaderlessInput
class="full-input mt"
label="New Password"
placeholder ="Enter New Password"
width="100%"
ref="newPasswordInput"
is-password="true"
2019-07-09 16:04:51 +01:00
:error="newPasswordError"
@setData="setNewPassword"
/>
2019-07-09 16:04:51 +01:00
<HeaderlessInput
class="full-input mt"
label="Confirm Password"
placeholder="Confirm Password"
2019-07-09 16:04:51 +01:00
width="100%"
ref="confirmPasswordInput"
is-password="true"
2019-07-09 16:04:51 +01:00
:error="confirmationPasswordError"
@setData="setPasswordConfirmation"
/>
2019-07-09 16:04:51 +01:00
<div class="change-password-popup__form-container__button-container">
<VButton
label="Cancel"
width="205px"
height="48px"
:on-press="onCloseClick"
is-white="true"
/>
<VButton
label="Update"
width="205px"
height="48px"
:on-press="onUpdateClick"
/>
2019-07-09 16:04:51 +01:00
</div>
</div>
<div class="change-password-popup__close-cross-container" @click="onCloseClick">
<CloseCrossIcon/>
2019-07-09 16:04:51 +01:00
</div>
</div>
</div>
</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';
import VButton from '@/components/common/VButton.vue';
2019-09-09 11:33:39 +01:00
import ChangePasswordIcon from '@/../static/images/account/changePasswordPopup/changePassword.svg';
import CloseCrossIcon from '@/../static/images/common/closeCross.svg';
2019-09-09 11:33:39 +01:00
import { AuthApi } from '@/api/auth';
import { APP_STATE_ACTIONS } from '@/utils/constants/actionNames';
2019-09-09 11:33:39 +01:00
import { validatePassword } from '@/utils/validation';
@Component({
components: {
ChangePasswordIcon,
CloseCrossIcon,
2019-09-09 11:33:39 +01:00
HeaderlessInput,
VButton,
},
2019-09-09 11:33:39 +01:00
})
export default class ChangePasswordPopup extends Vue {
private oldPassword: string = '';
private newPassword: string = '';
private confirmationPassword: string = '';
private oldPasswordError: string = '';
private newPasswordError: string = '';
private confirmationPasswordError: string = '';
private readonly auth: AuthApi = new AuthApi();
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 = '';
}
public async onUpdateClick(): Promise<void> {
let hasError = false;
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-09-09 11:33:39 +01:00
if (!validatePassword(this.newPassword)) {
this.newPasswordError = 'Invalid password. Use 6 or more characters';
hasError = true;
}
2019-09-09 11:33:39 +01:00
if (!this.confirmationPassword) {
this.confirmationPasswordError = 'Password required';
hasError = true;
}
2019-09-09 11:33:39 +01:00
if (this.newPassword !== this.confirmationPassword) {
this.confirmationPasswordError = 'Password not match to new one';
hasError = true;
}
2019-09-09 11:33:39 +01:00
if (hasError) {
return;
}
2019-09-09 11:33:39 +01:00
try {
await this.auth.changePassword(this.oldPassword, this.newPassword);
} catch (error) {
await this.$notify.error(error.message);
2019-09-09 11:33:39 +01:00
return;
}
2019-09-09 11:33:39 +01: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);
}
public onCloseClick(): void {
this.$store.dispatch(APP_STATE_ACTIONS.TOGGLE_CHANGE_PASSWORD_POPUP);
}
2019-09-09 11:33:39 +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;
font-family: 'font_regular', sans-serif;
2019-07-10 10:55:40 +01:00
}
2019-07-10 10:55:40 +01:00
.input-container.full-input {
width: 100%;
}
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-07-10 10:55:40 +01:00
.change-password-popup {
width: 100%;
max-width: 440px;
max-height: 470px;
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-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-07-10 10:55:40 +01:00
&__form-container {
width: 100%;
max-width: 440px;
2019-07-10 10:55:40 +01:00
&__main-label-text {
font-family: 'font_bold', sans-serif;
2019-07-10 10:55:40 +01:00
font-size: 32px;
line-height: 60px;
color: #384b65;
2019-07-10 10:55:40 +01:00
margin-bottom: 0;
margin-top: 0;
margin-left: 32px;
}
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-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;
&:hover .close-cross-svg-path {
fill: #2683ff;
2019-07-10 10:55:40 +01:00
}
}
}
2019-07-10 10:55:40 +01:00
@media screen and (max-width: 720px) {
2019-07-10 10:55:40 +01:00
.change-password-popup {
2019-07-10 10:55:40 +01:00
&__info-panel-container {
display: none;
}
2019-07-10 10:55:40 +01:00
&__form-container {
2019-07-10 10:55:40 +01:00
&__button-container {
width: 100%;
}
}
}
}
</style>