feat: add SSO workspace, named shares and Debian release tooling
This commit is contained in:
1 parent
833d908884
commit
87bc33e675
106 files changed
+4160
-5637
No files matched your search
@@ -17,7 +17,7 @@ const { locale } = useI18n();
|
||||
const userTheme = ref<UserTheme>(getTheme() || getMediaPreference());
|
||||
|
||||
onMounted(() => {
|
||||
setTheme(userTheme.value);
|
||||
setTheme(userTheme.value, false);
|
||||
setHtmlLocale(locale.value);
|
||||
// this might be null during HMR
|
||||
const loading = document.getElementById("loading");
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
import { baseURL } from "@/utils/constants";
|
||||
import { upload as postTus, useTus } from "./tus";
|
||||
@@ -139,7 +138,6 @@ async function postResources(
|
||||
bufferContent = await new Response(content).arrayBuffer();
|
||||
}
|
||||
|
||||
const authStore = useAuthStore();
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open(
|
||||
@@ -147,7 +145,7 @@ async function postResources(
|
||||
`${baseURL}/api/resources${url}?override=${overwrite}`,
|
||||
true
|
||||
);
|
||||
request.setRequestHeader("X-Auth", authStore.jwt);
|
||||
request.setRequestHeader("X-FB-Request", "1");
|
||||
|
||||
if (typeof onupload === "function") {
|
||||
request.upload.onprogress = onupload;
|
||||
|
||||
@@ -19,7 +19,8 @@ export async function create(
|
||||
url: string,
|
||||
password = "",
|
||||
expires = "",
|
||||
unit = "hours"
|
||||
unit = "hours",
|
||||
key = ""
|
||||
) {
|
||||
url = removePrefix(url);
|
||||
url = `/api/share${url}`;
|
||||
@@ -27,8 +28,9 @@ export async function create(
|
||||
url += `?expires=${expires}&unit=${unit}`;
|
||||
}
|
||||
let body = "{}";
|
||||
if (password != "" || expires !== "" || unit !== "hours") {
|
||||
if (password != "" || expires !== "" || unit !== "hours" || key !== "") {
|
||||
body = JSON.stringify({
|
||||
key,
|
||||
password: password,
|
||||
expires: expires.toString(), // backend expects string not number
|
||||
unit: unit,
|
||||
@@ -41,5 +43,5 @@ export async function create(
|
||||
}
|
||||
|
||||
export function getShareURL(share: Share) {
|
||||
return createURL("share/" + share.hash, {});
|
||||
return createURL("s/" + share.hash, {});
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import * as tus from "tus-js-client";
|
||||
import { baseURL, tusEndpoint, tusSettings, origin } from "@/utils/constants";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { removePrefix } from "@/api/utils";
|
||||
|
||||
const RETRY_BASE_DELAY = 1000;
|
||||
@@ -21,8 +20,6 @@ export async function upload(
|
||||
filePath = removePrefix(filePath);
|
||||
const resourcePath = `${tusEndpoint}${filePath}?override=${overwrite}`;
|
||||
|
||||
const authStore = useAuthStore();
|
||||
|
||||
// Exit early because of typescript, tus content can't be a string
|
||||
if (content === "") {
|
||||
return false;
|
||||
@@ -35,7 +32,7 @@ export async function upload(
|
||||
parallelUploads: 1,
|
||||
storeFingerprintForResuming: false,
|
||||
headers: {
|
||||
"X-Auth": authStore.jwt,
|
||||
"X-FB-Request": "1",
|
||||
},
|
||||
onShouldRetry: function (err) {
|
||||
const status = err.originalResponse
|
||||
@@ -43,7 +40,7 @@ export async function upload(
|
||||
: 0;
|
||||
|
||||
// Do not retry for file conflict.
|
||||
if (status === 409) {
|
||||
if (status === 409 || status === 401 || status === 403) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { renew, logout } from "@/utils/auth";
|
||||
import { startLogin } from "@/utils/auth";
|
||||
import { baseURL } from "@/utils/constants";
|
||||
import { encodePath } from "@/utils/url";
|
||||
|
||||
@@ -29,7 +29,7 @@ export async function fetchURL(
|
||||
try {
|
||||
res = await fetch(`${baseURL}${url}`, {
|
||||
headers: {
|
||||
"X-Auth": authStore.jwt,
|
||||
"X-FB-Request": "1",
|
||||
...headers,
|
||||
},
|
||||
...rest,
|
||||
@@ -42,10 +42,6 @@ export async function fetchURL(
|
||||
throw new StatusError("000 No connection", 0);
|
||||
}
|
||||
|
||||
if (auth && res.headers.get("X-Renew-Token") === "true") {
|
||||
await renew(authStore.jwt);
|
||||
}
|
||||
|
||||
if (res.status < 200 || res.status > 299) {
|
||||
const body = await res.text();
|
||||
const error = new StatusError(
|
||||
@@ -54,7 +50,8 @@ export async function fetchURL(
|
||||
);
|
||||
|
||||
if (auth && res.status == 401) {
|
||||
logout();
|
||||
authStore.clearUser();
|
||||
startLogin();
|
||||
}
|
||||
|
||||
throw error;
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
<template>
|
||||
<header>
|
||||
<img v-if="showLogo" :src="logoURL" alt="File Browser" />
|
||||
<router-link
|
||||
v-if="showLogo"
|
||||
to="/files/"
|
||||
class="workspace-brand"
|
||||
:aria-label="name"
|
||||
>
|
||||
<i class="material-icons" aria-hidden="true">folder_open</i
|
||||
><span>{{ name }}</span>
|
||||
</router-link>
|
||||
<Action
|
||||
v-if="showMenu"
|
||||
class="menu-button"
|
||||
@@ -18,6 +26,11 @@
|
||||
<slot name="actions" />
|
||||
</div>
|
||||
|
||||
<Action
|
||||
icon="contrast"
|
||||
:label="t('sso.toggleTheme')"
|
||||
@action="toggleTheme"
|
||||
/>
|
||||
<Action
|
||||
v-if="ifActionsSlot"
|
||||
id="more"
|
||||
@@ -37,7 +50,8 @@
|
||||
<script setup lang="ts">
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
|
||||
import { logoURL } from "@/utils/constants";
|
||||
import { name } from "@/utils/constants";
|
||||
import { toggleTheme } from "@/utils/theme";
|
||||
|
||||
import Action from "@/components/header/Action.vue";
|
||||
import { computed, useSlots } from "vue";
|
||||
|
||||
@@ -7,28 +7,34 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { computed, defineAsyncComponent } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
|
||||
import BaseModal from "./BaseModal.vue";
|
||||
import Help from "./Help.vue";
|
||||
import Info from "./Info.vue";
|
||||
import Delete from "./Delete.vue";
|
||||
import DeleteUser from "./DeleteUser.vue";
|
||||
import Download from "./Download.vue";
|
||||
import Rename from "./Rename.vue";
|
||||
import Move from "./Move.vue";
|
||||
import Copy from "./Copy.vue";
|
||||
import NewFile from "./NewFile.vue";
|
||||
import NewDir from "./NewDir.vue";
|
||||
import Replace from "./Replace.vue";
|
||||
import Share from "./Share.vue";
|
||||
import ShareDelete from "./ShareDelete.vue";
|
||||
import Upload from "./Upload.vue";
|
||||
import DiscardEditorChanges from "./DiscardEditorChanges.vue";
|
||||
import ResolveConflict from "./ResolveConflict.vue";
|
||||
import CurrentPassword from "./CurrentPassword.vue";
|
||||
const Help = defineAsyncComponent(() => import("./Help.vue"));
|
||||
const Info = defineAsyncComponent(() => import("./Info.vue"));
|
||||
const Delete = defineAsyncComponent(() => import("./Delete.vue"));
|
||||
const DeleteUser = defineAsyncComponent(() => import("./DeleteUser.vue"));
|
||||
const Download = defineAsyncComponent(() => import("./Download.vue"));
|
||||
const Rename = defineAsyncComponent(() => import("./Rename.vue"));
|
||||
const Move = defineAsyncComponent(() => import("./Move.vue"));
|
||||
const Copy = defineAsyncComponent(() => import("./Copy.vue"));
|
||||
const NewFile = defineAsyncComponent(() => import("./NewFile.vue"));
|
||||
const NewDir = defineAsyncComponent(() => import("./NewDir.vue"));
|
||||
const Replace = defineAsyncComponent(() => import("./Replace.vue"));
|
||||
const Share = defineAsyncComponent(() => import("./Share.vue"));
|
||||
const ShareDelete = defineAsyncComponent(() => import("./ShareDelete.vue"));
|
||||
const Upload = defineAsyncComponent(() => import("./Upload.vue"));
|
||||
const DiscardEditorChanges = defineAsyncComponent(
|
||||
() => import("./DiscardEditorChanges.vue")
|
||||
);
|
||||
const ResolveConflict = defineAsyncComponent(
|
||||
() => import("./ResolveConflict.vue")
|
||||
);
|
||||
const CurrentPassword = defineAsyncComponent(
|
||||
() => import("./CurrentPassword.vue")
|
||||
);
|
||||
|
||||
const layoutStore = useLayoutStore();
|
||||
|
||||
|
||||
@@ -83,6 +83,20 @@
|
||||
|
||||
<template v-else>
|
||||
<div class="card-content">
|
||||
<label for="share-key">{{ $t("sso.shortName") }}</label>
|
||||
<div class="share-key-field">
|
||||
<span>/s/</span
|
||||
><input
|
||||
id="share-key"
|
||||
class="input"
|
||||
v-model.trim="shortKey"
|
||||
maxlength="64"
|
||||
pattern="[A-Za-z0-9][A-Za-z0-9_-]{1,63}"
|
||||
:placeholder="$t('sso.randomName')"
|
||||
autocomplete="off"
|
||||
/>
|
||||
</div>
|
||||
<p class="field-hint">{{ $t("sso.shortHint") }}</p>
|
||||
<p>{{ $t("settings.shareDuration") }}</p>
|
||||
<div class="input-group input">
|
||||
<vue-number-input
|
||||
@@ -130,6 +144,7 @@
|
||||
id="focus-prompt"
|
||||
class="button button--flat button--blue"
|
||||
@click="submit"
|
||||
:disabled="submitting"
|
||||
:aria-label="$t('buttons.share')"
|
||||
:title="$t('buttons.share')"
|
||||
tabindex="4"
|
||||
@@ -158,6 +173,8 @@ export default {
|
||||
links: [],
|
||||
clip: null,
|
||||
password: "",
|
||||
shortKey: "",
|
||||
submitting: false,
|
||||
listing: true,
|
||||
};
|
||||
},
|
||||
@@ -222,16 +239,22 @@ export default {
|
||||
try {
|
||||
let res = null;
|
||||
|
||||
if (!this.time) {
|
||||
res = await api.share.create(this.url, this.password);
|
||||
} else {
|
||||
res = await api.share.create(
|
||||
this.url,
|
||||
this.password,
|
||||
this.time,
|
||||
this.unit
|
||||
);
|
||||
if (this.submitting) return;
|
||||
if (
|
||||
this.shortKey &&
|
||||
!/^[A-Za-z0-9][A-Za-z0-9_-]{1,63}$/.test(this.shortKey)
|
||||
) {
|
||||
this.$showError(new Error(this.$t("sso.shortHint")));
|
||||
return;
|
||||
}
|
||||
this.submitting = true;
|
||||
res = await api.share.create(
|
||||
this.url,
|
||||
this.password,
|
||||
this.time ? this.time : "",
|
||||
this.unit,
|
||||
this.shortKey
|
||||
);
|
||||
|
||||
this.links.push(res);
|
||||
this.sort();
|
||||
@@ -239,10 +262,13 @@ export default {
|
||||
this.time = 0;
|
||||
this.unit = "hours";
|
||||
this.password = "";
|
||||
this.shortKey = "";
|
||||
|
||||
this.listing = true;
|
||||
} catch (e) {
|
||||
this.$showError(e);
|
||||
} finally {
|
||||
this.submitting = false;
|
||||
}
|
||||
},
|
||||
deleteLink: async function (event, link) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { type SelectHTMLAttributes } from "vue";
|
||||
import "ace-builds";
|
||||
import { themes } from "ace-builds/src-noconflict/ext-themelist";
|
||||
|
||||
defineProps<{
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
<h3>{{ $t("settings.permissions") }}</h3>
|
||||
<p class="small">{{ $t("settings.permissionsHelp") }}</p>
|
||||
|
||||
<p>
|
||||
<input type="checkbox" v-model="admin" />
|
||||
{{ $t("settings.administrator") }}
|
||||
</p>
|
||||
<p class="field-hint">{{ $t("sso.managed") }}</p>
|
||||
|
||||
<p>
|
||||
<input type="checkbox" :disabled="admin" v-model="perm.create" />
|
||||
|
||||
@@ -1,26 +1,5 @@
|
||||
<template>
|
||||
<div>
|
||||
<p v-if="!isDefault && props.user !== null">
|
||||
<label for="username">{{ t("settings.username") }}</label>
|
||||
<input
|
||||
class="input input--block"
|
||||
type="text"
|
||||
v-model="user.username"
|
||||
id="username"
|
||||
/>
|
||||
</p>
|
||||
|
||||
<p v-if="!isDefault">
|
||||
<label for="password">{{ t("settings.password") }}</label>
|
||||
<input
|
||||
class="input input--block"
|
||||
type="password"
|
||||
:placeholder="passwordPlaceholder"
|
||||
v-model="user.password"
|
||||
id="password"
|
||||
/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="scope">{{ t("settings.scope") }}</label>
|
||||
<input
|
||||
@@ -46,15 +25,6 @@
|
||||
></languages>
|
||||
</p>
|
||||
|
||||
<p v-if="!isDefault && user.perm">
|
||||
<input
|
||||
type="checkbox"
|
||||
:disabled="user.perm.admin"
|
||||
v-model="user.lockPassword"
|
||||
/>
|
||||
{{ t("settings.lockPassword") }}
|
||||
</p>
|
||||
|
||||
<permissions v-model:perm="user.perm" />
|
||||
<commands v-if="enableExec" v-model:commands="user.commands" />
|
||||
|
||||
@@ -94,9 +64,6 @@ onMounted(() => {
|
||||
}
|
||||
});
|
||||
|
||||
const passwordPlaceholder = computed(() =>
|
||||
props.isNew ? "" : t("settings.avoidChanges")
|
||||
);
|
||||
const scopePlaceholder = computed(() =>
|
||||
createUserDirData.value ? t("settings.userScopeGenerationPlaceholder") : ""
|
||||
);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
@import "./epubReader.css";
|
||||
@import "./mdPreview.css";
|
||||
@import "./context-menu.css";
|
||||
@import "./workspace.css";
|
||||
|
||||
/* For testing only
|
||||
:focus {
|
||||
|
||||
@@ -0,0 +1,400 @@
|
||||
/* Lightweight workspace: system fonts, solid surfaces, no blur or filter layers. */
|
||||
:root {
|
||||
--blue: #3563e9;
|
||||
--dark-blue: #244bc2;
|
||||
--background: #f4f6fa;
|
||||
--surfacePrimary: #fff;
|
||||
--surfaceSecondary: #edf1f8;
|
||||
--textPrimary: #64718a;
|
||||
--textSecondary: #202b40;
|
||||
--borderPrimary: #e2e7f0;
|
||||
--borderSecondary: #c9d2e3;
|
||||
--divider: #e9edf4;
|
||||
--hover: #edf2ff;
|
||||
--action: #53617a;
|
||||
--iconPrimary: #5375da;
|
||||
--workspace-radius: 12px;
|
||||
}
|
||||
:root.dark {
|
||||
--blue: #88a7ff;
|
||||
--dark-blue: #6c92f2;
|
||||
--background: #10151f;
|
||||
--surfacePrimary: #19212f;
|
||||
--surfaceSecondary: #242f42;
|
||||
--textPrimary: #a0adc3;
|
||||
--textSecondary: #e7edf8;
|
||||
--borderPrimary: #2a3549;
|
||||
--borderSecondary: #44516a;
|
||||
--divider: #2a3549;
|
||||
--hover: #273650;
|
||||
--action: #b1bed5;
|
||||
--iconPrimary: #9bb8ff;
|
||||
}
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
button,
|
||||
input,
|
||||
select,
|
||||
textarea {
|
||||
font: inherit;
|
||||
}
|
||||
button,
|
||||
a,
|
||||
input,
|
||||
select,
|
||||
textarea {
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
:focus-visible {
|
||||
outline: 2px solid var(--blue);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
header {
|
||||
box-shadow: none;
|
||||
padding-inline: 18px;
|
||||
border-bottom: 1px solid var(--borderPrimary);
|
||||
}
|
||||
header img {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
}
|
||||
.workspace-brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-width: 13em;
|
||||
font-size: 16px;
|
||||
font-weight: 650;
|
||||
letter-spacing: -0.4px;
|
||||
}
|
||||
.workspace-brand i {
|
||||
padding: 7px;
|
||||
border-radius: 9px;
|
||||
background: var(--hover);
|
||||
color: var(--blue);
|
||||
font-size: 22px;
|
||||
}
|
||||
.workspace-overview {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin: 8px 0 24px;
|
||||
}
|
||||
.workspace-overview h1 {
|
||||
font-size: 28px;
|
||||
line-height: 1.2;
|
||||
margin: 6px 0 0;
|
||||
letter-spacing: -0.8px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.workspace-count {
|
||||
border: 1px solid var(--borderPrimary);
|
||||
border-radius: 20px;
|
||||
padding: 5px 12px;
|
||||
color: var(--textPrimary);
|
||||
font-size: 12px;
|
||||
}
|
||||
.share__box {
|
||||
border: 1px solid var(--borderPrimary);
|
||||
border-radius: 12px;
|
||||
box-shadow: none;
|
||||
}
|
||||
header .action {
|
||||
border-radius: 9px;
|
||||
}
|
||||
header .action:hover,
|
||||
nav .action:hover {
|
||||
background: var(--hover);
|
||||
}
|
||||
nav {
|
||||
padding: 22px 12px 12px;
|
||||
border-inline-end: 1px solid var(--borderPrimary);
|
||||
background: var(--surfacePrimary);
|
||||
}
|
||||
nav .action {
|
||||
border-radius: 9px;
|
||||
padding: 11px 14px;
|
||||
font-size: 14px;
|
||||
margin-block: 3px;
|
||||
text-align: start;
|
||||
}
|
||||
nav .action i {
|
||||
font-size: 21px;
|
||||
margin-inline-end: 10px;
|
||||
}
|
||||
nav > div {
|
||||
border-top: 0;
|
||||
margin-top: 18px;
|
||||
}
|
||||
nav > .action:first-of-type {
|
||||
background: var(--surfaceSecondary);
|
||||
font-weight: 600;
|
||||
}
|
||||
nav #logout {
|
||||
margin-top: 26px;
|
||||
}
|
||||
nav .credits {
|
||||
font-size: 11px;
|
||||
color: var(--textPrimary);
|
||||
}
|
||||
main {
|
||||
margin: 0 24px 24px auto;
|
||||
width: calc(100% - 19em);
|
||||
}
|
||||
.breadcrumbs {
|
||||
height: 64px;
|
||||
font-size: 13px;
|
||||
border: 0;
|
||||
}
|
||||
.breadcrumbs a {
|
||||
border-radius: 6px;
|
||||
}
|
||||
#listing.list {
|
||||
border: 1px solid var(--borderPrimary);
|
||||
border-radius: var(--workspace-radius);
|
||||
overflow: hidden;
|
||||
background: var(--surfacePrimary);
|
||||
}
|
||||
main #listing.list {
|
||||
min-height: 0;
|
||||
}
|
||||
#listing.list .item {
|
||||
padding: 11px 16px;
|
||||
min-height: 58px;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--divider);
|
||||
}
|
||||
#listing.list .item:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
#listing .item .name {
|
||||
color: var(--textSecondary);
|
||||
font-weight: 500;
|
||||
}
|
||||
#listing .item .size,
|
||||
#listing .item .modified {
|
||||
font-size: 12px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
#listing .item[aria-selected="true"] .name {
|
||||
color: inherit;
|
||||
}
|
||||
#listing .item:hover {
|
||||
background: var(--hover);
|
||||
}
|
||||
#listing.mosaic .item {
|
||||
border: 1px solid var(--borderPrimary);
|
||||
border-radius: var(--workspace-radius);
|
||||
padding: 16px;
|
||||
box-shadow: none;
|
||||
}
|
||||
#listing.mosaic .item:hover {
|
||||
box-shadow: none !important;
|
||||
border-color: var(--blue);
|
||||
}
|
||||
#listing.mosaic .item i {
|
||||
font-size: 42px;
|
||||
}
|
||||
@supports (content-visibility: auto) {
|
||||
#listing.list .item {
|
||||
content-visibility: auto;
|
||||
contain-intrinsic-size: auto 58px;
|
||||
}
|
||||
}
|
||||
.card {
|
||||
border: 1px solid var(--borderPrimary);
|
||||
border-radius: var(--workspace-radius);
|
||||
box-shadow: none;
|
||||
overflow: hidden;
|
||||
}
|
||||
.card-title {
|
||||
padding: 20px 24px;
|
||||
border-bottom: 1px solid var(--divider);
|
||||
}
|
||||
.card-title h2 {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.3px;
|
||||
}
|
||||
.card-content {
|
||||
padding: 20px 24px;
|
||||
}
|
||||
.card-action {
|
||||
border-top: 1px solid var(--divider);
|
||||
padding: 12px 20px;
|
||||
}
|
||||
.card.floating {
|
||||
box-shadow: 0 16px 56px #0003;
|
||||
}
|
||||
.input,
|
||||
input[type="text"],
|
||||
input[type="password"],
|
||||
select {
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--borderSecondary);
|
||||
background: var(--surfacePrimary);
|
||||
color: var(--textSecondary);
|
||||
}
|
||||
.input:focus,
|
||||
input:focus,
|
||||
select:focus {
|
||||
border-color: var(--blue);
|
||||
}
|
||||
.button {
|
||||
border-radius: 8px;
|
||||
text-transform: none;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
.button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: wait;
|
||||
}
|
||||
.share-key-field {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: 8px;
|
||||
border: 1px solid var(--borderSecondary);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.share-key-field span {
|
||||
padding: 10px 12px;
|
||||
color: var(--textPrimary);
|
||||
background: var(--surfaceSecondary);
|
||||
}
|
||||
.share-key-field .input {
|
||||
border: 0;
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
}
|
||||
.field-hint {
|
||||
font-size: 12px;
|
||||
color: var(--textPrimary);
|
||||
line-height: 1.5;
|
||||
}
|
||||
.sso-welcome {
|
||||
margin: 8vh auto 40px;
|
||||
padding: 42px 32px;
|
||||
width: calc(100% - 32px);
|
||||
max-width: 440px;
|
||||
text-align: center;
|
||||
background: var(--surfacePrimary);
|
||||
border: 1px solid var(--borderPrimary);
|
||||
border-radius: 20px;
|
||||
}
|
||||
.sso-symbol {
|
||||
display: flex;
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
margin: 0 auto 24px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 18px;
|
||||
background: var(--hover);
|
||||
color: var(--blue);
|
||||
}
|
||||
.sso-symbol i {
|
||||
font-size: 34px;
|
||||
}
|
||||
.eyebrow {
|
||||
color: var(--textPrimary);
|
||||
font-size: 10px;
|
||||
letter-spacing: 2px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.sso-welcome h1 {
|
||||
font-size: 32px;
|
||||
margin: 8px 0 12px;
|
||||
letter-spacing: -1px;
|
||||
color: var(--textSecondary);
|
||||
}
|
||||
.sso-welcome p {
|
||||
color: var(--textPrimary);
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
.sso-signin {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 13px;
|
||||
background: #3563e9;
|
||||
color: white;
|
||||
border: 0;
|
||||
}
|
||||
.sso-welcome small {
|
||||
display: block;
|
||||
margin-top: 24px;
|
||||
font-size: 11px;
|
||||
color: var(--textPrimary);
|
||||
}
|
||||
@media (min-width: 737px) and (max-width: 1024px) {
|
||||
nav {
|
||||
width: 13em;
|
||||
}
|
||||
main {
|
||||
width: calc(100% - 16em);
|
||||
margin-inline-end: 18px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 736px) {
|
||||
header {
|
||||
padding-inline: 8px;
|
||||
}
|
||||
header .menu-button {
|
||||
order: -1;
|
||||
}
|
||||
.workspace-brand {
|
||||
min-width: 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
.workspace-brand i {
|
||||
display: none;
|
||||
}
|
||||
.workspace-overview {
|
||||
margin: 6px 0 18px;
|
||||
}
|
||||
.workspace-overview h1 {
|
||||
font-size: 24px;
|
||||
}
|
||||
main {
|
||||
width: calc(100% - 24px);
|
||||
margin: 0 12px 16px;
|
||||
}
|
||||
nav {
|
||||
padding: 16px 12px;
|
||||
}
|
||||
.breadcrumbs {
|
||||
height: 52px;
|
||||
}
|
||||
#listing.list .item {
|
||||
padding: 10px 12px;
|
||||
min-height: 56px;
|
||||
}
|
||||
#listing.mosaic .item {
|
||||
padding: 12px;
|
||||
}
|
||||
.card.floating {
|
||||
width: calc(100% - 24px);
|
||||
max-height: calc(100vh - 32px);
|
||||
overflow: auto;
|
||||
}
|
||||
.sso-welcome {
|
||||
margin: 4vh auto;
|
||||
padding: 32px 24px;
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
animation-duration: 0.01ms !important;
|
||||
transition-duration: 0.01ms !important;
|
||||
scroll-behavior: auto !important;
|
||||
}
|
||||
}
|
||||
@@ -308,5 +308,16 @@
|
||||
"minutes": "Minutes",
|
||||
"seconds": "Seconds",
|
||||
"unit": "Time Unit"
|
||||
},
|
||||
"sso": {
|
||||
"description": "Your files. One secure workspace.",
|
||||
"signIn": "Continue with SSO",
|
||||
"managed": "Your account and access are managed by AniDev SSO",
|
||||
"shortName": "Short link name",
|
||||
"randomName": "Generate automatically",
|
||||
"shortHint": "2–64 letters, digits, underscores or hyphens. Public names are discoverable; protect sensitive shares with a password.",
|
||||
"workspace": "Your workspace",
|
||||
"toggleTheme": "Switch theme",
|
||||
"itemsCount": "{count} items"
|
||||
}
|
||||
}
|
||||
+58
-36
@@ -1,42 +1,50 @@
|
||||
import dayjs from "dayjs";
|
||||
import { createI18n } from "vue-i18n";
|
||||
|
||||
import("dayjs/locale/ar");
|
||||
import("dayjs/locale/bg");
|
||||
import("dayjs/locale/ca");
|
||||
import("dayjs/locale/cs");
|
||||
import("dayjs/locale/de");
|
||||
import("dayjs/locale/el");
|
||||
import("dayjs/locale/en");
|
||||
import("dayjs/locale/es");
|
||||
import("dayjs/locale/fr");
|
||||
import("dayjs/locale/he");
|
||||
import("dayjs/locale/hr");
|
||||
import("dayjs/locale/hu");
|
||||
import("dayjs/locale/is");
|
||||
import("dayjs/locale/it");
|
||||
import("dayjs/locale/ja");
|
||||
import("dayjs/locale/ko");
|
||||
import("dayjs/locale/lv");
|
||||
import("dayjs/locale/nb");
|
||||
import("dayjs/locale/nl");
|
||||
import("dayjs/locale/nl-be");
|
||||
import("dayjs/locale/pl");
|
||||
import("dayjs/locale/pt-br");
|
||||
import("dayjs/locale/pt");
|
||||
import("dayjs/locale/ro");
|
||||
import("dayjs/locale/ru");
|
||||
import("dayjs/locale/sk");
|
||||
import("dayjs/locale/sv");
|
||||
import("dayjs/locale/tr");
|
||||
import("dayjs/locale/uk");
|
||||
import("dayjs/locale/vi");
|
||||
import("dayjs/locale/zh-cn");
|
||||
import("dayjs/locale/zh-tw");
|
||||
|
||||
// All i18n resources specified in the plugin `include` option can be loaded
|
||||
// at once using the import syntax
|
||||
import messages from "@intlify/unplugin-vue-i18n/messages";
|
||||
import en from "./en.json";
|
||||
import ru from "./ru.json";
|
||||
const messages = { en, ru };
|
||||
const loaders = import.meta.glob<{ default: typeof en }>([
|
||||
"./*.json",
|
||||
"!./en.json",
|
||||
"!./ru.json",
|
||||
]);
|
||||
const dateLoaders: Record<string, () => Promise<unknown>> = {
|
||||
ar: () => import("dayjs/locale/ar"),
|
||||
bg: () => import("dayjs/locale/bg"),
|
||||
ca: () => import("dayjs/locale/ca"),
|
||||
cs: () => import("dayjs/locale/cs"),
|
||||
de: () => import("dayjs/locale/de"),
|
||||
el: () => import("dayjs/locale/el"),
|
||||
en: () => import("dayjs/locale/en"),
|
||||
es: () => import("dayjs/locale/es"),
|
||||
fr: () => import("dayjs/locale/fr"),
|
||||
he: () => import("dayjs/locale/he"),
|
||||
hr: () => import("dayjs/locale/hr"),
|
||||
hu: () => import("dayjs/locale/hu"),
|
||||
is: () => import("dayjs/locale/is"),
|
||||
it: () => import("dayjs/locale/it"),
|
||||
ja: () => import("dayjs/locale/ja"),
|
||||
ko: () => import("dayjs/locale/ko"),
|
||||
lv: () => import("dayjs/locale/lv"),
|
||||
nb: () => import("dayjs/locale/nb"),
|
||||
nl: () => import("dayjs/locale/nl"),
|
||||
"nl-be": () => import("dayjs/locale/nl-be"),
|
||||
pl: () => import("dayjs/locale/pl"),
|
||||
"pt-br": () => import("dayjs/locale/pt-br"),
|
||||
pt: () => import("dayjs/locale/pt"),
|
||||
ro: () => import("dayjs/locale/ro"),
|
||||
ru: () => import("dayjs/locale/ru"),
|
||||
sk: () => import("dayjs/locale/sk"),
|
||||
sv: () => import("dayjs/locale/sv"),
|
||||
tr: () => import("dayjs/locale/tr"),
|
||||
uk: () => import("dayjs/locale/uk"),
|
||||
vi: () => import("dayjs/locale/vi"),
|
||||
"zh-cn": () => import("dayjs/locale/zh-cn"),
|
||||
"zh-tw": () => import("dayjs/locale/zh-tw"),
|
||||
};
|
||||
|
||||
export function detectLocale() {
|
||||
// locale is an RFC 5646 language tag
|
||||
@@ -177,8 +185,21 @@ export const isRtl = (locale?: string) => {
|
||||
return rtlLanguages.includes(locale || i18n.global.locale.value);
|
||||
};
|
||||
|
||||
export function setLocale(locale: string) {
|
||||
dayjs.locale(locale);
|
||||
let localeGeneration = 0;
|
||||
export async function setLocale(locale: string) {
|
||||
const generation = ++localeGeneration;
|
||||
if (!(i18n.global.availableLocales as string[]).includes(locale)) {
|
||||
const loader = loaders["./" + locale + ".json"];
|
||||
if (loader) {
|
||||
const data = await loader();
|
||||
i18n.global.setLocaleMessage(locale, data.default);
|
||||
}
|
||||
}
|
||||
const dateLocale =
|
||||
locale === "pt" ? "pt-br" : locale === "pt-PT" ? "pt" : locale;
|
||||
if (dateLoaders[dateLocale]) await dateLoaders[dateLocale]();
|
||||
if (generation !== localeGeneration) return;
|
||||
dayjs.locale(dateLocale);
|
||||
// according to doc u only need .value if legacy: false but they lied
|
||||
// https://vue-i18n.intlify.dev/guide/essentials/scope.html#local-scope-1
|
||||
// @ts-expect-error incorrect type when legacy
|
||||
@@ -192,4 +213,5 @@ export function setHtmlLocale(locale: string) {
|
||||
else html.dir = "ltr";
|
||||
}
|
||||
|
||||
void setLocale(detectLocale());
|
||||
export default i18n;
|
||||
@@ -305,5 +305,16 @@
|
||||
"minutes": "Минуты",
|
||||
"seconds": "Секунды",
|
||||
"unit": "Единица времени"
|
||||
},
|
||||
"sso": {
|
||||
"description": "Ваши файлы. Одно удобное пространство.",
|
||||
"signIn": "Войти через SSO",
|
||||
"managed": "Учётная запись и доступ управляются в AniDev SSO",
|
||||
"shortName": "Короткое имя ссылки",
|
||||
"randomName": "Сгенерировать автоматически",
|
||||
"shortHint": "2–64 латинские буквы, цифры, дефис или подчёркивание. Для конфиденциальных файлов установите пароль ссылки.",
|
||||
"workspace": "Файловое пространство",
|
||||
"toggleTheme": "Переключить тему",
|
||||
"itemsCount": "Объектов: {count}"
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,17 @@ import Login from "@/views/Login.vue";
|
||||
import Layout from "@/views/Layout.vue";
|
||||
import Files from "@/views/Files.vue";
|
||||
import Share from "@/views/Share.vue";
|
||||
import Users from "@/views/settings/Users.vue";
|
||||
import User from "@/views/settings/User.vue";
|
||||
import Settings from "@/views/Settings.vue";
|
||||
import GlobalSettings from "@/views/settings/Global.vue";
|
||||
import ProfileSettings from "@/views/settings/Profile.vue";
|
||||
import Shares from "@/views/settings/Shares.vue";
|
||||
const Users = () => import("@/views/settings/Users.vue");
|
||||
const User = () => import("@/views/settings/User.vue");
|
||||
const Settings = () => import("@/views/Settings.vue");
|
||||
const GlobalSettings = () => import("@/views/settings/Global.vue");
|
||||
const ProfileSettings = () => import("@/views/settings/Profile.vue");
|
||||
const Shares = () => import("@/views/settings/Shares.vue");
|
||||
import Errors from "@/views/Errors.vue";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { baseURL, name } from "@/utils/constants";
|
||||
import i18n from "@/i18n";
|
||||
import { recaptcha, loginPage } from "@/utils/constants";
|
||||
import { login, validateLogin } from "@/utils/auth";
|
||||
import { validateLogin } from "@/utils/auth";
|
||||
|
||||
const titles = {
|
||||
Login: "sidebar.login",
|
||||
@@ -39,7 +38,8 @@ const routes = [
|
||||
component: Login,
|
||||
},
|
||||
{
|
||||
path: "/share",
|
||||
path: "/s",
|
||||
alias: "/share",
|
||||
component: Layout,
|
||||
children: [
|
||||
{
|
||||
@@ -154,25 +154,7 @@ const routes = [
|
||||
];
|
||||
|
||||
async function initAuth() {
|
||||
if (loginPage) {
|
||||
await validateLogin();
|
||||
} else {
|
||||
await login("", "", "");
|
||||
}
|
||||
|
||||
if (recaptcha) {
|
||||
await new Promise<void>((resolve) => {
|
||||
const check = () => {
|
||||
if (typeof window.grecaptcha === "undefined") {
|
||||
setTimeout(check, 100);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
|
||||
check();
|
||||
});
|
||||
}
|
||||
await validateLogin();
|
||||
}
|
||||
|
||||
const router = createRouter({
|
||||
@@ -181,9 +163,6 @@ const router = createRouter({
|
||||
});
|
||||
|
||||
router.beforeResolve(async (to, from) => {
|
||||
const title = i18n.global.t(titles[to.name as keyof typeof titles]);
|
||||
document.title = title + " - " + name;
|
||||
|
||||
const authStore = useAuthStore();
|
||||
|
||||
// this will only be null on first route
|
||||
@@ -195,6 +174,9 @@ router.beforeResolve(async (to, from) => {
|
||||
}
|
||||
}
|
||||
|
||||
const title = i18n.global.t(titles[to.name as keyof typeof titles]);
|
||||
document.title = title + " - " + name;
|
||||
|
||||
if (to.path.endsWith("/login") && authStore.isLoggedIn) {
|
||||
return { path: "/files/" };
|
||||
}
|
||||
|
||||
@@ -6,15 +6,12 @@ export const useAuthStore = defineStore("auth", {
|
||||
// convert to a function
|
||||
state: (): {
|
||||
user: IUser | null;
|
||||
jwt: string;
|
||||
logoutTimer: number | null;
|
||||
} => ({
|
||||
user: null,
|
||||
jwt: "",
|
||||
logoutTimer: null,
|
||||
}),
|
||||
getters: {
|
||||
// user and jwt getter removed, no longer needed
|
||||
isLoggedIn: (state) => state.user !== null,
|
||||
},
|
||||
actions: {
|
||||
|
||||
Vendored
+1
@@ -1,4 +1,5 @@
|
||||
interface IUser {
|
||||
displayName?: string;
|
||||
id: number;
|
||||
username: string;
|
||||
password: string;
|
||||
|
||||
+33
-133
@@ -1,141 +1,41 @@
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import router from "@/router";
|
||||
import type { JwtPayload } from "jwt-decode";
|
||||
import { jwtDecode } from "jwt-decode";
|
||||
import { authMethod, baseURL, noAuth, logoutPage } from "./constants";
|
||||
import { StatusError } from "@/api/utils";
|
||||
import { setSafeTimeout } from "@/api/utils";
|
||||
|
||||
export function parseToken(token: string) {
|
||||
// falsy or malformed jwt will throw InvalidTokenError
|
||||
const data = jwtDecode<JwtPayload & { user: IUser }>(token);
|
||||
|
||||
document.cookie = `auth=${token}; Path=/; SameSite=Strict;`;
|
||||
|
||||
localStorage.setItem("jwt", token);
|
||||
|
||||
const authStore = useAuthStore();
|
||||
authStore.jwt = token;
|
||||
authStore.setUser(data.user);
|
||||
|
||||
// proxy auth with custom logout subject to unknown external timeout
|
||||
if (logoutPage !== "/login" && authMethod === "proxy") {
|
||||
console.warn("idle timeout disabled with proxy auth and custom logout");
|
||||
return;
|
||||
}
|
||||
|
||||
if (authStore.logoutTimer) {
|
||||
clearTimeout(authStore.logoutTimer);
|
||||
}
|
||||
|
||||
const expiresAt = new Date(data.exp! * 1000);
|
||||
const timeout = expiresAt.getTime() - Date.now();
|
||||
authStore.setLogoutTimer(
|
||||
setSafeTimeout(() => {
|
||||
logout("inactivity");
|
||||
}, timeout)
|
||||
import { baseURL } from "./constants";
|
||||
import { setLocale, detectLocale } from "@/i18n";
|
||||
export function startLogin(
|
||||
target = window.location.pathname + window.location.search
|
||||
) {
|
||||
window.location.assign(
|
||||
baseURL + "/auth/login?return=" + encodeURIComponent(target)
|
||||
);
|
||||
}
|
||||
|
||||
export async function validateLogin() {
|
||||
try {
|
||||
if (localStorage.getItem("jwt")) {
|
||||
await renew(<string>localStorage.getItem("jwt"));
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Invalid JWT token in storage");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function login(
|
||||
username: string,
|
||||
password: string,
|
||||
recaptcha: string
|
||||
) {
|
||||
const data = { username, password, recaptcha };
|
||||
|
||||
const res = await fetch(`${baseURL}/api/login`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
let pending: Promise<void> | null = null;
|
||||
export function validateLogin(): Promise<void> {
|
||||
if (pending) return pending;
|
||||
pending = (async () => {
|
||||
const res = await fetch(baseURL + "/api/session", {
|
||||
credentials: "same-origin",
|
||||
cache: "no-store",
|
||||
});
|
||||
if (res.ok) {
|
||||
const user = await res.json();
|
||||
useAuthStore().setUser(user);
|
||||
await setLocale(user.locale || detectLocale());
|
||||
} else if (res.status === 401) useAuthStore().clearUser();
|
||||
else throw new Error("SSO session is temporarily unavailable");
|
||||
})().finally(() => {
|
||||
pending = null;
|
||||
});
|
||||
|
||||
const body = await res.text();
|
||||
|
||||
if (res.status === 200) {
|
||||
parseToken(body);
|
||||
} else {
|
||||
throw new StatusError(
|
||||
body || `${res.status} ${res.statusText}`,
|
||||
res.status
|
||||
);
|
||||
}
|
||||
return pending;
|
||||
}
|
||||
|
||||
export async function renew(jwt: string) {
|
||||
const res = await fetch(`${baseURL}/api/renew`, {
|
||||
export async function logout() {
|
||||
const res = await fetch(baseURL + "/auth/logout", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"X-Auth": jwt,
|
||||
},
|
||||
headers: { "X-FB-Request": "1" },
|
||||
credentials: "same-origin",
|
||||
});
|
||||
|
||||
const body = await res.text();
|
||||
|
||||
if (res.status === 200) {
|
||||
parseToken(body);
|
||||
} else {
|
||||
throw new StatusError(
|
||||
body || `${res.status} ${res.statusText}`,
|
||||
res.status
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function signup(username: string, password: string) {
|
||||
const data = { username, password };
|
||||
|
||||
const res = await fetch(`${baseURL}/api/signup`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
if (res.status !== 200) {
|
||||
const body = await res.text();
|
||||
throw new StatusError(
|
||||
body || `${res.status} ${res.statusText}`,
|
||||
res.status
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function logout(reason?: string) {
|
||||
document.cookie = "auth=; Max-Age=0; Path=/; SameSite=Strict;";
|
||||
|
||||
const authStore = useAuthStore();
|
||||
authStore.clearUser();
|
||||
|
||||
localStorage.setItem("jwt", "");
|
||||
if (noAuth) {
|
||||
window.location.reload();
|
||||
} else if (logoutPage !== "/login") {
|
||||
document.location.href = `${logoutPage}`;
|
||||
} else {
|
||||
if (typeof reason === "string" && reason.trim() !== "") {
|
||||
router.push({
|
||||
path: "/login",
|
||||
query: { "logout-reason": reason },
|
||||
});
|
||||
} else {
|
||||
router.push({
|
||||
path: "/login",
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!res.ok) throw new Error("Sign out failed. Please try again.");
|
||||
useAuthStore().clearUser();
|
||||
localStorage.removeItem("jwt");
|
||||
document.cookie = "auth=; Max-Age=0; Path=/; SameSite=Strict";
|
||||
window.location.assign(baseURL + "/login?logged-out=1");
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import "ace-builds";
|
||||
import { themesByName } from "ace-builds/src-noconflict/ext-themelist";
|
||||
import { getTheme } from "./theme";
|
||||
|
||||
export const getEditorTheme = (themeName: string) => {
|
||||
const key = themeName.replace(/^ace\/theme\//, "");
|
||||
if (themesByName[key] !== undefined) return `ace/theme/${key}`;
|
||||
return getTheme() === "dark" ? "ace/theme/twilight" : "ace/theme/chrome";
|
||||
};
|
||||
+14
-17
@@ -1,18 +1,29 @@
|
||||
import { theme } from "./constants";
|
||||
import "ace-builds";
|
||||
import { themesByName } from "ace-builds/src-noconflict/ext-themelist";
|
||||
|
||||
export const getTheme = (): UserTheme => {
|
||||
try {
|
||||
const saved = localStorage.getItem("fb.theme");
|
||||
if (saved === "light" || saved === "dark") return saved;
|
||||
} catch {
|
||||
/* Storage can be disabled by the browser. */
|
||||
}
|
||||
return (document.documentElement.className as UserTheme) || theme;
|
||||
};
|
||||
|
||||
export const setTheme = (theme: UserTheme) => {
|
||||
export const setTheme = (theme: UserTheme, persist = true) => {
|
||||
const html = document.documentElement;
|
||||
if (!theme) {
|
||||
html.className = getMediaPreference();
|
||||
} else {
|
||||
html.className = theme;
|
||||
}
|
||||
if (persist) {
|
||||
try {
|
||||
localStorage.setItem("fb.theme", html.className);
|
||||
} catch {
|
||||
/* Theme still applies without persistence. */
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const toggleTheme = (): void => {
|
||||
@@ -34,17 +45,3 @@ export const getMediaPreference = (): UserTheme => {
|
||||
return "light";
|
||||
}
|
||||
};
|
||||
|
||||
export const getEditorTheme = (themeName: string) => {
|
||||
if (!themeName.startsWith("ace/theme/")) {
|
||||
themeName = `ace/theme/${themeName}`;
|
||||
}
|
||||
const themeKey = themeName.replace("ace/theme/", "");
|
||||
if (themesByName[themeKey] !== undefined) {
|
||||
return themeName;
|
||||
} else if (getTheme() === "dark") {
|
||||
return "ace/theme/twilight";
|
||||
} else {
|
||||
return "ace/theme/chrome";
|
||||
}
|
||||
};
|
||||
@@ -7,6 +7,21 @@
|
||||
/>
|
||||
|
||||
<breadcrumbs base="/files" />
|
||||
<section v-if="fileStore.req?.isDir" class="workspace-overview">
|
||||
<div>
|
||||
<span class="eyebrow">{{ t("sso.workspace") }}</span>
|
||||
<h1>
|
||||
{{
|
||||
route.path.replace(/\/+$/, "") === "/files"
|
||||
? t("sidebar.myFiles")
|
||||
: fileStore.req.name
|
||||
}}
|
||||
</h1>
|
||||
</div>
|
||||
<span class="workspace-count">{{
|
||||
t("sso.itemsCount", { count: fileStore.req.items?.length || 0 })
|
||||
}}</span>
|
||||
</section>
|
||||
<errors v-if="error" :errorCode="error.status" />
|
||||
<component v-else-if="currentView" :is="currentView"></component>
|
||||
<div v-else>
|
||||
|
||||
+25
-132
@@ -1,139 +1,32 @@
|
||||
<template>
|
||||
<div id="login" :class="{ recaptcha: recaptcha }">
|
||||
<form @submit="submit">
|
||||
<img :src="logoURL" alt="File Browser" />
|
||||
<h1>{{ name }}</h1>
|
||||
<p v-if="reason != null" class="logout-message">
|
||||
{{ t(`login.logout_reasons.${reason}`) }}
|
||||
</p>
|
||||
<div v-if="error !== ''" class="wrong">{{ error }}</div>
|
||||
|
||||
<input
|
||||
autofocus
|
||||
class="input input--block"
|
||||
type="text"
|
||||
autocapitalize="off"
|
||||
v-model="username"
|
||||
:placeholder="t('login.username')"
|
||||
/>
|
||||
<input
|
||||
class="input input--block"
|
||||
type="password"
|
||||
v-model="password"
|
||||
:placeholder="t('login.password')"
|
||||
/>
|
||||
<input
|
||||
class="input input--block"
|
||||
v-if="createMode"
|
||||
type="password"
|
||||
v-model="passwordConfirm"
|
||||
:placeholder="t('login.passwordConfirm')"
|
||||
/>
|
||||
|
||||
<div v-if="recaptcha" id="recaptcha"></div>
|
||||
<input
|
||||
class="button button--block"
|
||||
type="submit"
|
||||
:value="createMode ? t('login.signup') : t('login.submit')"
|
||||
/>
|
||||
|
||||
<p @click="toggleMode" v-if="signup">
|
||||
{{ createMode ? t("login.loginInstead") : t("login.createAnAccount") }}
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<main class="sso-welcome">
|
||||
<div class="sso-symbol" aria-hidden="true">
|
||||
<i class="material-icons">folder_open</i>
|
||||
</div>
|
||||
<span class="eyebrow">FILE WORKSPACE</span>
|
||||
<h1>{{ name }}</h1>
|
||||
<p>{{ $t("sso.description") }}</p>
|
||||
<button class="button sso-signin" @click="signIn">
|
||||
<i class="material-icons">login</i>{{ $t("sso.signIn") }}
|
||||
</button>
|
||||
<small>{{ $t("sso.managed") }}</small>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { StatusError } from "@/api/utils";
|
||||
import * as auth from "@/utils/auth";
|
||||
import {
|
||||
name,
|
||||
logoURL,
|
||||
recaptcha,
|
||||
recaptchaKey,
|
||||
signup,
|
||||
} from "@/utils/constants";
|
||||
import { inject, onMounted, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
// Define refs
|
||||
const createMode = ref<boolean>(false);
|
||||
const error = ref<string>("");
|
||||
const username = ref<string>("");
|
||||
const password = ref<string>("");
|
||||
const passwordConfirm = ref<string>("");
|
||||
|
||||
import { onMounted } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { name, baseURL } from "@/utils/constants";
|
||||
import { startLogin } from "@/utils/auth";
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { t } = useI18n({});
|
||||
// Define functions
|
||||
const toggleMode = () => (createMode.value = !createMode.value);
|
||||
|
||||
const $showError = inject<IToastError>("$showError")!;
|
||||
|
||||
const reason = route.query["logout-reason"] ?? null;
|
||||
|
||||
const submit = async (event: Event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
const redirect = (route.query.redirect || "/files/") as string;
|
||||
|
||||
let captcha = "";
|
||||
if (recaptcha) {
|
||||
captcha = window.grecaptcha.getResponse();
|
||||
|
||||
if (captcha === "") {
|
||||
error.value = t("login.wrongCredentials");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (createMode.value) {
|
||||
if (password.value !== passwordConfirm.value) {
|
||||
error.value = t("login.passwordsDontMatch");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (createMode.value) {
|
||||
await auth.signup(username.value, password.value);
|
||||
}
|
||||
|
||||
await auth.login(username.value, password.value, captcha);
|
||||
router.push({ path: redirect });
|
||||
} catch (e: any) {
|
||||
// console.error(e);
|
||||
if (e instanceof StatusError) {
|
||||
if (e.status === 409) {
|
||||
error.value = t("login.usernameTaken");
|
||||
} else if (e.status === 403) {
|
||||
error.value = t("login.wrongCredentials");
|
||||
} else if (e.status === 400) {
|
||||
const match = e.message.match(/minimum length is (\d+)/);
|
||||
if (match) {
|
||||
error.value = t("login.passwordTooShort", { min: match[1] });
|
||||
} else {
|
||||
error.value = e.message;
|
||||
}
|
||||
} else {
|
||||
$showError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Run hooks
|
||||
function signIn() {
|
||||
startLogin(
|
||||
baseURL +
|
||||
(typeof route.query.redirect === "string"
|
||||
? route.query.redirect
|
||||
: "/files/")
|
||||
);
|
||||
}
|
||||
onMounted(() => {
|
||||
if (!recaptcha) return;
|
||||
|
||||
window.grecaptcha.ready(function () {
|
||||
window.grecaptcha.render("recaptcha", {
|
||||
sitekey: recaptchaKey,
|
||||
});
|
||||
});
|
||||
if (route.query.redirect && !route.query["logged-out"]) signIn();
|
||||
});
|
||||
</script>
|
||||
@@ -34,24 +34,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" v-if="user?.perm.admin">
|
||||
<div class="card-title">
|
||||
<h2>{{ t("settings.sunsetTitle") }}</h2>
|
||||
</div>
|
||||
|
||||
<div class="card-content">
|
||||
<p>{{ t("settings.sunsetBody") }}</p>
|
||||
<p>
|
||||
<a
|
||||
href="https://github.com/filebrowser/filebrowser#security"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>{{ t("settings.sunsetLink") }}</a
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="loading">
|
||||
<h2 class="message delayed">
|
||||
<div class="spinner">
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
/>
|
||||
</header-bar>
|
||||
|
||||
<breadcrumbs :base="'/share/' + hash" />
|
||||
<breadcrumbs :base="'/s/' + hash" />
|
||||
|
||||
<div v-if="layoutStore.loading">
|
||||
<h2 class="message delayed" style="padding-top: 3em !important">
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
import { files as api } from "@/api";
|
||||
import buttons from "@/utils/buttons";
|
||||
import url from "@/utils/url";
|
||||
import { baseURL } from "@/utils/constants";
|
||||
import ace, { Ace, version as ace_version } from "ace-builds";
|
||||
import "ace-builds/src-noconflict/ext-language_tools";
|
||||
import modelist from "ace-builds/src-noconflict/ext-modelist";
|
||||
@@ -92,7 +93,7 @@ import HeaderBar from "@/components/header/HeaderBar.vue";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useFileStore } from "@/stores/file";
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
import { getEditorTheme } from "@/utils/theme";
|
||||
import { getEditorTheme } from "@/utils/editor-theme";
|
||||
import { marked } from "marked";
|
||||
import markedKatex from "marked-katex-extension";
|
||||
import { inject, onBeforeUnmount, onMounted, ref, watchEffect } from "vue";
|
||||
@@ -172,10 +173,7 @@ onMounted(() => {
|
||||
}
|
||||
});
|
||||
|
||||
ace.config.set(
|
||||
"basePath",
|
||||
`https://cdn.jsdelivr.net/npm/ace-builds@${ace_version}/src-min-noconflict/`
|
||||
);
|
||||
ace.config.set("basePath", `${baseURL}/static/ace/${ace_version}/`);
|
||||
|
||||
if (!layoutStore.loading) {
|
||||
initEditor(fileContent);
|
||||
@@ -222,6 +220,7 @@ const initEditor = (fileContent: string) => {
|
||||
editor.value = ace.edit("editor", {
|
||||
value: fileContent,
|
||||
showPrintMargin: false,
|
||||
useWorker: false,
|
||||
readOnly: fileStore.req?.type === "textImmutable",
|
||||
theme: getEditorTheme(authStore.user?.aceEditorTheme ?? ""),
|
||||
mode: modelist.getModeForPath(fileStore.req!.name).mode,
|
||||
|
||||
@@ -205,7 +205,7 @@ import { useI18n } from "vue-i18n";
|
||||
// Prevents browser memory issues with large files
|
||||
const CSV_MAX_SIZE = 5 * 1024 * 1024;
|
||||
|
||||
const location = useStorage("book-progress", 0, undefined, {
|
||||
const location = useStorage<string | number>("book-progress", 0, undefined, {
|
||||
serializer: {
|
||||
read: (v) => JSON.parse(v),
|
||||
write: (v) => JSON.stringify(v),
|
||||
@@ -218,7 +218,7 @@ const size = useStorage("book-size", 120, undefined, {
|
||||
},
|
||||
});
|
||||
|
||||
const locationChange = (epubcifi: number) => {
|
||||
const locationChange = (epubcifi: string) => {
|
||||
location.value = epubcifi;
|
||||
};
|
||||
let rendition: Rendition | null = null;
|
||||
|
||||
@@ -8,11 +8,6 @@
|
||||
</div>
|
||||
|
||||
<div class="card-content">
|
||||
<p>
|
||||
<input type="checkbox" v-model="settings.signup" />
|
||||
{{ t("settings.allowSignup") }}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input type="checkbox" v-model="settings.createUserDir" />
|
||||
{{ t("settings.createUserDir") }}
|
||||
@@ -32,18 +27,6 @@
|
||||
/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="minimumPasswordLength">{{
|
||||
t("settings.minimumPasswordLength")
|
||||
}}</label>
|
||||
<vue-number-input
|
||||
controls
|
||||
v-model.number="settings.minimumPasswordLength"
|
||||
id="minimumPasswordLength"
|
||||
:min="1"
|
||||
/>
|
||||
</p>
|
||||
|
||||
<h3>{{ t("settings.rules") }}</h3>
|
||||
<p class="small">{{ t("settings.globalRules") }}</p>
|
||||
<rules v-model:rules="settings.rules" />
|
||||
|
||||
@@ -51,53 +51,6 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div v-if="!noAuth" class="column">
|
||||
<form
|
||||
class="card"
|
||||
v-if="!authStore.user?.lockPassword"
|
||||
@submit="updatePassword"
|
||||
>
|
||||
<div class="card-title">
|
||||
<h2>{{ t("settings.changePassword") }}</h2>
|
||||
</div>
|
||||
|
||||
<div class="card-content">
|
||||
<input
|
||||
:class="passwordClass"
|
||||
type="password"
|
||||
:placeholder="t('settings.newPassword')"
|
||||
v-model="password"
|
||||
name="password"
|
||||
/>
|
||||
<input
|
||||
:class="passwordClass"
|
||||
type="password"
|
||||
:placeholder="t('settings.newPasswordConfirm')"
|
||||
v-model="passwordConf"
|
||||
name="passwordConf"
|
||||
/>
|
||||
<input
|
||||
v-if="isCurrentPasswordRequired"
|
||||
:class="passwordClass"
|
||||
type="password"
|
||||
:placeholder="t('settings.currentPassword')"
|
||||
v-model="currentPassword"
|
||||
name="current_password"
|
||||
autocomplete="current-password"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="card-action">
|
||||
<input
|
||||
class="button button--flat"
|
||||
type="submit"
|
||||
name="submitPassword"
|
||||
:value="t('buttons.update')"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -107,9 +60,8 @@ import { useLayoutStore } from "@/stores/layout";
|
||||
import { users as api } from "@/api";
|
||||
import AceEditorTheme from "@/components/settings/AceEditorTheme.vue";
|
||||
import Languages from "@/components/settings/Languages.vue";
|
||||
import { computed, inject, onMounted, ref } from "vue";
|
||||
import { inject, onMounted, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { authMethod, noAuth } from "@/utils/constants";
|
||||
|
||||
const layoutStore = useLayoutStore();
|
||||
const authStore = useAuthStore();
|
||||
@@ -118,10 +70,6 @@ const { t } = useI18n();
|
||||
const $showSuccess = inject<IToastSuccess>("$showSuccess")!;
|
||||
const $showError = inject<IToastError>("$showError")!;
|
||||
|
||||
const password = ref<string>("");
|
||||
const passwordConf = ref<string>("");
|
||||
const currentPassword = ref<string>("");
|
||||
const isCurrentPasswordRequired = ref<boolean>(false);
|
||||
const hideDotfiles = ref<boolean>(false);
|
||||
const singleClick = ref<boolean>(false);
|
||||
const redirectAfterCopyMove = ref<boolean>(false);
|
||||
@@ -129,20 +77,6 @@ const dateFormat = ref<boolean>(false);
|
||||
const locale = ref<string>("");
|
||||
const aceEditorTheme = ref<string>("");
|
||||
|
||||
const passwordClass = computed(() => {
|
||||
const baseClass = "input input--block";
|
||||
|
||||
if (password.value === "" && passwordConf.value === "") {
|
||||
return baseClass;
|
||||
}
|
||||
|
||||
if (password.value === passwordConf.value) {
|
||||
return `${baseClass} input--green`;
|
||||
}
|
||||
|
||||
return `${baseClass} input--red`;
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
layoutStore.loading = true;
|
||||
if (authStore.user === null) return false;
|
||||
@@ -153,38 +87,10 @@ onMounted(async () => {
|
||||
dateFormat.value = authStore.user.dateFormat;
|
||||
aceEditorTheme.value = authStore.user.aceEditorTheme;
|
||||
layoutStore.loading = false;
|
||||
isCurrentPasswordRequired.value = authMethod == "json";
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
const updatePassword = async (event: Event) => {
|
||||
event.preventDefault();
|
||||
|
||||
if (
|
||||
password.value !== passwordConf.value ||
|
||||
password.value === "" ||
|
||||
currentPassword.value === "" ||
|
||||
authStore.user === null
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const data = {
|
||||
...authStore.user,
|
||||
id: authStore.user.id,
|
||||
password: password.value,
|
||||
};
|
||||
await api.update(data, ["password"], currentPassword.value);
|
||||
authStore.updateUser(data);
|
||||
$showSuccess(t("settings.passwordUpdated"));
|
||||
} catch (e: any) {
|
||||
$showError(e);
|
||||
} finally {
|
||||
password.value = passwordConf.value = "";
|
||||
}
|
||||
};
|
||||
const updateSettings = async (event: Event) => {
|
||||
event.preventDefault();
|
||||
|
||||
|
||||
@@ -1,211 +1,74 @@
|
||||
<template>
|
||||
<errors v-if="error" :errorCode="error.status" />
|
||||
<div class="row" v-else-if="!layoutStore.loading">
|
||||
<div class="column">
|
||||
<form @submit="save" class="card">
|
||||
<div class="card-title">
|
||||
<h2 v-if="user?.id === 0">{{ $t("settings.newUser") }}</h2>
|
||||
<h2 v-else>{{ $t("settings.user") }} {{ user?.username }}</h2>
|
||||
</div>
|
||||
|
||||
<div class="card-content" v-if="user">
|
||||
<user-form
|
||||
v-model:user="user"
|
||||
v-model:createUserDir="createUserDir"
|
||||
:isDefault="false"
|
||||
:isNew="isNew"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="card-action">
|
||||
<button
|
||||
v-if="!isNew"
|
||||
@click.prevent="deletePrompt"
|
||||
type="button"
|
||||
class="button button--flat button--red"
|
||||
:aria-label="$t('buttons.delete')"
|
||||
:title="$t('buttons.delete')"
|
||||
>
|
||||
{{ $t("buttons.delete") }}
|
||||
</button>
|
||||
<router-link to="/settings/users">
|
||||
<button
|
||||
class="button button--flat button--grey"
|
||||
:aria-label="$t('buttons.cancel')"
|
||||
:title="$t('buttons.cancel')"
|
||||
>
|
||||
{{ $t("buttons.cancel") }}
|
||||
</button>
|
||||
</router-link>
|
||||
<input
|
||||
class="button button--flat"
|
||||
type="submit"
|
||||
:value="$t('buttons.save')"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
<form v-else-if="user" class="card" @submit.prevent="save">
|
||||
<div class="card-title">
|
||||
<h2>{{ user.displayName || user.username }}</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<p class="field-hint">{{ $t("sso.managed") }}</p>
|
||||
<label for="user-scope">{{ $t("settings.scope") }}</label>
|
||||
<input
|
||||
id="user-scope"
|
||||
class="input input--block"
|
||||
v-model="user.scope"
|
||||
required
|
||||
/>
|
||||
<p v-for="permission in permissions" :key="permission">
|
||||
<label
|
||||
><input type="checkbox" v-model="user.perm[permission]" />
|
||||
{{ $t("settings.perm." + permission) }}</label
|
||||
>
|
||||
</p>
|
||||
<rules v-model:rules="user.rules" />
|
||||
</div>
|
||||
<div class="card-action">
|
||||
<router-link to="/settings/users" class="button button--flat">{{
|
||||
$t("buttons.cancel")
|
||||
}}</router-link
|
||||
><button class="button" :disabled="saving">
|
||||
{{ $t("buttons.save") }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
import { users as api, settings } from "@/api";
|
||||
import UserForm from "@/components/settings/UserForm.vue";
|
||||
import Errors from "@/views/Errors.vue";
|
||||
import { computed, inject, onMounted, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { ref, onMounted, inject } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { users as api } from "@/api";
|
||||
import { StatusError } from "@/api/utils";
|
||||
import { authMethod } from "@/utils/constants";
|
||||
import { logout } from "@/utils/auth";
|
||||
|
||||
const error = ref<StatusError>();
|
||||
const originalUser = ref<IUser>();
|
||||
const user = ref<IUser>();
|
||||
const createUserDir = ref<boolean>(false);
|
||||
const isCurrentPasswordRequired = ref<boolean>(false);
|
||||
|
||||
const $showError = inject<IToastError>("$showError")!;
|
||||
const $showSuccess = inject<IToastSuccess>("$showSuccess")!;
|
||||
|
||||
const authStore = useAuthStore();
|
||||
const layoutStore = useLayoutStore();
|
||||
import Errors from "@/views/Errors.vue";
|
||||
import Rules from "@/components/settings/Rules.vue";
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
|
||||
onMounted(() => {
|
||||
fetchData();
|
||||
});
|
||||
|
||||
const isNew = computed(() => route.path === "/settings/users/new");
|
||||
|
||||
watch(route, () => fetchData());
|
||||
watch(user, () => {
|
||||
if (!user.value?.perm.admin) return;
|
||||
user.value.lockPassword = false;
|
||||
});
|
||||
|
||||
const fetchData = async () => {
|
||||
layoutStore.loading = true;
|
||||
|
||||
const user = ref<IUser>();
|
||||
const error = ref<StatusError>();
|
||||
const saving = ref(false);
|
||||
const showError = inject<IToastError>("$showError")!;
|
||||
const showSuccess = inject<IToastSuccess>("$showSuccess")!;
|
||||
const permissions = [
|
||||
"create",
|
||||
"rename",
|
||||
"modify",
|
||||
"delete",
|
||||
"share",
|
||||
"download",
|
||||
] as const;
|
||||
onMounted(async () => {
|
||||
try {
|
||||
if (isNew.value) {
|
||||
const { defaults, createUserDir: _createUserDir } = await settings.get();
|
||||
isCurrentPasswordRequired.value = authMethod == "json";
|
||||
createUserDir.value = _createUserDir;
|
||||
user.value = {
|
||||
...defaults,
|
||||
username: "",
|
||||
password: "",
|
||||
rules: [],
|
||||
lockPassword: false,
|
||||
id: 0,
|
||||
};
|
||||
} else {
|
||||
const { authMethod } = await settings.get();
|
||||
isCurrentPasswordRequired.value = authMethod == "json";
|
||||
const id = Array.isArray(route.params.id)
|
||||
? route.params.id.join("")
|
||||
: route.params.id;
|
||||
user.value = { ...(await api.get(parseInt(id))) };
|
||||
}
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
error.value = err;
|
||||
}
|
||||
user.value = await api.get(Number(route.params.id));
|
||||
} catch (e) {
|
||||
error.value = e as StatusError;
|
||||
}
|
||||
});
|
||||
async function save() {
|
||||
if (!user.value || saving.value) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
await api.update(user.value, ["scope", "perm", "rules"]);
|
||||
showSuccess("Saved");
|
||||
} catch (e) {
|
||||
showError(e as Error);
|
||||
} finally {
|
||||
layoutStore.loading = false;
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const deletePrompt = () => {
|
||||
if (isCurrentPasswordRequired.value) {
|
||||
layoutStore.showHover({
|
||||
prompt: "current-password",
|
||||
confirm: (event: Event, currentPassword: string) => {
|
||||
event.preventDefault();
|
||||
layoutStore.closeHovers();
|
||||
deleteUser(currentPassword);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
layoutStore.showHover({
|
||||
prompt: "deleteUser",
|
||||
confirm: () => deleteUser(""),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const deleteUser = async (currentPassword: string) => {
|
||||
if (!user.value) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
await api.remove(user.value.id, currentPassword);
|
||||
if (user.value.id == authStore.user?.id) {
|
||||
logout();
|
||||
} else {
|
||||
router.push({ path: "/settings/users" });
|
||||
}
|
||||
$showSuccess(t("settings.userDeleted"));
|
||||
} catch (err) {
|
||||
if (err instanceof StatusError) {
|
||||
err.status === 403 ? $showError(t("errors.forbidden")) : $showError(err);
|
||||
} else if (err instanceof Error) {
|
||||
$showError(err);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const save = (event: Event) => {
|
||||
event.preventDefault();
|
||||
if (isCurrentPasswordRequired.value) {
|
||||
layoutStore.showHover({
|
||||
prompt: "current-password",
|
||||
confirm: (event: Event, currentPassword: string) => {
|
||||
event.preventDefault();
|
||||
layoutStore.closeHovers();
|
||||
send(currentPassword);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
send("");
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const send = async (currentPassword: string) => {
|
||||
if (!user.value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (isNew.value) {
|
||||
const newUser: IUser = {
|
||||
...originalUser?.value,
|
||||
...user.value,
|
||||
};
|
||||
|
||||
const loc = await api.create(newUser, currentPassword);
|
||||
router.push({ path: loc || "/settings/users" });
|
||||
$showSuccess(t("settings.userCreated"));
|
||||
} else {
|
||||
await api.update(user.value, ["all"], currentPassword);
|
||||
|
||||
if (user.value.id === authStore.user?.id) {
|
||||
authStore.updateUser(user.value);
|
||||
}
|
||||
|
||||
$showSuccess(t("settings.userUpdated"));
|
||||
}
|
||||
} catch (e: any) {
|
||||
$showError(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
@@ -5,28 +5,19 @@
|
||||
<div class="card">
|
||||
<div class="card-title">
|
||||
<h2>{{ t("settings.users") }}</h2>
|
||||
<router-link to="/settings/users/new"
|
||||
><button class="button">
|
||||
{{ t("buttons.new") }}
|
||||
</button></router-link
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="card-content full">
|
||||
<table>
|
||||
<tr>
|
||||
<th>{{ t("settings.username") }}</th>
|
||||
<th>{{ t("settings.admin") }}</th>
|
||||
|
||||
<th>{{ t("settings.scope") }}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<tr v-for="user in users" :key="user.id">
|
||||
<td>{{ user.username }}</td>
|
||||
<td>
|
||||
<i v-if="user.perm.admin" class="material-icons">done</i
|
||||
><i v-else class="material-icons">close</i>
|
||||
</td>
|
||||
<td>{{ user.displayName || user.username }}</td>
|
||||
<td>{{ user.scope }}</td>
|
||||
<td class="small">
|
||||
<router-link :to="'/settings/users/' + user.id"
|
||||
|
||||
Reference in new issue
Block a user