2019-04-01 12:24:45 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-09-26 14:36:12 +01:00
|
|
|
<template src="./registerArea.html"></template>
|
2019-04-01 12:24:45 +01:00
|
|
|
|
|
|
|
<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';
|
2020-03-17 11:44:47 +00:00
|
|
|
import RegistrationSuccess from '@/components/common/RegistrationSuccess.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-10-23 13:26:39 +01:00
|
|
|
import AuthIcon from '@/../static/images/AuthImage.svg';
|
|
|
|
import InfoIcon from '@/../static/images/info.svg';
|
|
|
|
import LogoIcon from '@/../static/images/Logo.svg';
|
|
|
|
|
2019-10-29 14:24:16 +00:00
|
|
|
import { AuthHttpApi } from '@/api/auth';
|
2019-09-09 11:33:39 +01:00
|
|
|
import { RouteConfig } from '@/router';
|
2020-06-11 18:57:32 +01:00
|
|
|
import { GoogleTagManager } from '@/types/gtm';
|
2019-09-09 11:33:39 +01:00
|
|
|
import { User } from '@/types/users';
|
2019-10-28 17:33:06 +00:00
|
|
|
import { APP_STATE_ACTIONS } from '@/utils/constants/actionNames';
|
2019-11-12 12:14:05 +00:00
|
|
|
import { LocalData } from '@/utils/localData';
|
2020-04-15 12:36:21 +01:00
|
|
|
import { MetaUtils } from '@/utils/meta';
|
2020-06-02 15:08:20 +01:00
|
|
|
import { Validator } from '@/utils/validation';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
|
|
|
HeaderlessInput,
|
2020-03-17 11:44:47 +00:00
|
|
|
RegistrationSuccess,
|
2019-10-23 13:26:39 +01:00
|
|
|
AuthIcon,
|
|
|
|
LogoIcon,
|
|
|
|
InfoIcon,
|
2019-11-29 12:52:21 +00:00
|
|
|
PasswordStrength,
|
2019-09-09 11:33:39 +01:00
|
|
|
},
|
|
|
|
})
|
2019-09-26 14:36:12 +01:00
|
|
|
export default class RegisterArea extends Vue {
|
2019-09-09 11:33:39 +01:00
|
|
|
private readonly user = new User();
|
|
|
|
|
|
|
|
// tardigrade logic
|
|
|
|
private secret: string = '';
|
2020-06-11 18:57:32 +01:00
|
|
|
private gtm: GoogleTagManager;
|
|
|
|
private satellitesString: string;
|
|
|
|
private partneredSatellites: string[];
|
|
|
|
private satelliteName: string;
|
2019-09-09 11:33:39 +01:00
|
|
|
|
|
|
|
private userId: string = '';
|
|
|
|
private isTermsAccepted: boolean = false;
|
|
|
|
private password: string = '';
|
|
|
|
private repeatedPassword: string = '';
|
|
|
|
|
2021-02-19 15:39:53 +00:00
|
|
|
// Only for beta sats (like US2).
|
|
|
|
private areBetaTermsAccepted: boolean = false;
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
private fullNameError: string = '';
|
|
|
|
private emailError: string = '';
|
|
|
|
private passwordError: string = '';
|
|
|
|
private repeatedPasswordError: string = '';
|
|
|
|
private isTermsAcceptedError: boolean = false;
|
2019-10-11 11:42:38 +01:00
|
|
|
private isLoading: boolean = false;
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2021-02-19 15:39:53 +00:00
|
|
|
// Only for beta sats (like US2).
|
|
|
|
private areBetaTermsAcceptedError: boolean = false;
|
|
|
|
|
2019-10-29 14:24:16 +00:00
|
|
|
private readonly auth: AuthHttpApi = new AuthHttpApi();
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-11-29 12:52:21 +00:00
|
|
|
public isPasswordStrengthShown: boolean = false;
|
|
|
|
|
2020-05-29 16:36:59 +01:00
|
|
|
// tardigrade logic
|
|
|
|
public isDropdownShown: boolean = false;
|
|
|
|
|
2020-06-11 18:57:32 +01:00
|
|
|
/**
|
|
|
|
* Lifecycle hook before vue instance is created.
|
|
|
|
* Initializes google tag manager (Tardigrade).
|
|
|
|
*/
|
|
|
|
public async beforeCreate(): Promise<void> {
|
|
|
|
this.satellitesString = MetaUtils.getMetaContent('partnered-satellite-names');
|
|
|
|
this.partneredSatellites = this.satellitesString.split(',');
|
|
|
|
this.satelliteName = MetaUtils.getMetaContent('satellite-name');
|
|
|
|
|
|
|
|
if (this.partneredSatellites.includes(this.satelliteName)) {
|
|
|
|
this.gtm = new GoogleTagManager();
|
|
|
|
await this.gtm.init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lifecycle hook on component destroy.
|
|
|
|
* Sets view to default state and removed GTM.
|
|
|
|
*/
|
|
|
|
public beforeDestroy(): void {
|
|
|
|
if (this.partneredSatellites.includes(this.satelliteName)) {
|
|
|
|
this.gtm.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isRegistrationSuccessful) {
|
|
|
|
this.$store.dispatch(APP_STATE_ACTIONS.TOGGLE_SUCCESSFUL_REGISTRATION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-14 15:35:10 +00:00
|
|
|
/**
|
|
|
|
* Lifecycle hook after initial render.
|
|
|
|
* Sets up variables from route params.
|
|
|
|
*/
|
2021-02-05 21:03:10 +00:00
|
|
|
public mounted(): void {
|
2019-09-09 11:33:39 +01:00
|
|
|
if (this.$route.query.token) {
|
|
|
|
this.secret = this.$route.query.token.toString();
|
2019-04-01 12:24:45 +01:00
|
|
|
}
|
|
|
|
|
2020-07-28 15:23:17 +01:00
|
|
|
if (this.$route.query.partner) {
|
|
|
|
this.user.partner = this.$route.query.partner.toString();
|
|
|
|
}
|
2019-09-09 11:33:39 +01:00
|
|
|
}
|
|
|
|
|
2020-02-17 13:04:08 +00:00
|
|
|
/**
|
2020-03-17 11:44:47 +00:00
|
|
|
* Indicates if registration successful area shown.
|
|
|
|
*/
|
|
|
|
public get isRegistrationSuccessful(): boolean {
|
|
|
|
return this.$store.state.appStateModule.appState.isSuccessfulRegistrationShown;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-29 16:36:59 +01:00
|
|
|
* Toggles satellite selection dropdown visibility (Tardigrade).
|
2020-02-17 13:04:08 +00:00
|
|
|
*/
|
2020-05-29 16:36:59 +01:00
|
|
|
public toggleDropdown(): void {
|
|
|
|
this.isDropdownShown = !this.isDropdownShown;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes satellite selection dropdown (Tardigrade).
|
|
|
|
*/
|
|
|
|
public closeDropdown(): void {
|
|
|
|
this.isDropdownShown = false;
|
2020-02-17 13:04:08 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 11:44:47 +00:00
|
|
|
/**
|
|
|
|
* Makes password strength container visible.
|
|
|
|
*/
|
2019-11-29 12:52:21 +00:00
|
|
|
public showPasswordStrength(): void {
|
|
|
|
this.isPasswordStrengthShown = true;
|
|
|
|
}
|
|
|
|
|
2020-03-17 11:44:47 +00:00
|
|
|
/**
|
|
|
|
* Hides password strength container.
|
|
|
|
*/
|
2019-11-29 12:52:21 +00:00
|
|
|
public hidePasswordStrength(): void {
|
|
|
|
this.isPasswordStrengthShown = false;
|
|
|
|
}
|
|
|
|
|
2020-02-14 15:35:10 +00:00
|
|
|
/**
|
2020-03-17 11:44:47 +00:00
|
|
|
* Validates input fields and proceeds user creation.
|
2020-02-14 15:35:10 +00:00
|
|
|
*/
|
2019-10-11 11:42:38 +01:00
|
|
|
public async onCreateClick(): Promise<void> {
|
|
|
|
if (this.isLoading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isLoading = true;
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
if (!this.validateFields()) {
|
2019-10-11 11:42:38 +01:00
|
|
|
this.isLoading = false;
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
return;
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
|
|
|
|
2019-10-11 11:42:38 +01:00
|
|
|
await this.createUser();
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2019-10-11 11:42:38 +01:00
|
|
|
this.isLoading = false;
|
2019-09-09 11:33:39 +01:00
|
|
|
}
|
2020-02-14 15:35:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reloads page.
|
|
|
|
*/
|
2019-09-09 11:33:39 +01:00
|
|
|
public onLogoClick(): void {
|
|
|
|
location.reload();
|
|
|
|
}
|
2020-02-14 15:35:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes location to login route.
|
|
|
|
*/
|
2019-09-09 11:33:39 +01:00
|
|
|
public onLoginClick(): void {
|
|
|
|
this.$router.push(RouteConfig.Login.path);
|
|
|
|
}
|
2020-02-14 15:35:10 +00:00
|
|
|
|
2020-03-17 11:44:47 +00:00
|
|
|
/**
|
|
|
|
* Sets user's email field from value string.
|
|
|
|
*/
|
2019-09-09 11:33:39 +01:00
|
|
|
public setEmail(value: string): void {
|
|
|
|
this.user.email = value.trim();
|
|
|
|
this.emailError = '';
|
|
|
|
}
|
2020-02-14 15:35:10 +00:00
|
|
|
|
2020-03-17 11:44:47 +00:00
|
|
|
/**
|
|
|
|
* Sets user's full name field from value string.
|
|
|
|
*/
|
2019-09-09 11:33:39 +01:00
|
|
|
public setFullName(value: string): void {
|
|
|
|
this.user.fullName = value.trim();
|
|
|
|
this.fullNameError = '';
|
|
|
|
}
|
2020-02-14 15:35:10 +00:00
|
|
|
|
2020-03-17 11:44:47 +00:00
|
|
|
/**
|
|
|
|
* Sets user's password field from value string.
|
|
|
|
*/
|
2019-09-09 11:33:39 +01:00
|
|
|
public setPassword(value: string): void {
|
2019-10-29 14:24:16 +00:00
|
|
|
this.user.password = value.trim();
|
2019-09-09 11:33:39 +01:00
|
|
|
this.password = value;
|
|
|
|
this.passwordError = '';
|
|
|
|
}
|
2020-02-14 15:35:10 +00:00
|
|
|
|
2020-03-17 11:44:47 +00:00
|
|
|
/**
|
|
|
|
* Sets user's repeat password field from value string.
|
|
|
|
*/
|
2019-09-09 11:33:39 +01:00
|
|
|
public setRepeatedPassword(value: string): void {
|
|
|
|
this.repeatedPassword = value;
|
|
|
|
this.repeatedPasswordError = '';
|
|
|
|
}
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2021-02-19 15:39:53 +00:00
|
|
|
/**
|
|
|
|
* Only for US2 tardigrade beta satellite.
|
|
|
|
* Sets user's repeat password field from value string.
|
|
|
|
*/
|
|
|
|
public get isBetaSatellite(): boolean {
|
|
|
|
const US2_SAT_NAME_PART = 'US2';
|
|
|
|
const satName: string = this.$store.state.appStateModule.satelliteName;
|
|
|
|
|
|
|
|
return satName.includes(US2_SAT_NAME_PART);
|
|
|
|
}
|
|
|
|
|
2020-03-17 11:44:47 +00:00
|
|
|
/**
|
|
|
|
* Validates input values to satisfy expected rules.
|
|
|
|
*/
|
2019-09-09 11:33:39 +01:00
|
|
|
private validateFields(): boolean {
|
|
|
|
let isNoErrors = true;
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
if (!this.user.fullName.trim()) {
|
|
|
|
this.fullNameError = 'Invalid Name';
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2020-06-02 15:08:20 +01:00
|
|
|
if (!Validator.email(this.user.email.trim())) {
|
2019-09-09 11:33:39 +01:00
|
|
|
this.emailError = 'Invalid Email';
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2020-06-02 15:08:20 +01:00
|
|
|
if (!Validator.password(this.password)) {
|
2019-09-09 11:33:39 +01:00
|
|
|
this.passwordError = 'Invalid Password';
|
|
|
|
isNoErrors = false;
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
2019-08-14 19:11:18 +01:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
if (this.repeatedPassword !== this.password) {
|
|
|
|
this.repeatedPasswordError = 'Password doesn\'t match';
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
if (!this.isTermsAccepted) {
|
|
|
|
this.isTermsAcceptedError = true;
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
2019-08-14 19:11:18 +01:00
|
|
|
|
2021-02-19 15:39:53 +00:00
|
|
|
// only for beta US2 sats.
|
|
|
|
if (this.isBetaSatellite && !this.areBetaTermsAccepted) {
|
|
|
|
this.areBetaTermsAcceptedError = true;
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
return isNoErrors;
|
|
|
|
}
|
|
|
|
|
2020-03-17 11:44:47 +00:00
|
|
|
/**
|
|
|
|
* Creates user and toggles successful registration area visibility.
|
|
|
|
*/
|
2019-09-09 11:33:39 +01:00
|
|
|
private async createUser(): Promise<void> {
|
|
|
|
try {
|
2021-02-05 21:03:10 +00:00
|
|
|
this.userId = await this.auth.register(this.user, this.secret);
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-11-12 12:14:05 +00:00
|
|
|
LocalData.setUserId(this.userId);
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-12-11 20:07:15 +00:00
|
|
|
this.$segment.identify(this.userId, {
|
|
|
|
email: this.$store.getters.user.email,
|
|
|
|
});
|
|
|
|
|
2021-02-08 13:06:44 +00:00
|
|
|
const verificationPageURL: string = MetaUtils.getMetaContent('verification-page-url');
|
|
|
|
if (verificationPageURL) {
|
|
|
|
const externalAddress: string = MetaUtils.getMetaContent('external-address');
|
2020-04-15 12:36:21 +01:00
|
|
|
const url = new URL(verificationPageURL);
|
|
|
|
|
2021-02-08 13:06:44 +00:00
|
|
|
url.searchParams.append('redirect', externalAddress);
|
2020-04-15 12:36:21 +01:00
|
|
|
|
|
|
|
window.top.location.href = url.href;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-17 11:44:47 +00:00
|
|
|
await this.$store.dispatch(APP_STATE_ACTIONS.TOGGLE_SUCCESSFUL_REGISTRATION);
|
2019-09-09 11:33:39 +01:00
|
|
|
} catch (error) {
|
2019-10-28 17:33:06 +00:00
|
|
|
await this.$notify.error(error.message);
|
2019-10-11 11:42:38 +01:00
|
|
|
this.isLoading = false;
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
|
|
|
}
|
2019-09-09 11:33:39 +01:00
|
|
|
}
|
2019-04-01 12:24:45 +01:00
|
|
|
</script>
|
|
|
|
|
2019-09-26 14:36:12 +01:00
|
|
|
<style src="./registerArea.scss" scoped lang="scss"></style>
|