Skip to content
Snippets Groups Projects
SignUp.vue 22 KiB
Newer Older
moon's avatar
moon committed
<template>
  <div>
moon's avatar
moon committed
    <base-toaster
      :open="toasterIsOpen"
      @close="hideDialog"
    >
      <div class="flex justify-between space-x-4 items-center">
        <font-awesome-icon
          class="ml-3"
          icon="fa-solid fa-thumbs-up "
          size="lg"
        />

moon's avatar
moon committed
        <h4>
raghosh's avatar
raghosh committed
          Sign up request successful. An activation link has been sent to the
          email {{ email.val }}
raghosh's avatar
raghosh committed
          . Please click the link to activate your account.
moon's avatar
moon committed
        </h4>
moon's avatar
moon committed
        <button
          class="btn btn-outline"
          @click="hideDialog"
        >
          <font-awesome-icon
            icon="fa-regular fa-circle-xmark"
            size="2x"
          />
moon's avatar
moon committed
    <div class="flex items-center justify-center">
      <div class="sm:block border border-gray-300 rounded-lg w-2/5 mt-6 rounded-lg p-4">
        <div class="p-8 text-left">
raghosh's avatar
raghosh committed
          <h1
            class="
              font-bold
              text-left
              font-montserrat
              text-3xl
              sm:text-5xl
              mb-7
            "
          >
moon's avatar
moon committed
            Sign Up to join CD-Code
moon's avatar
moon committed
          </h1>
raghosh's avatar
raghosh committed
          <form @submit.prevent="register">
moon's avatar
moon committed
            <div
              class="my-4"
              :class="{ invalid: !name.isValid }"
            >
raghosh's avatar
raghosh committed
              <div class="flex justify-between">
                <h1
                  class="
                    text-left
                    font-bold
                    mb-2
                    text-xl
                    sm:text-2xl
                    font-montserrat
                  "
                >
                  Name*
                </h1>
                <h1
                  class="
                    text-left text-gray-400
                    mb-2
                    text-lg
                    sm:text-2xl
                    font-montserrat
                  "
                >
                  Note: * fields are mandatory.
                </h1>
raghosh's avatar
raghosh committed
              </div>
moon's avatar
moon committed
              <input
raghosh's avatar
raghosh committed
                v-model.trim="name.val"
moon's avatar
moon committed
                type="text"
raghosh's avatar
raghosh committed
                class="
                  text-xl
                  outline-none
                  px-4
                  py-5
                  w-full
                  bg-transparent
                  border
                  rounded-lg
                  border-gray-400
                  hover:border-blue-700
                  focus:border-blue-700
                "
                placeholder="Enter full name."
moon's avatar
moon committed
                @blur="clearValidity('name')"
              >
              <p
                v-if="!name.isValid"
                class="text-red-500"
              >
moon's avatar
moon committed
            </div>
moon's avatar
moon committed
            <div
              class="my-4"
              :class="{ invalid: !email.isValid }"
            >
raghosh's avatar
raghosh committed
              <h1
                class="
                  text-left
                  font-bold
                  mb-2
                  text-xl
                  sm:text-2xl
                  font-montserrat
                "
              >
                Email*
moon's avatar
moon committed
              </h1>
              <input
raghosh's avatar
raghosh committed
                v-model.trim="email.val"
moon's avatar
moon committed
                type="email"
raghosh's avatar
raghosh committed
                class="
                  text-xl
                  outline-none
                  w-full
                  bg-transparent
                  px-4
                  py-5
                  rounded-lg
raghosh's avatar
raghosh committed
                  hover:border-blue-700
                  focus:border-blue-700
                "
                placeholder="Enter email."
moon's avatar
moon committed
                @blur="clearValidity('email')"
              >
              <p
                v-if="!email.isValid"
                class="text-red-500"
              >
moon's avatar
moon committed
              <p
                v-if="error && errorMsg"
                class="text-red-500"
              >
moon's avatar
moon committed
            </div>
moon's avatar
moon committed
            <div
              class="my-4"
              :class="{ invalid: !password.isValid }"
            >
raghosh's avatar
raghosh committed
              <h1
                class="
                  text-left
                  font-bold
                  mb-2
                  text-xl
                  sm:text-2xl
                  font-montserrat
                "
              >
                Password*
moon's avatar
moon committed
              </h1>
              <input
raghosh's avatar
raghosh committed
                v-model.trim="password.val"
moon's avatar
moon committed
                type="password"
raghosh's avatar
raghosh committed
                class="
                  text-xl
                  outline-none
                  px-4
                  py-5
                  rounded-lg
raghosh's avatar
raghosh committed
                  w-full
                  bg-transparent
                  hover:border-blue-700
                  focus:border-blue-700
                "
                placeholder="Password must be minimum 6 character."
moon's avatar
moon committed
                @blur="clearValidity('password')"
              >
              <p
                v-if="!password.isValid"
                class="text-red-500"
              >
                Password must not be empty or less than 6 character.
              </p>
moon's avatar
moon committed
            </div>
moon's avatar
moon committed
            <div
              class="my-4"
              :class="{ invalid: !username.isValid }"
            >
raghosh's avatar
raghosh committed
              <h1
                class="
                  text-left
                  font-bold
                  mb-2
                  text-xl
                  sm:text-2xl
                  font-montserrat
                "
              >
                Username*
moon's avatar
moon committed
              </h1>
              <input
raghosh's avatar
raghosh committed
                v-model.trim="username.val"
moon's avatar
moon committed
                type="text"
raghosh's avatar
raghosh committed
                class="
                  text-xl
                  outline-none
                  px-4
                  py-5
                  rounded-lg
raghosh's avatar
raghosh committed
                  w-full
                  bg-transparent
                  border-b
                  hover:border-blue-700
                  focus:border-blue-700
                "
                placeholder="Username must be minimum 3 character."
moon's avatar
moon committed
                @blur="clearValidity('username')"
              >
              <p
                v-if="!username.isValid"
                class="text-red-500"
              >
moon's avatar
moon committed
            </div>
moon's avatar
moon committed
            <div
              class="my-4"
              :class="{ invalid: !current_role.isValid }"
            >
raghosh's avatar
raghosh committed
              <h1
                class="
                  text-left
                  font-bold
                  mb-2
                  text-xl
                  sm:text-2xl
                  font-montserrat
                "
              >
                Current Role*
moon's avatar
moon committed
              </h1>
moon's avatar
moon committed
              <select
                id="inline-current-role"
raghosh's avatar
raghosh committed
                v-model="current_role.val"
                class="
                  bg-white
                  px-4
                  py-5
                  rounded-lg
raghosh's avatar
raghosh committed
                  w-full
                  text-gray-700
                  outline-none
                  bg-transparent
                  border-b
                  hover:border-blue-700
                "
moon's avatar
moon committed
                @blur="clearValidity('current_role')"
moon's avatar
moon committed
              >
moon's avatar
moon committed
                <option
                  id="phd"
                  value="PhD"
                >
                  PhD
                </option>
                <option
                  id="postdoc"
                  value="PostDoc"
                >
                  PostDoc
                </option>
                <option
                  id="research_scientist"
                  value="Research_Scientist"
                >
moon's avatar
moon committed
                  Research Scientist
                </option>
                <option
                  id="principal_investigator"
                  value="Principal_Investigator"
                >
                  Principal Investigator
                </option>
moon's avatar
moon committed
              <p
                v-if="!current_role.isValid"
                class="text-red-500"
              >
            <div
              class="my-4"
              :class="{ invalid: !scientific_discipline.isValid }"
            >
              <h1
raghosh's avatar
raghosh committed
                class="
                  text-left
                  font-bold
                  mb-2
                  text-xl
                  sm:text-2xl
                  font-montserrat
                "
              >
                Scientific Disciplines*
              </h1>
              <div
                v-for="options in scientificDisciplineOptions"
                :key="options.id"
              >
                <input
                  :id="options.id"
                  v-model="scientific_discipline.val"
                  type="checkbox"
                  class="h-6 w-6"
                  :name="options"
                  :value="options.discipline"
                  @blur="clearValidity('scientific_discipline')"
moon's avatar
moon committed
                >
                <label
                  class="mx-3"
                  :for="options.id"
                >{{
moon's avatar
moon committed
              <p
                v-if="!scientific_discipline.isValid"
                class="text-red-500"
              >
                Please select atleast one scientific discipline.
              </p>
raghosh's avatar
raghosh committed
            </div>
moon's avatar
moon committed
            <div
              class="my-4"
              :class="{ invalid: !affiliation.isValid }"
            >
raghosh's avatar
raghosh committed
                class="
                  text-left
                  font-bold
                  mb-2
                  text-xl
                  sm:text-2xl
                  font-montserrat
                "
              >
                Affiliation*
              </h1>
              <input
                v-model.trim="affiliation.val"
                type="text"
                class="
                  text-xl
                  outline-none
                  px-4
                  py-5
                  rounded-lg
raghosh's avatar
raghosh committed
                  w-full
                  bg-transparent
                  hover:border-blue-700
                  focus:border-blue-700
                "
                placeholder="Institute name currently associated with."
moon's avatar
moon committed
                @blur="clearValidity('affiliation')"
              >
              <p
                v-if="!affiliation.isValid"
                class="text-red-500"
              >
                Affiliation must not be empty.
              </p>
            </div>
moon's avatar
moon committed
            <div
              class="my-4"
              :class="{ invalid: !profileLink.isValid }"
            >
raghosh's avatar
raghosh committed
                class="
                  text-left
                  font-bold
                  mb-2
                  text-xl
                  sm:text-2xl
                  font-montserrat
                "
              >
                Profile Link
              </h1>
              <input
                v-model.trim="profileLink.val"
                type="text"
                class="
                  text-xl
                  outline-none
                  px-4
                  py-5
                  rounded-lg
raghosh's avatar
raghosh committed
                  w-full
                  bg-transparent
                  hover:border-blue-700
                  focus:border-blue-700
                "
                placeholder="eg- https://www.google.com (optional)"
moon's avatar
moon committed
                @blur="clearValidity('profileLink')"
              >
              <p
                v-if="!profileLink.isValid"
                class="text-red-500"
              >
                The url entered is invalid. Please check it again!
              </p>
              <p
                v-if="profileLinkError && profileLinkErrMsg"
                class="text-red-500"
              >
                {{ profileLinkErrMsg }}
              </p>
            </div>
moon's avatar
moon committed
            <div
              class="my-4"
              :class="{ invalid: !motivation.isValid }"
            >
raghosh's avatar
raghosh committed
              <h1
                class="
                  text-left
                  font-bold
                  mb-2
                  text-xl
                  sm:text-2xl
                  font-montserrat
                "
              >
                Motivation*
moon's avatar
moon committed
              </h1>
              <textarea
raghosh's avatar
raghosh committed
                v-model.trim="motivation.val"
moon's avatar
moon committed
                rows="5"
                type="text"
raghosh's avatar
raghosh committed
                class="
                  text-xl
                  outline-none
                  w-full
                  bg-transparent
raghosh's avatar
raghosh committed
                  py-5
                  rounded-lg
raghosh's avatar
raghosh committed
                  hover:border-blue-700
                  focus:border-blue-700
                "
                placeholder="Your motivation text."
moon's avatar
moon committed
                @blur="clearValidity('motivation')"
moon's avatar
moon committed
              />
moon's avatar
moon committed
            <p
              v-if="!motivation.isValid"
              class="text-red-500"
            >
              Motivation text must not be empty.
            </p>
moon's avatar
moon committed
            <p
              v-if="!formIsValid"
              class="font-bold text-red-400"
            >
              Required fields were not provided.
            </p>
moon's avatar
moon committed
            <p
              v-show="error"
              class="text-red-500"
            >
              {{ errorMsg }}
            </p>
            <div v-if="isLoading">
              <base-spinner />
            </div>
           
moon's avatar
moon committed
            <button
              type="submit"
              class="
raghosh's avatar
raghosh committed
                  text-2xl
                  font-bold
                  rounded-lg
                  p-5
raghosh's avatar
raghosh committed
                  text-white
raghosh's avatar
raghosh committed
                "
moon's avatar
moon committed
            >
              Create Account
            </button>
moon's avatar
moon committed
              <h4 class="mt-6">
                Already have an account? <a
                  class="text-blue-500 hover:text-blue-600 hover:no-underline"
                  @click="$router.go(-1)"
                >Sign in</a>
              </h4>
moon's avatar
moon committed
            </div>
moon's avatar
moon committed
          </form>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
moon's avatar
moon committed
import BaseSpinner from '../components/UI/BaseSpinner.vue';
import BaseToaster from '../components/UI/BaseToaster.vue';
let host = require('@/components/js/const').apiHost;
moon's avatar
moon committed
export default {
moon's avatar
moon committed
  name: 'Register',
raghosh's avatar
raghosh committed
  components: { BaseToaster, BaseSpinner },
moon's avatar
moon committed
  data() {
    return {
raghosh's avatar
raghosh committed
      name: {
moon's avatar
moon committed
        val: '',
raghosh's avatar
raghosh committed
      },
      email: {
moon's avatar
moon committed
        val: '',
raghosh's avatar
raghosh committed
      },
      password: {
moon's avatar
moon committed
        val: '',
raghosh's avatar
raghosh committed
      },
      username: {
moon's avatar
moon committed
        val: '',
raghosh's avatar
raghosh committed
      },
      motivation: {
moon's avatar
moon committed
        val: '',
raghosh's avatar
raghosh committed
      },
      affiliation: {
moon's avatar
moon committed
        val: '',
raghosh's avatar
raghosh committed
      },
      current_role: {
moon's avatar
moon committed
        val: '',
raghosh's avatar
raghosh committed
      },
      profileLink: {
moon's avatar
moon committed
        val: '',
raghosh's avatar
raghosh committed
      },
      scientific_discipline: {
raghosh's avatar
raghosh committed
      },
moon's avatar
moon committed
      error: false,
raghosh's avatar
raghosh committed
      errorMsg: ``,
moon's avatar
moon committed
      isDev: process.env.NODE_ENV === 'development',
raghosh's avatar
raghosh committed
      toasterIsOpen: false,
      scientificDisciplineOptions: [
moon's avatar
moon committed
        { id: '1', discipline: 'Physics' },
        { id: '2', discipline: 'Chemistry' },
        { id: '3', discipline: 'Biology' },
        { id: '4', discipline: 'Computer Science' },
        { id: '5', discipline: 'Mathematics' },
raghosh's avatar
raghosh committed
      ],
      profileLinkError: false,
moon's avatar
moon committed
      profileLinkErrMsg: '',
raghosh's avatar
raghosh committed
    };
moon's avatar
moon committed
  methods: {
    clearValidity(input) {
      this[input].isValid = true;
raghosh's avatar
raghosh committed
    },
    validateForm() {
      this.formIsValid = true;
moon's avatar
moon committed
      if (this.name.val === '') {
        this.name.isValid = false;
        this.formIsValid = false;
      }
moon's avatar
moon committed
      if (this.email.val === '') {
        this.email.isValid = false;
        this.formIsValid = false;
      }
moon's avatar
moon committed
      if (this.password.val === '' || this.password.val.length < 6) {
        
        this.password.isValid = false;
        this.formIsValid = false;
      }
moon's avatar
moon committed
      if (this.username.val === '' || this.username.val.length < 3) {
        this.username.isValid = false;
        this.formIsValid = false;
      }
moon's avatar
moon committed
      if (this.current_role.val === '') {
        this.current_role.isValid = false;
        this.formIsValid = false;
      }
      if (this.scientific_discipline.val.length === 0) {
        this.scientific_discipline.isValid = false;
        this.formIsValid = false;
      }
moon's avatar
moon committed
      if (this.affiliation.val === '') {
        this.affiliation.isValid = false;
        this.formIsValid = false;
      }
      if (this.isValidHttpUrl() === false) {
        this.profileLink.isValid = false;
        this.formIsValid = false;
      }
moon's avatar
moon committed
      if (this.motivation.val === '') {
        this.motivation.isValid = false;
        this.formIsValid = false;
      }
raghosh's avatar
raghosh committed
    },
    isValidHttpUrl() {
      let timer = null;
moon's avatar
moon committed
        '^(https?:\\/\\/)?' + // protocol
          '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
          '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
          '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
          '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
          '(\\#[-a-z\\d_]*)?$',
        'i'
      ); // fragment locator
      let isValid;
moon's avatar
moon committed
      if (this.profileLink.val === '') {
        console.log('profile link empty');
        return true;
      } else {
        isValid = pattern.test(this.profileLink.val);
moon's avatar
moon committed
        console.log('lint is there', isValid);
      }
      return isValid;
      //     if(!isValid){
      //       console.log("triggered");
      // this.profileLinkError= true;
      // this.profileLinkErrMsg="The url entered is invalid. Please check it again!"
      //     } else{
      // this.profileLinkError=false;
      // this.profileLinkErrMsg=""
      //     }
      // clearTimeout(timer);
      // timer= setTimeout(()=>{
      //   let isValid= pattern.test(this.profileLink.val);
      //     if(!isValid){
      //       console.log("triggered");
      // this.profileLinkError= true;
      // this.profileLinkErrMsg="The url entered is invalid. Please check it again!"
      //     } else{
      // this.profileLinkError=false;
      // this.profileLinkErrMsg=""
      //     }
raghosh's avatar
raghosh committed

raghosh's avatar
raghosh committed
    showDialog() {
      this.toasterIsOpen = true;
    },
    hideDialog() {
      this.toasterIsOpen = false;
moon's avatar
moon committed
      this.$router.push('login');
moon's avatar
moon committed
    async register(e) {
raghosh's avatar
raghosh committed
      const vm = this;
      vm.validateForm();
      if (!vm.formIsValid) {
        return;
      }
raghosh's avatar
raghosh committed
      if (vm.isDev) {
moon's avatar
moon committed
        host = require('@/components/js/const').devApiHost;
raghosh's avatar
raghosh committed
      }
      this.isLoading = true;
      const res = await fetch(`${host}/api/auth/local/register`, {
moon's avatar
moon committed
        method: 'POST',
        mode: 'cors', // no-cors, *cors, same-origin
        cache: 'no-cache', // *default, no-cache, reload, force-cache,
moon's avatar
moon committed
          'Content-Type': 'application/json',
          // 'Content-Type': 'application/x-www-form-urlencoded',
        },
        body: JSON.stringify({
         full_name: vm.name.val,
raghosh's avatar
raghosh committed
          password: vm.password.val,
          email: vm.email.val,
          username: vm.username.val,
          motivation_text: vm.motivation.val,
          current_role: vm.current_role.val,
          scientific_discipline: vm.scientific_discipline.val,
          current_affiliation: vm.affiliation.val,
          profile_link: vm.profileLink.val,
        }),
      });
       if (!res.ok && res.status === 500) {
        this.isLoading = false;
        this.error = true;
        this.errorMsg = `${res.status} Internal Error, please write a mail to DDCode Admin`;

        return;
      }
      if (!res.ok && res.status === 405) {
        this.isLoading = false;
        this.error = true;
        this.errorMsg = `${res.status} Internal Error, please write a mail to DDCode Admin`;

        return;
      }
      const response = await res.json();
moon's avatar
moon committed
      if (!res.ok && response.error.status === 400 && response.error.message === 'Email is already taken') {
        this.isLoading = false;
        this.error = true;
moon's avatar
moon committed
        this.errorMsg = 'Email Address already registered with an existing account. You can reset your password by clicking forget password from sign up page.';
        this.password.val = '';
      this.isLoading = false;
        vm.toasterIsOpen = true;
        this.error = false;
moon's avatar
moon committed
        this.errorMsg = '';
      // try {
      //   await vm.axios.post(`${host}/api/auth/local/register`, {
      //     full_name: vm.name.val,
      //     password: vm.password.val,
      //     email: vm.email.val,
      //     username: vm.username.val,
      //     motivation_text: vm.motivation.val,
      //     current_role: vm.current_role.val,
      //     scientific_discipline: vm.scientific_discipline.val,
      //     current_affiliation: vm.affiliation.val,
      //     profile_link: vm.profileLink.val,
      //   });

      //   this.isLoading = false;
      //   vm.toasterIsOpen = true;
      //   this.error = false;
      //   this.errorMsg = "";
      //   //vm.$router.push('login')
      // } catch (e) {
      //   console.error(e);
      //   this.isLoading = false;
      //   if (e.message === "Request failed with status code 405") {
      //     console.log(e.message);
      //   }
      //   if (e.message === "Request failed with status code 400") {
      //     vm.error = true;
      //     vm.errorMsg =
      //       "Email Address already registered with an existing account. You can reset your password by clicking forget password from sign up page.";
      //   }

      
      // }
raghosh's avatar
raghosh committed
    },
  },
};
moon's avatar
moon committed
</script>
raghosh's avatar
raghosh committed
@import url("~@/assets/bootstrap.css");
raghosh's avatar
raghosh committed
a {
  color: #ef0087 !important;
raghosh's avatar
raghosh committed
}
.invalid h1,
raghosh's avatar
raghosh committed
  color: red;
}
.invalid input,
.invalid textarea,
raghosh's avatar
raghosh committed
  border: 1px solid red;
}
moon's avatar
moon committed
</style>