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">
|
|
|
|
import { Component, Vue } from 'vue-property-decorator';
|
|
|
|
import HeaderlessInput from '../../components/common/HeaderlessInput.vue';
|
|
|
|
import { EMPTY_STATE_IMAGES } from '../../utils/constants/emptyStatesImages';
|
|
|
|
import RegistrationSuccessPopup from '../../components/common/RegistrationSuccessPopup.vue';
|
|
|
|
import { validateEmail, validatePassword } from '../../utils/validation';
|
|
|
|
import ROUTES from '../../utils/constants/routerConstants';
|
2019-06-11 20:00:23 +01:00
|
|
|
import EVENTS from '../../utils/constants/analyticsEventNames';
|
2019-04-01 12:24:45 +01:00
|
|
|
import { LOADING_CLASSES } from '../../utils/constants/classConstants';
|
|
|
|
import { APP_STATE_ACTIONS, NOTIFICATION_ACTIONS } from '../../utils/constants/actionNames';
|
|
|
|
import { createUserRequest } from '../../api/users';
|
2019-05-15 09:28:36 +01:00
|
|
|
import { setUserId } from '@/utils/consoleLocalStorage';
|
2019-04-01 12:24:45 +01:00
|
|
|
|
|
|
|
@Component(
|
|
|
|
{
|
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
fullName: '',
|
|
|
|
fullNameError: '',
|
|
|
|
shortName: '',
|
|
|
|
email: '',
|
|
|
|
emailError: '',
|
|
|
|
password: '',
|
|
|
|
passwordError: '',
|
|
|
|
repeatedPassword: '',
|
|
|
|
repeatedPasswordError: '',
|
|
|
|
isTermsAccepted: false,
|
|
|
|
isTermsAcceptedError: false,
|
|
|
|
secret: '',
|
|
|
|
loadingClassName: LOADING_CLASSES.LOADING_OVERLAY,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
setEmail: function (value: string): void {
|
|
|
|
this.$data.email = value;
|
|
|
|
this.$data.emailError = '';
|
|
|
|
},
|
|
|
|
setFullName: function (value: string): void {
|
|
|
|
this.$data.fullName = value;
|
|
|
|
this.$data.fullNameError = '';
|
|
|
|
},
|
|
|
|
setShortName: function (value: string): void {
|
|
|
|
this.$data.shortName = value;
|
|
|
|
},
|
|
|
|
setPassword: function (value: string): void {
|
|
|
|
this.$data.password = value;
|
|
|
|
this.$data.passwordError = '';
|
|
|
|
},
|
|
|
|
setRepeatedPassword: function (value: string): void {
|
|
|
|
this.$data.repeatedPassword = value;
|
|
|
|
this.$data.repeatedPasswordError = '';
|
|
|
|
},
|
|
|
|
validateFields: function (): boolean {
|
|
|
|
let isNoErrors = true;
|
|
|
|
if (!this.$data.fullName.trim()) {
|
|
|
|
this.$data.fullNameError = 'Invalid Name';
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validateEmail(this.$data.email.trim())) {
|
|
|
|
this.$data.emailError = 'Invalid Email';
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validatePassword(this.$data.password)) {
|
|
|
|
this.$data.passwordError = 'Invalid Password';
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.$data.repeatedPassword !== this.$data.password) {
|
|
|
|
this.$data.repeatedPasswordError = 'Password doesn\'t match';
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.$data.isTermsAccepted) {
|
|
|
|
this.$data.isTermsAcceptedError = true;
|
|
|
|
isNoErrors = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isNoErrors;
|
|
|
|
},
|
|
|
|
createUser: async function(): Promise<any> {
|
|
|
|
let user = {
|
|
|
|
email: this.$data.email.trim(),
|
|
|
|
fullName: this.$data.fullName.trim(),
|
|
|
|
shortName: this.$data.shortName.trim(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let response = await createUserRequest(user, this.$data.password, this.$data.secret);
|
|
|
|
if (!response.isSuccess) {
|
|
|
|
this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, response.errorMessage);
|
|
|
|
this.$data.loadingClassName = LOADING_CLASSES.LOADING_OVERLAY;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-15 09:28:36 +01:00
|
|
|
if (response.data) {
|
|
|
|
setUserId(response.data);
|
|
|
|
}
|
|
|
|
|
2019-04-01 12:24:45 +01:00
|
|
|
this.$store.dispatch(APP_STATE_ACTIONS.TOGGLE_SUCCESSFUL_REGISTRATION_POPUP);
|
2019-05-15 09:28:36 +01:00
|
|
|
if (this.$refs['register_success_popup'] !== null) {
|
|
|
|
(this.$refs['register_success_popup'] as any).startResendEmailCountdown();
|
|
|
|
}
|
2019-04-01 12:24:45 +01:00
|
|
|
},
|
|
|
|
onCreateClick: function (): any {
|
|
|
|
let self = this as any;
|
|
|
|
|
2019-04-23 15:46:54 +01:00
|
|
|
if (!self.validateFields()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-01 12:24:45 +01:00
|
|
|
|
|
|
|
this.$data.loadingClassName = LOADING_CLASSES.LOADING_OVERLAY_ACTIVE;
|
|
|
|
|
|
|
|
self.createUser();
|
|
|
|
},
|
|
|
|
onLogoClick: function (): void {
|
2019-06-11 20:00:23 +01:00
|
|
|
this.$segment.track(EVENTS.CLICKED_LOGO);
|
2019-04-01 12:24:45 +01:00
|
|
|
location.reload();
|
|
|
|
},
|
|
|
|
onLoginClick: function (): void {
|
2019-06-11 20:00:23 +01:00
|
|
|
this.$segment.track(EVENTS.CLICKED_LOGIN);
|
2019-04-01 12:24:45 +01:00
|
|
|
this.$router.push(ROUTES.LOGIN.path);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
infoImage: function() {
|
|
|
|
|
|
|
|
return EMPTY_STATE_IMAGES.INFO;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
HeaderlessInput,
|
|
|
|
RegistrationSuccessPopup
|
|
|
|
},
|
|
|
|
mounted(): void {
|
|
|
|
if (this.$route.query.token) {
|
|
|
|
this.$data.secret = this.$route.query.token.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export default class Register extends Vue {
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style src="./register.scss" scoped lang="scss"></style>
|