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';
|
|
|
|
|
2021-02-24 22:35:24 +00:00
|
|
|
import AddCouponCodeInput from '@/components/common/AddCouponCodeInput.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
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';
|
2021-04-09 17:07:15 +01:00
|
|
|
import LogoIcon from '@/../static/images/dcs-logo.svg';
|
2021-04-14 21:28:48 +01:00
|
|
|
import InfoIcon from '@/../static/images/info.svg';
|
2019-10-23 13:26:39 +01:00
|
|
|
|
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';
|
|
|
|
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,
|
2021-02-24 22:35:24 +00:00
|
|
|
AddCouponCodeInput,
|
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 = '';
|
|
|
|
|
|
|
|
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;
|
2021-04-12 22:38:30 +01:00
|
|
|
private areBetaTermsAcceptedError: boolean = false;
|
2021-02-19 15:39:53 +00:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
private fullNameError: string = '';
|
|
|
|
private emailError: string = '';
|
|
|
|
private passwordError: string = '';
|
|
|
|
private repeatedPasswordError: string = '';
|
2021-02-08 14:38:01 +00:00
|
|
|
private companyNameError: string = '';
|
|
|
|
private employeeCountError: string = '';
|
|
|
|
private positionError: string = '';
|
2019-09-09 11:33:39 +01:00
|
|
|
private isTermsAcceptedError: boolean = false;
|
2019-10-11 11:42:38 +01:00
|
|
|
private isLoading: boolean = false;
|
2021-02-08 14:38:01 +00:00
|
|
|
private isProfessional: boolean = false;
|
2019-09-09 11:33:39 +01:00
|
|
|
|
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;
|
|
|
|
|
2021-02-08 14:38:01 +00:00
|
|
|
// Employee Count dropdown options
|
|
|
|
public employeeCountOptions = ['1-50', '51-1000', '1001+'];
|
|
|
|
public optionsShown = false;
|
|
|
|
|
2021-04-15 23:03:08 +01:00
|
|
|
public readonly loginPath: string = RouteConfig.Login.path;
|
|
|
|
|
2020-06-11 18:57:32 +01:00
|
|
|
/**
|
|
|
|
* Lifecycle hook on component destroy.
|
2021-04-12 22:38:30 +01:00
|
|
|
* Sets view to default state.
|
2020-06-11 18:57:32 +01:00
|
|
|
*/
|
|
|
|
public beforeDestroy(): void {
|
|
|
|
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
|
|
|
/**
|
2021-02-23 17:26:24 +00:00
|
|
|
* Indicates if satellite is in beta.
|
2021-02-19 15:39:53 +00:00
|
|
|
*/
|
|
|
|
public get isBetaSatellite(): boolean {
|
2021-02-23 17:26:24 +00:00
|
|
|
return this.$store.state.appStateModule.isBetaSatellite;
|
2021-02-19 15:39:53 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 22:35:24 +00:00
|
|
|
/**
|
|
|
|
* Indicates if coupon code ui is enabled
|
|
|
|
*/
|
|
|
|
public get couponCodeUIEnabled(): boolean {
|
|
|
|
return this.$store.state.appStateModule.couponCodeUIEnabled;
|
|
|
|
}
|
|
|
|
|
2021-02-08 14:38:01 +00:00
|
|
|
/**
|
|
|
|
* Sets user's company name field from value string.
|
|
|
|
*/
|
|
|
|
public setCompanyName(value: string): void {
|
|
|
|
this.user.companyName = value.trim();
|
|
|
|
this.companyNameError = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets user's company size field from value string.
|
|
|
|
*/
|
|
|
|
public setEmployeeCount(value: string): void {
|
|
|
|
this.user.employeeCount = value;
|
|
|
|
this.employeeCountError = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets user's position field from value string.
|
|
|
|
*/
|
|
|
|
public setPosition(value: string): void {
|
|
|
|
this.user.position = value.trim();
|
|
|
|
this.positionError = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* toggle user account type
|
|
|
|
*/
|
|
|
|
public toggleAccountType(value: boolean): void {
|
|
|
|
this.isProfessional = value;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-02-08 14:38:01 +00:00
|
|
|
if (this.isProfessional) {
|
|
|
|
|
|
|
|
if (!this.user.companyName.trim()) {
|
|
|
|
this.companyNameError = 'No Company Name filled in';
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.user.position.trim()) {
|
|
|
|
this.positionError = 'No Position filled in';
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.user.employeeCount.trim()) {
|
|
|
|
this.employeeCountError = 'No Company Size filled in';
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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> {
|
2021-02-08 14:38:01 +00:00
|
|
|
this.user.isProfessional = this.isProfessional;
|
2019-09-09 11:33:39 +01:00
|
|
|
try {
|
2021-02-05 21:03:10 +00:00
|
|
|
this.userId = await this.auth.register(this.user, this.secret);
|
2019-11-12 12:14:05 +00:00
|
|
|
LocalData.setUserId(this.userId);
|
2019-09-09 11:33:39 +01:00
|
|
|
|
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>
|