code cleanup
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
<script>
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { user } from '../../user.svelte.js';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
import { api } from '../../urls.svelte.js';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { user } from '../../user.svelte.js';
|
||||
|
||||
let connections = $state([]);
|
||||
|
||||
async function loadConnections(){
|
||||
let url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/connected`;
|
||||
|
||||
let resp = await fetch(url,{credentials:'include'});
|
||||
const url = api('/user/oidc/connected');
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
const arr = await resp.json();
|
||||
while (connections.length) connections.pop();
|
||||
@@ -19,11 +20,11 @@
|
||||
onMount(loadConnections);
|
||||
|
||||
async function unlink(connection){
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/connected`;
|
||||
const url = api('user/oidc/connected');
|
||||
const resp = await fetch(url,{
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(connection)
|
||||
method : 'DELETE',
|
||||
credentials : 'include',
|
||||
body : JSON.stringify(connection)
|
||||
});
|
||||
if (resp.ok){
|
||||
loadConnections();
|
||||
|
||||
@@ -1,35 +1,34 @@
|
||||
<script>
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { api } from '../../urls.svelte.js';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
|
||||
let { editPassword = $bindable() } = $props();
|
||||
|
||||
let oldPass = $state("");
|
||||
let newPass = $state("");
|
||||
let repeat = $state("");
|
||||
let caption = $state(t('update'));
|
||||
|
||||
let oldEmpty = $derived(!/\S/.test(oldPass));
|
||||
let newEmpty = $derived(!/\S/.test(newPass));
|
||||
let caption = $state(t('update'));
|
||||
let error = $state("");
|
||||
let newPass = $state("");
|
||||
let mismatch = $derived(newPass != repeat);
|
||||
|
||||
let error = $state("");
|
||||
let sent = $state(false);
|
||||
let newEmpty = $derived(!/\S/.test(newPass));
|
||||
let oldPass = $state("");
|
||||
let oldEmpty = $derived(!/\S/.test(oldPass));
|
||||
let repeat = $state("");
|
||||
let sent = $state(false);
|
||||
|
||||
function abort(){
|
||||
editPassword = false;
|
||||
}
|
||||
|
||||
async function submit(){
|
||||
caption = t('data_sent');
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/password`;
|
||||
caption = t('data_sent');
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/password`;
|
||||
const data = {
|
||||
old: oldPass,
|
||||
new: newPass
|
||||
old : oldPass,
|
||||
new : newPass
|
||||
};
|
||||
const resp = await fetch(url,{
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(data),
|
||||
credentials: 'include'
|
||||
method : 'PATCH',
|
||||
body : JSON.stringify(data),
|
||||
credentials : 'include'
|
||||
});
|
||||
|
||||
if (resp.ok){
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { onMount } from 'svelte';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
|
||||
import { api } from '../../urls.svelte.js'
|
||||
import { t } from '../../translations.svelte.js';
|
||||
|
||||
let caption = $state(t('save_service'));
|
||||
let disabled = $state(false);
|
||||
let service = $state({})
|
||||
let { serviceName } = $props();
|
||||
let service = $state({})
|
||||
let caption = $state(t('save_service'));
|
||||
let message = $state(t('loading_data'));
|
||||
let router = useTinyRouter();
|
||||
let disabled = $state(false);
|
||||
let message = $state(t('loading_data'));
|
||||
let router = useTinyRouter();
|
||||
|
||||
onMount(async () => {
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/${serviceName}`;
|
||||
const url = api(`user/oidc/${serviceName}`);
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
const json = await resp.json();
|
||||
@@ -23,12 +25,12 @@
|
||||
});
|
||||
|
||||
async function update(){
|
||||
caption = t('data_sent');
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/${serviceName}`;
|
||||
caption = t('data_sent');
|
||||
const url = api(`user/oidc/${serviceName}`);
|
||||
const resp = await fetch(url,{
|
||||
credentials: 'include',
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(service)
|
||||
credentials : 'include',
|
||||
method : 'PATCH',
|
||||
body : JSON.stringify(service)
|
||||
});
|
||||
if (resp.ok){
|
||||
caption = t('saved');
|
||||
|
||||
@@ -1,34 +1,33 @@
|
||||
<script>
|
||||
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
import { onMount } from 'svelte';
|
||||
import { checkUser } from '../../user.svelte.js';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
const router = useTinyRouter();
|
||||
import { api } from '../../urls.svelte.js'
|
||||
import { checkUser } from '../../user.svelte.js';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
|
||||
let { user_id } = $props();
|
||||
|
||||
let editUser = $state(null);
|
||||
let options = $state([]);
|
||||
let sent = $state(false);
|
||||
let caption = $state(t('save_user'));
|
||||
let message = $state(t('loading_data'));
|
||||
let caption = $state(t('save_user'));
|
||||
let editUser = $state(null);
|
||||
let message = $state(t('loading_data'));
|
||||
let options = $state([]);
|
||||
const router = useTinyRouter();
|
||||
let sent = $state(false);
|
||||
|
||||
onMount(async () => {
|
||||
let url = `${location.protocol}//${location.host.replace('5173','8080')}/themes.json`;
|
||||
let url = `${location.protocol}//${location.host.replace('5173','8080')}/themes.json`;
|
||||
let resp = await fetch(url);
|
||||
if (resp.ok){
|
||||
const arr = await resp.json();
|
||||
for (let entry of arr){
|
||||
const value = entry.value;
|
||||
const value = entry.value;
|
||||
const caption = entry.caption ? entry.caption : value;
|
||||
options.push({caption:caption,value:value})
|
||||
}
|
||||
}
|
||||
|
||||
if (user_id) {
|
||||
url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/${user_id}`;
|
||||
url = api(`user/${user_id}`);
|
||||
resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok) {
|
||||
editUser = await resp.json();
|
||||
@@ -43,20 +42,20 @@
|
||||
|
||||
async function save(ev){
|
||||
ev.preventDefault();
|
||||
sent = true;
|
||||
caption = t('data_sent');
|
||||
sent = true;
|
||||
caption = t('data_sent');
|
||||
let method = 'PATCH';
|
||||
let url = null;
|
||||
let url = null;
|
||||
if (user_id) {
|
||||
url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/${user_id}`;
|
||||
url = api(`user/${user_id}`);
|
||||
} else {
|
||||
url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/create`;
|
||||
url = api('user/create');
|
||||
method = 'POST';
|
||||
}
|
||||
let resp = await fetch(url,{
|
||||
method: method,
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(editUser)
|
||||
method : method,
|
||||
credentials : 'include',
|
||||
body : JSON.stringify(editUser)
|
||||
});
|
||||
if (resp.ok){
|
||||
caption = t('saved');
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { onMount } from 'svelte';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
import { user } from '../../user.svelte.js';
|
||||
|
||||
import { api } from '../../urls.svelte.js';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { user } from '../../user.svelte.js';
|
||||
|
||||
const router = useTinyRouter();
|
||||
let users = $state([]);
|
||||
|
||||
let users = $state([]);
|
||||
|
||||
onMount(async () => {
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/list`;
|
||||
async function listUsers(){
|
||||
const url = api('user/list');
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
const json = await resp.json();
|
||||
for (let u of json) users.push(u);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function impersonate(userId){
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/${userId}/impersonate`;
|
||||
const url = api(`user/${userId}/impersonate`);
|
||||
const resp = await fetch(url,{
|
||||
method: 'POST',
|
||||
credentials: 'include'
|
||||
method : 'POST',
|
||||
credentials : 'include'
|
||||
});
|
||||
if (resp.ok){
|
||||
const json = await resp.json();
|
||||
@@ -29,6 +30,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
onMount(listUsers);
|
||||
</script>
|
||||
|
||||
<fieldset tabindex="0">
|
||||
|
||||
@@ -1,27 +1,16 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { onMount } from 'svelte';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
import { user } from '../../user.svelte.js';
|
||||
|
||||
import { api } from '../../urls.svelte.js';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { user } from '../../user.svelte.js';
|
||||
|
||||
const router = useTinyRouter();
|
||||
|
||||
let services = $state([]);
|
||||
|
||||
async function loadButtons(){
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/buttons`;
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
const json = await resp.json();
|
||||
while (services.length) services.pop();
|
||||
for (let service of json) services.push(service);
|
||||
}
|
||||
}
|
||||
|
||||
onMount(loadButtons);
|
||||
|
||||
async function connect(service){
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/redirect/${service}`;
|
||||
const url = api(`user/oidc/redirect/${service}`);
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
var json = await resp.json();
|
||||
@@ -33,14 +22,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function loadButtons(){
|
||||
const url = api(`user/oidc/buttons`);
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
const json = await resp.json();
|
||||
while (services.length) services.pop();
|
||||
for (let service of json) services.push(service);
|
||||
}
|
||||
}
|
||||
|
||||
async function drop(service){
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/${service}`;
|
||||
const url = api(`user/oidc/${service}`);
|
||||
const resp = await fetch(url,{
|
||||
credentials: 'include',
|
||||
method: 'DELETE'
|
||||
credentials : 'include',
|
||||
method : 'DELETE'
|
||||
});
|
||||
if (resp.ok) loadButtons();
|
||||
}
|
||||
|
||||
onMount(loadButtons);
|
||||
</script>
|
||||
|
||||
<fieldset tabindex="0">
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { onMount } from 'svelte';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
import { checkUser } from '../../user.svelte.js';
|
||||
|
||||
import { api } from '../../urls.svelte.js';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { checkUser } from '../../user.svelte.js';
|
||||
|
||||
const router = useTinyRouter();
|
||||
let message = $state(t('processing_code'));
|
||||
|
||||
let message = $state(t('processing_code'));
|
||||
onMount(async () => {
|
||||
async function process(){
|
||||
let params = new URLSearchParams(location.search);
|
||||
|
||||
if (params.get('code')){
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/token`;
|
||||
const url = api('user/oidc/token');
|
||||
const resp = await fetch(url,{
|
||||
method : 'POST',
|
||||
body: JSON.stringify(Object.fromEntries(params)),
|
||||
credentials: 'include'
|
||||
method : 'POST',
|
||||
body : JSON.stringify(Object.fromEntries(params)),
|
||||
credentials : 'include'
|
||||
});
|
||||
if (resp.ok){
|
||||
let json = await resp.json();
|
||||
let json = await resp.json();
|
||||
const redirect = json.redirect ? json.redirect : '/user';
|
||||
checkUser();
|
||||
router.navigate(redirect);
|
||||
@@ -27,7 +29,9 @@
|
||||
if (!message) message = t(resp);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onMount(process);
|
||||
</script>
|
||||
|
||||
{message}
|
||||
@@ -1,14 +1,15 @@
|
||||
<script>
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { user } from '../../user.svelte.js';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
|
||||
import EditPassword from './EditPassword.svelte';
|
||||
const router = useTinyRouter();
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { user } from '../../user.svelte.js';
|
||||
|
||||
import EditPassword from './EditPassword.svelte';
|
||||
|
||||
const router = useTinyRouter();
|
||||
let editPassword = false;
|
||||
|
||||
</script>
|
||||
|
||||
<fieldset>
|
||||
<legend>
|
||||
{t('your_profile')}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { onMount } from 'svelte';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
|
||||
let mail = "";
|
||||
let caption = t('send_mail');
|
||||
let error = null;
|
||||
import { api } from '../../urls.svelte.js';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
|
||||
let caption = t('send_mail');
|
||||
let error = null;
|
||||
let mail = "";
|
||||
const router = useTinyRouter();
|
||||
|
||||
async function submit(ev){
|
||||
ev.preventDefault();
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/reset_pw`;
|
||||
const url = api(`user/reset_pw`);
|
||||
const resp = await fetch(url,{
|
||||
method : 'POST',
|
||||
body : mail
|
||||
body : mail
|
||||
});
|
||||
if (resp.ok) {
|
||||
caption = t('data_sent');
|
||||
@@ -24,9 +26,9 @@
|
||||
|
||||
async function checkToken(){
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const token = urlParams.get('token');
|
||||
const token = urlParams.get('token');
|
||||
if (token) {
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/validate/${token}`;
|
||||
const url = api(`user/validate/${token}`);
|
||||
const resp = await fetch(url,{
|
||||
credentials: 'include'
|
||||
});
|
||||
@@ -46,13 +48,13 @@
|
||||
<style>
|
||||
label{display:block}
|
||||
fieldset{
|
||||
display: block;
|
||||
position: relative;
|
||||
left: 50%;
|
||||
width: 200px;
|
||||
margin-left: -100px;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
display : block;
|
||||
position : relative;
|
||||
left : 50%;
|
||||
width : 200px;
|
||||
margin-left : -100px;
|
||||
margin-bottom : 30px;
|
||||
text-align : center;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
<script>
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { user } from '../../user.svelte.js';
|
||||
import { user } from '../../user.svelte.js';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
|
||||
import Services from './ConnectedServices.svelte';
|
||||
import Services from './ConnectedServices.svelte';
|
||||
import LoginServiceList from './LoginServices.svelte';
|
||||
import Profile from './Profile.svelte';
|
||||
import UserList from './List.svelte';
|
||||
import Profile from './Profile.svelte';
|
||||
import UserList from './List.svelte';
|
||||
|
||||
let params = new URLSearchParams(location.search);
|
||||
let params = new URLSearchParams(location.search);
|
||||
let redirect = params.get('returnTo');
|
||||
if (redirect && user.name){
|
||||
location.href = redirect;
|
||||
}
|
||||
if (redirect && user.name) location.href = redirect;
|
||||
</script>
|
||||
|
||||
<h1>{t('user_module')}</h1>
|
||||
|
||||
Reference in New Issue
Block a user