Skip to content

Commit

Permalink
add subdomain field when register user
Browse files Browse the repository at this point in the history
  • Loading branch information
MohMehrnia committed Sep 14, 2020
1 parent 11c1ad6 commit 38f6a5c
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 143 deletions.
307 changes: 164 additions & 143 deletions src/components/userManagement/registerUser.vue
Original file line number Diff line number Diff line change
@@ -1,156 +1,177 @@
<template v-slot:items="props">
<v-container fluid fill-height>
<v-layout align-center>
<v-row justify="center" align="center" no-gutters>
<v-col cols="12" md="5" lg="5">
<v-row>
<v-col>
<ValidationObserver ref="observer" v-slot="{ handleSubmit, invalid }">
<form @submit.prevent="handleSubmit(onSubmit)" autocomplete="off">
<v-card class="mx-auto" outlined>
<v-card-title :class="$store.state.defaultColor + ' white--text'">
<v-icon large color="white">mdi-account-plus</v-icon>
<span class="mr-2">
<v-container fluid fill-height>
<v-layout align-center>
<v-row justify="center" align="center" no-gutters>
<v-col cols="12" md="5" lg="5">
<v-row>
<v-col>
<ValidationObserver ref="observer" v-slot="{ handleSubmit, invalid }">
<form @submit.prevent="handleSubmit(onSubmit)" autocomplete="off">
<v-card class="mx-auto" outlined>
<v-card-title :class="$store.state.defaultColor + ' white--text'">
<v-icon large color="white">mdi-account-plus</v-icon>
<span class="mr-2">
ثبت نام
</span>
</v-card-title>
<v-card-text class="mt-5">
<ValidationProvider
v-slot="{ errors }"
name="عنوان شرکت"
rules="required"
immediate
>
<v-text-field
v-model="company.title"
label="عنوان شرکت"
clearable
:error-messages="errors"
outlined
shaped
></v-text-field>
</ValidationProvider>
<ValidationProvider
v-slot="{ errors }"
name="آدرس ایمیل"
rules="required|email"
vid="email"
immediate
>
<v-text-field
v-model="company.email"
label="آدرس ایمیل"
clearable
:type="'email'"
:error-messages="errors"
outlined
shaped
dir="ltr"
></v-text-field>
</ValidationProvider>
<div style="text-align: center" v-if="$store.state.isOnline">
<vue-hcaptcha
sitekey="e3605ee2-18a4-4e7c-9a8e-5885075be08e"
@verify="captchaVerified"
@error="hCaptchaVerified=false">
</vue-hcaptcha>
</div>
</v-card-text>
</v-card-title>
<v-card-text class="mt-5">
<ValidationProvider
v-slot="{ errors }"
name="عنوان شرکت"
rules="required"
immediate
>
<v-text-field
v-model="company.title"
label="عنوان شرکت"
clearable
:error-messages="errors"
outlined
shaped
></v-text-field>
</ValidationProvider>
<ValidationProvider
v-slot="{ errors }"
name="آدرس ایمیل"
rules="required|email"
vid="email"
immediate
>
<v-text-field
v-model="company.email"
label="آدرس ایمیل"
clearable
:type="'email'"
:error-messages="errors"
outlined
shaped
dir="ltr"
></v-text-field>
</ValidationProvider>
<ValidationProvider
v-slot="{ errors }"
name="عنوان دامنه"
:rules="{ required,regex: /^([a-zA-Z0-9][a-zA-Z0-9-_]*\.)*[a-zA-Z0-9]*[a-zA-Z0-9-_]*[[a-zA-Z0-9]+$a/ }"
vid="subdomain"
immediate
>
<v-text-field
v-model="company.subdomain"
label="آدرس زیردامنه"
clearable
:error-messages="errors"
outlined
shaped
dir="ltr"
></v-text-field>
</ValidationProvider>
<div style="text-align: center" v-if="$store.state.isOnline">
<vue-hcaptcha
sitekey="e3605ee2-18a4-4e7c-9a8e-5885075be08e"
@verify="captchaVerified"
@error="hCaptchaVerified=false">
</vue-hcaptcha>
</div>
</v-card-text>

<v-card-actions>
<v-btn
color="$store.state.defaultColor + ' darken-1'"
:disabled="invalid"
value="registerUser"
type="submit"
text>
ثبت نام
</v-btn>
<v-btn
:color="$store.state.defaultColor + ' darken-1'"
text
@click="$router.push('/login')"
>
برگشت
</v-btn>
</v-card-actions>
</v-card>
</form>
</ValidationObserver>
</v-col>
</v-row>
</v-col>
</v-row>
</v-layout>
</v-container>
<v-card-actions>
<v-btn
color="$store.state.defaultColor + ' darken-1'"
:disabled="invalid"
value="registerUser"
type="submit"
text>
ثبت نام
</v-btn>
<v-btn
:color="$store.state.defaultColor + ' darken-1'"
text
@click="$router.push('/login')"
>
برگشت
</v-btn>
</v-card-actions>
</v-card>
</form>
</ValidationObserver>
</v-col>
</v-row>
</v-col>
</v-row>
</v-layout>
</v-container>
</template>

<script>
import {required, email} from "vee-validate/dist/rules";
import {mapActions} from "vuex";
import VueHcaptcha from '@hcaptcha/vue-hcaptcha';
import {
extend,
ValidationObserver,
ValidationProvider,
setInteractionMode
} from "vee-validate";
import {required, email, regex} from "vee-validate/dist/rules";
import {mapActions} from "vuex";
import VueHcaptcha from '@hcaptcha/vue-hcaptcha';
import {
extend,
ValidationObserver,
ValidationProvider,
setInteractionMode
} from "vee-validate";
setInteractionMode("eager");
extend("required", {
...required,
message: "{_field_} نمی تواند خالی باشد"
});
extend("email", {
...email,
message:"{_field_} آدرس معتبری نمی باشد"
});
setInteractionMode("eager");
extend("regex", {
...regex,
message: "{_field_} نامعتیر می باشد"
});
extend("required", {
...required,
message: "{_field_} نمی تواند خالی باشد"
});
extend("email", {
...email,
message: "{_field_} آدرس معتبری نمی باشد"
});
export default {
name: "registerUser",
data() {
return {
company: {
title: "",
email: ""
},
submitStatus: null,
hCaptchaVerified: false
};
},
components: {
ValidationProvider,
ValidationObserver,
VueHcaptcha
},
methods: {
...mapActions({
registerUser: "CompanyService/addCompany",
IsEmailExists: "UserService/IsEmailExists"
}),
onSubmit: function () {
if (this.hCaptchaVerified !== true && this.$store.state.isOnline) return;
this.IsEmailExists(this.company.email).then((res) => {
if (res.data === true) {
this.$refs.observer.setErrors({
email: ['آدرس ایمیل قبلا به ثبت رسیده است']
});
} else {
this.registerUser(this.company).then(() => {
this.$router.push("/registerUserConfirm")
});
}
});
},
captchaVerified(e) {
if (e) this.hCaptchaVerified = true;
else this.hCaptchaVerified = false;
}
},
metaInfo: {
title: 'ثبت نام'
}
export default {
name: "registerUser",
data() {
return {
company: {
title: "",
email: ""
},
submitStatus: null,
hCaptchaVerified: false
};
},
components: {
ValidationProvider,
ValidationObserver,
VueHcaptcha
},
methods: {
...mapActions({
registerUser: "CompanyService/addCompany",
IsEmailExists: "UserService/IsEmailExists"
}),
onSubmit: function () {
if (this.hCaptchaVerified !== true && this.$store.state.isOnline) return;
this.IsEmailExists(this.company.email).then((res) => {
if (res.data === true) {
this.$refs.observer.setErrors({
email: ['آدرس ایمیل قبلا به ثبت رسیده است']
});
} else {
this.registerUser(this.company).then(() => {
this.$router.push("/registerUserConfirm")
});
}
});
},
captchaVerified(e) {
if (e) this.hCaptchaVerified = true;
else this.hCaptchaVerified = false;
}
},
metaInfo: {
title: 'ثبت نام'
}
};
</script>

<style scoped>
Expand Down
1 change: 1 addition & 0 deletions src/store/models/Company.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class Company extends Model {
id: this.uid(() => this.$uuid.v4()),
title: this.attr(''),
email: this.attr(''),
subdomain:this.attr(''),
allowdelete:this.boolean(null)
};
}
Expand Down

0 comments on commit 38f6a5c

Please sign in to comment.