acenturyandabit / acenturyandabit/workflowish

Better password prompting

Offen
#3 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
todo
Vorherrschende Sprache
TypeScript
Sterne
0
Forks
1
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

https://api.github.com/acenturyandabit/workflowish/blob/d01a875/src/Stores/HTTPKVStore.tsx#L120

```javascript

import { DefaultKVConstructionArgs, KVStore, KVStoreSettingsStruct } from "./types";
import * as React from "react";
import { Checkbox, FormControlLabel, TextField } from "@mui/material"
import { BaseStoreDataType } from "~CoreDataLake";

const HTTPKVStoreType = "HTTPStore" as const;
export interface HTTPKVStoreSettings extends KVStoreSettingsStruct {
type: typeof HTTPKVStoreType
saveURL: string
loadURL: string
syncURL: string
usePassword?: boolean
}

const isHTTPKVStoreSettings = (x: KVStoreSettingsStruct | DefaultKVConstructionArgs):
x is HTTPKVStoreSettings => x?.type == HTTPKVStoreType

class HTTPKVStore implements
KVStore{
settings: HTTPKVStoreSettings
password?: string
static type = HTTPKVStoreType
constructor(_settings: HTTPKVStoreSettings | DefaultKVConstructionArgs) {
if (isHTTPKVStoreSettings(_settings)) {
this.settings = _settings;
} else {
this.settings = {
type: HTTPKVStoreType,
saveURL: "",
loadURL: "",
syncURL: "",
usePassword: false
};
}
this.sync = this.sync.bind(this)
}

toJsonSettings() {
return this.settings
}

makeFileDialog(bumpKVStores: () => void) {
return (
<>

HTTP Store Settings


{
this.settings.saveURL = evt.target.value;
bumpKVStores();
}}
/>



{
this.settings.loadURL = evt.target.value;
bumpKVStores();
}}
/>



{
this.settings.syncURL = evt.target.value;
bumpKVStores();
}}
/>
{
this.settings.usePassword = evt.target.checked;
bumpKVStores();
}}
/>}
label={"Use Password (Prompts on load - press 'load' to retry password)"}
/>

)
}

save(data: BaseStoreDataType) {
this.authedFetch(this.settings.saveURL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data)
})
}

async sync(data: BaseStoreDataType): Promise {
const response = this.authedFetch(this.settings.syncURL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data)
})
return await (await response).json()
}

async load(): Promise {
if (this.settings.usePassword && !this.password) {
// TODO: Better security

// TODO: Better password prompting
this.password = prompt("Please enter your password for " + this.settings.loadURL) || "";
}
const response = await this.authedFetch(this.settings.loadURL);
return await response.json();
}

async authedFetch(url: string, args?: RequestInit): Promise> {
const headers = new Headers(args?.headers)
if (this.password) headers.set("password", this.password);
return await fetch(url, {
...args,
headers: headers,
})
}
}
export default HTTPKVStore

```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.