Add Remember me

This commit is contained in:
Viktor Yudov
2024-08-13 02:51:05 +03:00
parent 4e79d0ee03
commit 3e6ded18a5
7 changed files with 49 additions and 3 deletions

View File

@@ -562,7 +562,25 @@
<input type="password" name="password" :placeholder="$t('password')" v-model="password" autocomplete="current-password"
class="px-3 py-2 text-sm dark:bg-neutral-700 text-gray-500 dark:text-gray-500 mb-5 border-2 border-gray-100 dark:border-neutral-800 rounded-lg w-full focus:border-red-800 dark:focus:border-red-800 dark:placeholder:text-neutral-400 outline-none" />
<!-- Remember me -->
<label v-if="rememberMeEnabled"
class="inline-block mb-5 cursor-pointer whitespace-nowrap" :title="$t('titleRememberMe')">
<input type="checkbox" class="sr-only" v-model="remember">
<div v-if="remember"
class="inline-block align-middle rounded-full w-10 h-6 mr-1 bg-red-800 cursor-pointer hover:bg-red-700 transition-all">
<div class="rounded-full w-4 h-4 m-1 ml-5 bg-white"></div>
</div>
<div v-if="!remember"
class="inline-block align-middle rounded-full w-10 h-6 mr-1 bg-gray-200 dark:bg-neutral-400 cursor-pointer hover:bg-gray-300 dark:hover:bg-neutral-500 transition-all">
<div class="rounded-full w-4 h-4 m-1 bg-white"></div>
</div>
<span class="text-sm">{{$t("rememberMe")}}</span>
</label>
<button v-if="authenticating"
class="bg-red-800 dark:bg-red-800 w-full rounded shadow py-2 text-sm text-white dark:text-white cursor-not-allowed">
<svg class="w-5 animate-spin mx-auto" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"

View File

@@ -43,6 +43,13 @@ class API {
});
}
async getRememberMeEnabled() {
return this.call({
method: 'get',
path: '/remember-me',
});
}
async getuiTrafficStats() {
return this.call({
method: 'get',
@@ -64,11 +71,11 @@ class API {
});
}
async createSession({ password }) {
async createSession({ password, remember }) {
return this.call({
method: 'post',
path: '/session',
body: { password },
body: { password, remember },
});
}

View File

@@ -53,6 +53,8 @@ new Vue({
authenticating: false,
password: null,
requiresPassword: null,
remember: false,
rememberMeEnabled: false,
clients: null,
clientsPersist: {},
@@ -239,6 +241,7 @@ new Vue({
this.authenticating = true;
this.api.createSession({
password: this.password,
remember: this.remember,
})
.then(async () => {
const session = await this.api.getSession();
@@ -362,6 +365,11 @@ new Vue({
alert(err.message || err.toString());
});
this.api.getRememberMeEnabled()
.then((rememberMeEnabled) => {
this.rememberMeEnabled = rememberMeEnabled;
});
setInterval(() => {
this.refresh({
updateCharts: this.updateCharts,

View File

@@ -34,6 +34,8 @@ const messages = { // eslint-disable-line no-unused-vars
backup: 'Backup',
titleRestoreConfig: 'Restore your configuration',
titleBackupConfig: 'Backup your configuration',
rememberMe: 'Remember me',
titleRememberMe: 'Stay logged after closing the browser',
},
ua: {
name: 'Ім`я',