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

298 lines
8.8 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"
/>
<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
class="full-input"
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-transparent="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 PasswordStrength from '@/components/common/PasswordStrength.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';
import { AuthHttpApi } from '@/api/auth';
import { APP_STATE_ACTIONS } from '@/utils/constants/actionNames';
import { Validator } from '@/utils/validation';
2019-09-09 11:33:39 +01:00
@Component({
components: {
ChangePasswordIcon,
CloseCrossIcon,
2019-09-09 11:33:39 +01:00
HeaderlessInput,
VButton,
PasswordStrength,
},
2019-09-09 11:33:39 +01:00
})
export default class ChangePasswordPopup extends Vue {
private oldPassword: string = '';
private newPassword: string = '';
private confirmationPassword: string = '';
2019-09-09 11:33:39 +01:00
private oldPasswordError: string = '';
private newPasswordError: string = '';
private confirmationPasswordError: string = '';
private readonly auth: AuthHttpApi = new AuthHttpApi();
2019-09-09 11:33:39 +01:00
/**
* Indicates if hint popup needs to be shown while creating new password.
*/
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 = '';
}
/**
* 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;
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 (!Validator.password(this.newPassword)) {
2019-09-09 11:33:39 +01:00
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);
}
/**
* Closes popup.
*/
2019-09-09 11:33:39 +01:00
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
}
}
}
.password-input {
position: relative;
width: 100%;
}
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>