shiori/view/login.html
2018-05-23 23:12:16 +07:00

110 lines
No EOL
4.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="/css/stylesheet.css">
<link rel="stylesheet" href="/css/fontawesome.css">
<link rel="stylesheet" href="/css/source-sans-pro.css">
<script src="/js/vue.js"></script>
<script src="/js/axios.js"></script>
<script src="/js/js-cookie.js"></script>
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/res/apple-touch-icon-144x144.png" />
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="/res/apple-touch-icon-152x152.png" />
<link rel="icon" type="image/png" href="/res/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="/res/favicon-16x16.png" sizes="16x16" />
<title>Login - Shiori - Bookmarks Manager</title>
</head>
<body>
<div id="login-page" :class="{night: nightMode}">
<p class="error-message" v-if="error !== ''">{{error}}</p>
<div id="login-box">
<div id="logo-area">
<p id="logo">
<span></span>shiori
</p>
<p id="tagline">simple bookmark manager</p>
</div>
<div id="input-area">
<div class="input-field">
<p>Username: </p>
<input type="text" name="username" v-model.trim="username" placeholder="Username">
</div>
<div class="input-field">
<p>Password: </p>
<input type="password" name="password" v-model.trim="password" placeholder="Password" @keyup.enter="login">
</div>
<div class="input-field">
<a @click="toggleRemember">
<i class="fa-fw" :class="rememberMe ? 'fas fa-check-square' : 'far fa-square'"></i>Remember me
</a>
</div>
</div>
<div id="button-area">
<a v-if="loading">
<i class="fas fa-fw fa-spinner fa-spin"></i>
</a>
<a v-else class="button" @click="login">Login</a>
</div>
</div>
</div>
<script>
var app = new Vue({
el: '#login-page',
data: {
error: '',
loading: false,
username: '',
password: '',
rememberMe: false,
nightMode: false,
},
methods: {
toggleRemember: function () {
this.rememberMe = !this.rememberMe;
},
login: function () {
// Validate input
if (this.username === '') {
this.error = 'Username must not empty';
return;
}
// Send request
this.loading = true;
axios.post('/api/login', {
username: this.username,
password: this.password,
remember: this.rememberMe
}, {
timeout: 10000
})
.then(function (response) {
var token = response.data;
Cookies.set('token', token, {
expires: this.rememberMe ? 7 : 1
});
location.href = '/';
})
.catch(function (error) {
var errorMsg = (error.response ? error.response.data : error.message).trim();
app.password = '';
app.loading = false;
app.error = errorMsg;
});
}
},
mounted() {
// Read config from local storage
var nightMode = localStorage.getItem('shiori-night-mode');
this.nightMode = nightMode === '1';
}
});
</script>
</body>
</html>