thelounge/client/components/Windows/SignIn.vue

148 lines
2.7 KiB
Vue
Raw Normal View History

2019-02-18 10:18:32 +01:00
<template>
2019-08-03 21:03:45 +02:00
<div id="sign-in" class="window" role="tabpanel" aria-label="Sign-in">
<form class="container" method="post" action="" @submit="onSubmit">
2019-02-18 10:18:32 +01:00
<img
src="img/logo-vertical-transparent-bg.svg"
class="logo"
alt="The Lounge"
width="256"
2019-03-01 15:18:16 +01:00
height="170"
2019-08-03 21:03:45 +02:00
/>
2019-02-18 10:18:32 +01:00
<img
src="img/logo-vertical-transparent-bg-inverted.svg"
class="logo-inverted"
alt="The Lounge"
width="256"
2019-03-01 15:18:16 +01:00
height="170"
2019-08-03 21:03:45 +02:00
/>
2019-02-18 10:18:32 +01:00
<label for="signin-username">Username</label>
<input
id="signin-username"
ref="username"
class="input"
type="text"
name="username"
autocapitalize="none"
autocorrect="off"
autocomplete="username"
:value="getStoredUser()"
required
2019-03-01 15:18:16 +01:00
autofocus
2019-08-03 21:03:45 +02:00
/>
2019-02-18 10:18:32 +01:00
<div class="password-container">
<label for="signin-password">Password</label>
<RevealPassword v-slot:default="slotProps">
<input
id="signin-password"
ref="password"
:type="slotProps.isVisible ? 'text' : 'password'"
name="password"
class="input"
autocapitalize="none"
autocorrect="off"
autocomplete="current-password"
2019-03-01 15:18:16 +01:00
required
2019-08-03 21:03:45 +02:00
/>
2019-02-18 10:18:32 +01:00
</RevealPassword>
</div>
2019-08-03 21:03:45 +02:00
<div v-if="errorShown" class="error">Authentication failed.</div>
2019-02-18 10:18:32 +01:00
<styled-button :disabled="inFlight">Sign in</styled-button>
2019-02-18 10:18:32 +01:00
</form>
</div>
</template>
2022-02-24 01:40:54 +01:00
<style scoped>
.container {
flex: 1 0 auto;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
label {
display: block;
margin-top: 10px;
width: 100%;
}
.btn {
margin-top: 25px;
}
.error {
color: #e74c3c;
margin-top: 1em;
width: 100%;
}
.password-container {
width: 100%;
}
.password-container .reveal-password {
top: 31px;
}
2022-02-24 03:13:28 +01:00
@media (max-width: 479px) {
#sign-in .btn {
width: 100%;
}
}
2022-02-24 01:40:54 +01:00
</style>
2019-02-18 10:18:32 +01:00
<script>
2019-11-16 18:24:03 +01:00
import storage from "../../js/localStorage";
2019-02-18 10:18:32 +01:00
import socket from "../../js/socket";
import RevealPassword from "../RevealPassword.vue";
import StyledButton from "../StyledButton.vue";
2019-02-18 10:18:32 +01:00
export default {
name: "SignIn",
components: {
RevealPassword,
StyledButton,
2019-02-18 10:18:32 +01:00
},
data() {
return {
inFlight: false,
errorShown: false,
};
},
mounted() {
2019-11-12 12:09:12 +01:00
socket.on("auth:failed", this.onAuthFailed);
},
beforeDestroy() {
2019-11-12 12:09:12 +01:00
socket.off("auth:failed", this.onAuthFailed);
},
2019-02-18 10:18:32 +01:00
methods: {
onAuthFailed() {
this.inFlight = false;
this.errorShown = true;
},
2019-02-18 10:18:32 +01:00
onSubmit(event) {
event.preventDefault();
this.inFlight = true;
this.errorShown = false;
const values = {
user: this.$refs.username.value,
password: this.$refs.password.value,
};
storage.set("user", values.user);
2019-11-05 20:29:51 +01:00
socket.emit("auth:perform", values);
2019-02-18 10:18:32 +01:00
},
getStoredUser() {
return storage.get("user");
},
},
};
</script>