add otp form
This commit is contained in:
+1
-1
@@ -143,7 +143,7 @@ export default {
|
|||||||
autoFetch: true,
|
autoFetch: true,
|
||||||
},
|
},
|
||||||
endpoints: {
|
endpoints: {
|
||||||
login: { url: "/api/auth/login", method: "post" },
|
login: { url: "/api/otp/verify", method: "post" },
|
||||||
logout: {
|
logout: {
|
||||||
url: "/api/auth/logout",
|
url: "/api/auth/logout",
|
||||||
method: "delete",
|
method: "delete",
|
||||||
|
|||||||
+75
-7
@@ -4,8 +4,24 @@
|
|||||||
<CCardGroup>
|
<CCardGroup>
|
||||||
<CCard class="p-4">
|
<CCard class="p-4">
|
||||||
<CCardBody>
|
<CCardBody>
|
||||||
<CForm @submit.prevent="doLogin">
|
<CForm
|
||||||
|
v-if="step === 1"
|
||||||
|
@submit.prevent="doLogin">
|
||||||
<h1 class="text-muted text-center mb-5">پنل مدیریت</h1>
|
<h1 class="text-muted text-center mb-5">پنل مدیریت</h1>
|
||||||
|
|
||||||
|
<CInput
|
||||||
|
:class="validation.username ? 'err' : null"
|
||||||
|
placeholder="شماره موبایل"
|
||||||
|
:description="validation.username ? validation.username.msg : null"
|
||||||
|
autocomplete="username email"
|
||||||
|
v-model="phone"
|
||||||
|
>
|
||||||
|
<template #prepend-content>
|
||||||
|
<CIcon name="cil-user"/>
|
||||||
|
</template>
|
||||||
|
</CInput>
|
||||||
|
<!--
|
||||||
|
|
||||||
<CInput
|
<CInput
|
||||||
:class="validation.username ? 'err' : null"
|
:class="validation.username ? 'err' : null"
|
||||||
placeholder="نام کاربری"
|
placeholder="نام کاربری"
|
||||||
@@ -35,16 +51,43 @@
|
|||||||
<i @click="showPass = !showPass" class="far fa-eye"></i>
|
<i @click="showPass = !showPass" class="far fa-eye"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<CInputCheckbox label="مرا به خاطر بسپار" @update:checked="val => login.remember_me = val"/>
|
<CInputCheckbox label="مرا به خاطر بسپار" @update:checked="val => login.remember_me = val"/> -->
|
||||||
|
<CRow>
|
||||||
|
<CCol col="12" class="text-right mt-2">
|
||||||
|
<CButton color="primary" @click="send_number" class="px-4">ارسال کد</CButton>
|
||||||
|
</CCol>
|
||||||
|
</CRow>
|
||||||
|
<!-- <p class="text-muted mt-3" style="font-size: 11px;">*درصورتی که گزینه "مرا به خاطر بسپار" را فعال نکنید بعد از 1 ساعت باید دوباره وارد سیستم شوید.</p> -->
|
||||||
|
|
||||||
<p class="text-muted mt-3" style="font-size: 11px;">*درصورتی که گزینه "مرا به خاطر بسپار" را فعال نکنید بعد از 1 ساعت باید دوباره وارد سیستم شوید.</p>
|
</CForm>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<CForm
|
||||||
|
v-if="step === 2"
|
||||||
|
@submit.prevent="doLogin">
|
||||||
|
<h1 class="text-muted text-center mb-5">پنل مدیریت</h1>
|
||||||
|
<CInput
|
||||||
|
:class="validation.username ? 'err' : null"
|
||||||
|
placeholder="کد ورود را وارد کنید"
|
||||||
|
:description="validation.username ? validation.username.msg : null"
|
||||||
|
autocomplete="username email"
|
||||||
|
v-model="otp"
|
||||||
|
>
|
||||||
|
<template #prepend-content>
|
||||||
|
<CIcon name="cil-user"/>
|
||||||
|
</template>
|
||||||
|
</CInput>
|
||||||
|
|
||||||
<CRow>
|
<CRow>
|
||||||
<CCol col="12" class="text-right mt-2">
|
<CCol col="12" class="text-right mt-2">
|
||||||
<CButton color="primary" type="submit" class="px-4">ورود</CButton>
|
<CButton color="primary" type="submit" class="px-4">ارسال کد</CButton>
|
||||||
</CCol>
|
</CCol>
|
||||||
</CRow>
|
</CRow>
|
||||||
</CForm>
|
</CForm>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</CCardBody>
|
</CCardBody>
|
||||||
</CCard>
|
</CCard>
|
||||||
</CCardGroup>
|
</CCardGroup>
|
||||||
@@ -53,10 +96,14 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { ref } from 'vue';
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
showPass: false,
|
showPass: false,
|
||||||
|
step: 1,
|
||||||
|
phone: '',
|
||||||
|
otp: '',
|
||||||
login: {
|
login: {
|
||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
@@ -71,11 +118,31 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async send_number(){
|
||||||
|
console.log(this.phone)
|
||||||
|
const phoneNumber = this.phone
|
||||||
|
const send_request = await fetch('/api/auth/otp', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Accept' : 'application/json',
|
||||||
|
'content-type' : 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({phone: phoneNumber})
|
||||||
|
|
||||||
|
})
|
||||||
|
//if (send_request.status === 200) {
|
||||||
|
this.step = 2
|
||||||
|
//}
|
||||||
|
|
||||||
|
},
|
||||||
doLogin() {
|
doLogin() {
|
||||||
this.validation = {}
|
this.validation = {}
|
||||||
|
|
||||||
this.$auth.loginWith('local', {
|
this.$auth.loginWith('local', {
|
||||||
data: this.login
|
data: {
|
||||||
|
phone: this.phone,
|
||||||
|
code: this.otp
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
window.location.replace(window.location.origin + "/admin" )
|
window.location.replace(window.location.origin + "/admin" )
|
||||||
@@ -91,8 +158,9 @@ export default {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
layout: 'admin-auth'
|
layout: 'admin-auth',
|
||||||
}
|
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
|||||||
@@ -165,11 +165,11 @@ module.exports.otp = [
|
|||||||
// .withMessage(_sr["fa"].min_char.min4),
|
// .withMessage(_sr["fa"].min_char.min4),
|
||||||
],
|
],
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
|
console.log('body', req.body)
|
||||||
try {
|
try {
|
||||||
const errors = validationResult(req);
|
const errors = validationResult(req);
|
||||||
if (!errors.isEmpty())
|
if (!errors.isEmpty())
|
||||||
return res.status(422).json({ validation: errors.mapped() });
|
return res.status(422).json({ validation: errors.mapped() });
|
||||||
|
|
||||||
const { phone } = req.body;
|
const { phone } = req.body;
|
||||||
const user = await User.findOne({ mobileNumber: phone });
|
const user = await User.findOne({ mobileNumber: phone });
|
||||||
if (!user)
|
if (!user)
|
||||||
|
|||||||
Reference in New Issue
Block a user