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';
|
2019-09-09 11:33:39 +01:00
|
|
|
import RegistrationSuccessPopup from '@/components/common/RegistrationSuccessPopup.vue';
|
|
|
|
|
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';
|
|
|
|
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';
|
2019-09-09 11:33:39 +01:00
|
|
|
import { validateEmail, validatePassword } from '@/utils/validation';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
|
|
|
HeaderlessInput,
|
|
|
|
RegistrationSuccessPopup,
|
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 = '';
|
2019-12-02 19:27:56 +00:00
|
|
|
private referralToken: string = '';
|
2019-09-09 11:33:39 +01:00
|
|
|
private refUserId: string = '';
|
|
|
|
|
|
|
|
private userId: string = '';
|
|
|
|
private isTermsAccepted: boolean = false;
|
|
|
|
private password: string = '';
|
|
|
|
private repeatedPassword: string = '';
|
|
|
|
|
|
|
|
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
|
|
|
|
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-02-14 15:35:10 +00:00
|
|
|
/**
|
|
|
|
* Lifecycle hook after initial render.
|
|
|
|
* Sets up variables from route params.
|
|
|
|
*/
|
2019-10-28 17:33:06 +00:00
|
|
|
async mounted(): Promise<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
|
|
|
}
|
|
|
|
|
2019-12-02 19:27:56 +00:00
|
|
|
if (this.$route.query.referralToken) {
|
|
|
|
this.referralToken = this.$route.query.referralToken.toString();
|
|
|
|
}
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
const { ids = '' } = this.$route.params;
|
|
|
|
let decoded = '';
|
|
|
|
try {
|
|
|
|
decoded = atob(ids);
|
|
|
|
} catch (error) {
|
2019-10-28 17:33:06 +00:00
|
|
|
await this.$notify.error('Invalid Referral URL');
|
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
|
|
|
const referralIds = ids ? JSON.parse(decoded) : undefined;
|
|
|
|
if (referralIds) {
|
|
|
|
this.user.partnerId = referralIds.partnerId;
|
|
|
|
this.refUserId = referralIds.userId;
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
2019-09-09 11:33:39 +01:00
|
|
|
}
|
|
|
|
|
2020-02-17 13:04:08 +00:00
|
|
|
/**
|
|
|
|
* Checks if page is inside iframe
|
|
|
|
*/
|
|
|
|
public get isInsideIframe(): boolean {
|
|
|
|
return window.self !== window.top;
|
|
|
|
}
|
|
|
|
|
2019-11-29 12:52:21 +00:00
|
|
|
public showPasswordStrength(): void {
|
|
|
|
this.isPasswordStrengthShown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public hidePasswordStrength(): void {
|
|
|
|
this.isPasswordStrengthShown = false;
|
|
|
|
}
|
|
|
|
|
2020-02-14 15:35:10 +00:00
|
|
|
/**
|
|
|
|
* Register user.
|
|
|
|
*/
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
if (!validateEmail(this.user.email.trim())) {
|
|
|
|
this.emailError = 'Invalid Email';
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
if (!validatePassword(this.password)) {
|
|
|
|
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
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
return isNoErrors;
|
|
|
|
}
|
|
|
|
|
|
|
|
private async createUser(): Promise<void> {
|
|
|
|
try {
|
2019-12-02 19:27:56 +00:00
|
|
|
this.userId = this.referralToken ?
|
|
|
|
await this.auth.referralRegister(this.user, this.referralToken) :
|
|
|
|
await this.auth.register(this.user, this.secret, this.refUserId);
|
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,
|
|
|
|
referralToken: this.referralToken,
|
|
|
|
});
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
// TODO: improve it
|
2020-02-25 12:22:18 +00:00
|
|
|
await this.$store.dispatch(APP_STATE_ACTIONS.TOGGLE_SUCCESSFUL_REGISTRATION_POPUP);
|
2019-10-04 12:55:18 +01:00
|
|
|
const registrationSuccessPopupRef = this.$refs['register_success_popup'];
|
|
|
|
|
|
|
|
if (registrationSuccessPopupRef) {
|
|
|
|
(registrationSuccessPopupRef as any).startResendEmailCountdown();
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
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>
|