Сообщение о неверном вводе

This commit is contained in:
2021-06-03 20:17:01 +03:00
parent baac5a7c17
commit 61518b4fb4
3 changed files with 96 additions and 29 deletions

View File

@@ -2,19 +2,28 @@
<div>
<img id="logo" src="./assets/logo.png">
<div class="pageSide" v-if="loggedin">
<img :src="image" >
<img id="meme" :src="image">
<MazBtn
class="maz-btn--mini"
@click="logout"
>
Logout
</MazBtn>
</div>
<Login v-else id="login" @auth="auth" />
</div>
</template>
<script>
import axios from 'axios';
import Login from './components/Login.vue'
import { MazBtn } from 'maz-ui';
export default {
name: 'App',
components: {
Login
Login,
MazBtn
},
data() {
return {
@@ -27,6 +36,11 @@ export default {
this.loggedin = true
this.image = image
}
},
logout() {
axios.post('http://127.0.0.1:3000/api/logout').then(() => {
this.loggedin = false
});
}
}
}
@@ -37,13 +51,10 @@ body {
background-color: #343a40;
}
#app {
body {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
#logo {
@@ -54,10 +65,21 @@ body {
border-radius: 50%;
}
#meme {
width: 100%;
margin-bottom: 3em;
}
.pageSide {
padding: 1.5rem;
background-color: #FFF;
border-radius: .3rem;
text-align: center;
max-width: 600px;
margin: auto;
}
@media screen and (max-width: 600px) {
}
</style>

View File

@@ -26,6 +26,11 @@
<PassNBtns loginMethod="email" @flip="usePhone = !usePhone" @auth="auth" />
</div>
</transition>
<transition name="slide">
<div v-if="msg" class="msg" v-bind:key="msg">
{{msg}}
</div>
</transition>
</div>
</template>
@@ -43,6 +48,7 @@ export default {
},
data() {
return {
msg: '',
usePhone: false,
email: '',
phone: '',
@@ -57,34 +63,55 @@ export default {
return 'primary'
}
},
async auth(pass) {
axios({
method: "post",
url: "http://127.0.0.1:3000/api/login",
withCredentials: true,
responseType: 'arraybuffer',
headers: {
"Content-Type": "application/json",
},
data: {
login: this.usePhone ? this.phone : this.email,
pass: pass
}
}).then((response) => {
var bytes = new Uint8Array(response.data);
var binary = bytes.reduce((data, b) => data += String.fromCharCode(b), '');
this.src = "data:image/jpeg;base64," + btoa(binary);
this.$emit('auth', this.src)
});
auth(pass, onload) {
if (onload || (pass && this.usePhone ? this.phone : this.email)) {
axios({
method: "post",
url: "http://127.0.0.1:3000/api/login",
withCredentials: true,
responseType: 'arraybuffer',
headers: {
"Content-Type": "application/json",
},
data: {
login: this.usePhone ? this.phone : this.email,
pass: pass
}
}).then((response) => {
this.msg = ''
var bytes = new Uint8Array(response.data);
var binary = bytes.reduce((data, b) => data += String.fromCharCode(b), '');
this.src = "data:image/jpeg;base64," + btoa(binary);
this.$emit('auth', this.src)
}).finally(() => {
if (!onload) {
this.msg = 'Invalid credentials'
}
});
} else {
this.msg = 'Please enter your credentials'
}
}
},
mounted() {
this.auth()
this.auth('', true)
}
}
</script>
<style scoped>
.msg {
position: relative;
padding: .8rem;
background-color: #FFF;
border-radius: .3rem;
text-align: center;
max-width: 150px;
margin: 3em auto 0 auto;
color: orangered;
z-index: -10;
}
.flip-enter-active {
transition: all 0.4s ease;
}
@@ -93,4 +120,12 @@ export default {
transform: perspective(1000px) rotateY(180deg);
opacity: 0;
}
.slide-enter-active {
transition: all 0.4s ease;
}
.slide-enter, .slide-leave {
transform: translateY(-100px);
}
</style>

View File

@@ -2,13 +2,15 @@ const express = require('express')
const cookieSession = require('cookie-session')
const app = express()
const cors = require('cors')
const https = require('https')
const fs = require('fs')
require('dotenv').config()
app.use(cookieSession({
name: 'session',
secret: process.env.SECRET,
maxAge: 24 * 60 * 60 * 1000, // 24 hours
secure: false,
secure: process.env.NODE_ENV === 'production',
sameSite: 'none'
}))
@@ -41,4 +43,12 @@ app.post('/api/logout', (req, res) => {
}
})
app.listen(process.env.PORT)
if (process.env.NODE_ENV === 'production') {
https.createServer({
key: fs.readFileSync(process.env.SSL + '/privkey.pem'),
cert: fs.readFileSync(process.env.SSL + '/cert.pem')
}, app)
.listen(process.env.PORT, () => console.log('Prod server started on ' + process.env.PORT));
} else {
app.listen(process.env.PORT, () => console.log('Dev server started on ' + process.env.PORT));
}