123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- <template>
- <div>
- <metadata title="Register" v-if="isPage" />
- <div class="modal is-active">
- <div class="modal-background" @click="closeRegisterModal()" />
- <div class="modal-card">
- <header class="modal-card-head">
- <p class="modal-card-title">Register</p>
- <button
- v-if="!isPage"
- class="delete"
- @click="closeRegisterModal()"
- />
- </header>
- <section class="modal-card-body">
- <!-- email address -->
- <p class="control">
- <label class="label">Email</label>
- <input
- v-model="email.value"
- class="input"
- type="email"
- placeholder="Email..."
- @keypress="onInput('email')"
- autofocus
- />
- </p>
- <transition name="fadein-helpbox">
- <input-help-box
- :entered="email.entered"
- :valid="email.valid"
- :message="email.message"
- ></input-help-box>
- </transition>
- <!-- username -->
- <p class="control">
- <label class="label">Username</label>
- <input
- v-model="username.value"
- class="input"
- type="text"
- placeholder="Username..."
- @keypress="onInput('username')"
- />
- </p>
- <transition name="fadein-helpbox">
- <input-help-box
- :entered="username.entered"
- :valid="username.valid"
- :message="username.message"
- ></input-help-box>
- </transition>
- <!-- password -->
- <p class="control">
- <label class="label">Password</label>
- </p>
- <div id="password-container">
- <input
- v-model="password.value"
- class="input"
- type="password"
- ref="password"
- placeholder="Password..."
- @keypress="
- onInput('password') &&
- $parent.submitOnEnter(submitModal, $event)
- "
- />
- <a @click="togglePasswordVisibility()">
- <i class="material-icons">
- {{
- !password.visible
- ? "visibility"
- : "visibility_off"
- }}
- </i>
- </a>
- </div>
- <transition name="fadein-helpbox">
- <input-help-box
- :valid="password.valid"
- :entered="password.entered"
- :message="password.message"
- ></input-help-box>
- </transition>
- <br />
- <p>
- By registering you agree to our
- <router-link
- to="/terms"
- @click.native="closeRegisterModal()"
- >
- Terms of Service
- </router-link>
- and
- <router-link
- to="/privacy"
- @click.native="closeRegisterModal()"
- >
- Privacy Policy </router-link
- >.
- </p>
- </section>
- <footer class="modal-card-foot">
- <div id="actions">
- <a
- class="button is-primary"
- href="#"
- @click="submitModal()"
- >Register</a
- >
- <a
- class="button is-github"
- :href="apiDomain + '/auth/github/authorize'"
- @click="githubRedirect()"
- >
- <div class="icon">
- <img
- class="invert"
- src="/assets/social/github.svg"
- />
- </div>
- Register with GitHub
- </a>
- </div>
- <router-link to="/login" v-if="isPage">
- Already have an account?
- </router-link>
- <a v-else href="#" @click="changeToLoginModal()">
- Already have an account?
- </a>
- </footer>
- </div>
- </div>
- </div>
- </template>
- <script>
- import { mapActions } from "vuex";
- import Toast from "toasters";
- import validation from "@/validation";
- import InputHelpBox from "../InputHelpBox.vue";
- export default {
- components: { InputHelpBox },
- data() {
- return {
- username: {
- value: "",
- valid: false,
- entered: false,
- message: "Only letters, numbers and underscores are allowed."
- },
- email: {
- value: "",
- valid: false,
- entered: false,
- message: "Please enter a valid email address."
- },
- password: {
- value: "",
- valid: false,
- entered: false,
- visible: false,
- message:
- "Include at least one lowercase letter, one uppercase letter, one number and one special character."
- },
- recaptcha: {
- key: "",
- token: "",
- enabled: false
- },
- apiDomain: "",
- isPage: false
- };
- },
- watch: {
- // eslint-disable-next-line
- "username.value": function (value) {
- if (!validation.isLength(value, 2, 32)) {
- this.username.message =
- "Username must have between 2 and 32 characters.";
- this.username.valid = false;
- } else if (!validation.regex.azAZ09_.test(value)) {
- this.username.message =
- "Invalid format. Allowed characters: a-z, A-Z, 0-9 and _.";
- this.username.valid = false;
- } else {
- this.username.message = "Everything looks great!";
- this.username.valid = true;
- }
- },
- // eslint-disable-next-line
- "email.value": function (value) {
- if (!validation.isLength(value, 3, 254)) {
- this.email.message =
- "Email must have between 3 and 254 characters.";
- this.email.valid = false;
- } else if (
- value.indexOf("@") !== value.lastIndexOf("@") ||
- !validation.regex.emailSimple.test(value)
- ) {
- this.email.message = "Invalid format.";
- this.email.valid = false;
- } else {
- this.email.message = "Everything looks great!";
- this.email.valid = true;
- }
- },
- // eslint-disable-next-line
- "password.value": function (value) {
- if (!validation.isLength(value, 6, 200)) {
- this.password.message =
- "Password must have between 6 and 200 characters.";
- this.password.valid = false;
- } else if (!validation.regex.password.test(value)) {
- this.password.message =
- "Include at least one lowercase letter, one uppercase letter, one number and one special character.";
- this.password.valid = false;
- } else {
- this.password.message = "Everything looks great!";
- this.password.valid = true;
- }
- }
- },
- async mounted() {
- if (this.$route.path === "/register") this.isPage = true;
- this.apiDomain = await lofig.get("apiDomain");
- lofig.get("recaptcha").then(obj => {
- this.recaptcha.enabled = obj.enabled;
- if (obj.enabled === true) {
- this.recaptcha.key = obj.key;
- const recaptchaScript = document.createElement("script");
- recaptchaScript.onload = () => {
- grecaptcha.ready(() => {
- grecaptcha
- .execute(this.recaptcha.key, { action: "login" })
- .then(token => {
- this.recaptcha.token = token;
- });
- });
- };
- recaptchaScript.setAttribute(
- "src",
- `https://www.google.com/recaptcha/api.js?render=${this.recaptcha.key}`
- );
- document.head.appendChild(recaptchaScript);
- }
- });
- },
- methods: {
- togglePasswordVisibility() {
- if (this.$refs.password.type === "password") {
- this.$refs.password.type = "text";
- this.password.visible = true;
- } else {
- this.$refs.password.type = "password";
- this.password.visible = false;
- }
- },
- changeToLoginModal() {
- if (!this.isPage) {
- this.closeRegisterModal();
- this.openModal({ sector: "header", modal: "login" });
- }
- },
- closeRegisterModal() {
- if (!this.isPage)
- this.closeModal({ sector: "header", modal: "login" });
- },
- submitModal() {
- if (
- !this.username.valid ||
- !this.email.valid ||
- !this.password.valid
- )
- return new Toast("Please ensure all fields are valid.");
- return this.register({
- username: this.username.value,
- email: this.email.value,
- password: this.password.value,
- recaptchaToken: this.recaptcha.token
- })
- .then(res => {
- if (res.status === "success") window.location.href = "/";
- })
- .catch(err => new Toast(err.message));
- },
- onInput(inputName) {
- this[inputName].entered = true;
- },
- githubRedirect() {
- localStorage.setItem("github_redirect", this.$route.path);
- },
- ...mapActions("modalVisibility", ["closeModal", "openModal"]),
- ...mapActions("user/auth", ["register"])
- }
- };
- </script>
- <style lang="scss" scoped>
- .night-mode {
- .modal-card,
- .modal-card-head,
- .modal-card-body,
- .modal-card-foot {
- background-color: var(--dark-grey-3);
- }
- .label,
- p:not(.help) {
- color: var(--light-grey-2);
- }
- }
- #password-container {
- display: flex;
- align-items: center;
- a {
- width: 0;
- margin-left: -30px;
- z-index: 0;
- top: 2px;
- position: relative;
- color: var(--light-grey-1);
- }
- }
- .control {
- margin-bottom: 2px !important;
- }
- .modal-card-foot {
- display: flex;
- justify-content: space-between;
- flex-wrap: wrap;
- }
- .button.is-github {
- background-color: var(--dark-grey-2);
- color: var(--white) !important;
- }
- .is-github:focus {
- background-color: var(--dark-grey-4);
- }
- .invert {
- filter: brightness(5);
- }
- #recaptcha {
- padding: 10px 0;
- }
- a {
- color: var(--primary-color);
- }
- </style>
- <style lang="scss">
- .grecaptcha-badge {
- z-index: 2000;
- }
- </style>
|