2019-04-01 12:24:45 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
<template src="./register.html"></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 InfoComponent from '@/components/common/InfoComponent.vue';
|
|
|
|
import RegistrationSuccessPopup from '@/components/common/RegistrationSuccessPopup.vue';
|
|
|
|
|
|
|
|
import { AuthApi } from '@/api/auth';
|
|
|
|
import { RouteConfig } from '@/router';
|
|
|
|
import { User } from '@/types/users';
|
|
|
|
import { setUserId } from '@/utils/consoleLocalStorage';
|
|
|
|
import { APP_STATE_ACTIONS, NOTIFICATION_ACTIONS } from '@/utils/constants/actionNames';
|
|
|
|
import { LOADING_CLASSES } from '@/utils/constants/classConstants';
|
|
|
|
import { validateEmail, validatePassword } from '@/utils/validation';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
|
|
|
HeaderlessInput,
|
|
|
|
RegistrationSuccessPopup,
|
|
|
|
InfoComponent,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class Register extends Vue {
|
|
|
|
private readonly user = new User();
|
|
|
|
|
|
|
|
// tardigrade logic
|
|
|
|
private secret: string = '';
|
|
|
|
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;
|
|
|
|
|
|
|
|
private loadingClassName: string = LOADING_CLASSES.LOADING_OVERLAY;
|
|
|
|
|
|
|
|
private readonly auth: AuthApi = new AuthApi();
|
|
|
|
|
|
|
|
mounted(): void {
|
|
|
|
if (this.$route.query.token) {
|
|
|
|
this.secret = this.$route.query.token.toString();
|
2019-04-01 12:24:45 +01:00
|
|
|
}
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
const { ids = '' } = this.$route.params;
|
|
|
|
let decoded = '';
|
|
|
|
try {
|
|
|
|
decoded = atob(ids);
|
|
|
|
} catch (error) {
|
|
|
|
this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, 'Invalid Referral URL');
|
2019-07-18 14:39:39 +01:00
|
|
|
this.loadingClassName = LOADING_CLASSES.LOADING_OVERLAY;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public onCreateClick(): void {
|
|
|
|
if (!this.validateFields()) {
|
|
|
|
return;
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
this.loadingClassName = LOADING_CLASSES.LOADING_OVERLAY_ACTIVE;
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
this.createUser();
|
2019-07-18 14:39:39 +01:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
this.loadingClassName = LOADING_CLASSES.LOADING_OVERLAY;
|
|
|
|
}
|
|
|
|
public onLogoClick(): void {
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
public onLoginClick(): void {
|
|
|
|
this.$router.push(RouteConfig.Login.path);
|
|
|
|
}
|
|
|
|
public setEmail(value: string): void {
|
|
|
|
this.user.email = value.trim();
|
|
|
|
this.emailError = '';
|
|
|
|
}
|
|
|
|
public setFullName(value: string): void {
|
|
|
|
this.user.fullName = value.trim();
|
|
|
|
this.fullNameError = '';
|
|
|
|
}
|
|
|
|
public setShortName(value: string): void {
|
|
|
|
this.user.shortName = value.trim();
|
|
|
|
}
|
|
|
|
public setPassword(value: string): void {
|
|
|
|
this.password = value;
|
|
|
|
this.passwordError = '';
|
|
|
|
}
|
|
|
|
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 {
|
|
|
|
this.userId = await this.auth.create(this.user, this.password , this.secret, this.refUserId);
|
|
|
|
|
|
|
|
setUserId(this.userId);
|
|
|
|
|
|
|
|
// TODO: improve it
|
|
|
|
this.$store.dispatch(APP_STATE_ACTIONS.TOGGLE_SUCCESSFUL_REGISTRATION_POPUP);
|
|
|
|
if (this.$refs['register_success_popup'] !== null) {
|
|
|
|
(this.$refs['register_success_popup'] as any).startResendEmailCountdown();
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
2019-09-09 11:33:39 +01:00
|
|
|
} catch (error) {
|
|
|
|
this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
|
|
|
this.loadingClassName = LOADING_CLASSES.LOADING_OVERLAY;
|
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>
|
|
|
|
|
|
|
|
<style src="./register.scss" scoped lang="scss"></style>
|