mirror of
https://github.com/balzack/databag.git
synced 2025-05-05 07:55:15 +00:00
adding delete account modal
This commit is contained in:
parent
fe04521e07
commit
03cd108cb3
@ -31,6 +31,7 @@ const Strings = [
|
|||||||
monthEnd: 'dd/mm',
|
monthEnd: 'dd/mm',
|
||||||
error: 'Error',
|
error: 'Error',
|
||||||
tryAgain: 'Please try again.',
|
tryAgain: 'Please try again.',
|
||||||
|
allDevices: 'Logout of all devices',
|
||||||
|
|
||||||
// seal wizard
|
// seal wizard
|
||||||
sealUnset: 'Generate a key to enable end-to-end encrypted topics.',
|
sealUnset: 'Generate a key to enable end-to-end encrypted topics.',
|
||||||
@ -246,6 +247,7 @@ const Strings = [
|
|||||||
monthEnd: 'jj/mm',
|
monthEnd: 'jj/mm',
|
||||||
error: 'Erreur',
|
error: 'Erreur',
|
||||||
tryAgain: 'Veuillez réessayer.',
|
tryAgain: 'Veuillez réessayer.',
|
||||||
|
allDevices: 'Déconnexion de tous les appareils',
|
||||||
|
|
||||||
messages: 'Messages',
|
messages: 'Messages',
|
||||||
sealUnset:
|
sealUnset:
|
||||||
@ -461,6 +463,7 @@ const Strings = [
|
|||||||
monthEnd: 'dd/mm',
|
monthEnd: 'dd/mm',
|
||||||
error: 'Error',
|
error: 'Error',
|
||||||
tryAgain: 'Inténtalo de nuevo.',
|
tryAgain: 'Inténtalo de nuevo.',
|
||||||
|
allDevices: 'Cerrar sesión en todos los dispositivos',
|
||||||
|
|
||||||
sealUnset:
|
sealUnset:
|
||||||
'Genere una clave para habilitar temas cifrados de un extremo a otro.',
|
'Genere una clave para habilitar temas cifrados de un extremo a otro.',
|
||||||
@ -673,6 +676,7 @@ const Strings = [
|
|||||||
monthEnd: 'dd/mm',
|
monthEnd: 'dd/mm',
|
||||||
error: 'Fehler',
|
error: 'Fehler',
|
||||||
tryAgain: 'Bitte versuche es erneut.',
|
tryAgain: 'Bitte versuche es erneut.',
|
||||||
|
allDevices: 'Abmelden aller Geräte',
|
||||||
|
|
||||||
sealUnset:
|
sealUnset:
|
||||||
'Generieren Sie einen Schlüssel, um Ende-zu-Ende-verschlüsselte Themen zu ermöglichen.',
|
'Generieren Sie einen Schlüssel, um Ende-zu-Ende-verschlüsselte Themen zu ermöglichen.',
|
||||||
@ -1038,6 +1042,7 @@ const Strings = [
|
|||||||
start: 'Crie Uma Conversa',
|
start: 'Crie Uma Conversa',
|
||||||
started: 'Iniciar',
|
started: 'Iniciar',
|
||||||
|
|
||||||
|
allDevices: 'Sair de todos os dispositivos',
|
||||||
deleteMessage: 'Apagar Mensagem',
|
deleteMessage: 'Apagar Mensagem',
|
||||||
blockMessage: 'Bloquear Mensagem',
|
blockMessage: 'Bloquear Mensagem',
|
||||||
reportMessage: 'Denunciar Mensagem',
|
reportMessage: 'Denunciar Mensagem',
|
||||||
@ -1183,6 +1188,7 @@ const Strings = [
|
|||||||
guest: 'Гость',
|
guest: 'Гость',
|
||||||
leave: 'Покинуть',
|
leave: 'Покинуть',
|
||||||
members: 'Участники',
|
members: 'Участники',
|
||||||
|
allDevices: 'Выход из всех устройств',
|
||||||
editSubject: 'Редактировать тему',
|
editSubject: 'Редактировать тему',
|
||||||
topicMembers: 'Участники темы',
|
topicMembers: 'Участники темы',
|
||||||
leaveTopic: 'Покинуть тему',
|
leaveTopic: 'Покинуть тему',
|
||||||
|
@ -77,12 +77,18 @@ export function useAppContext() {
|
|||||||
);
|
);
|
||||||
updateState({session: login});
|
updateState({session: login});
|
||||||
},
|
},
|
||||||
accountLogout: async () => {
|
accountLogout: async (all: boolean) => {
|
||||||
if (state.session) {
|
if (state.session) {
|
||||||
await sdk.current.logout(state.session, false);
|
await sdk.current.logout(state.session, all);
|
||||||
updateState({session: null});
|
updateState({session: null});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
accountRemove: async () => {
|
||||||
|
if (state.session) {
|
||||||
|
await sdk.current.remove(state.session);
|
||||||
|
updateState({ session: null });
|
||||||
|
}
|
||||||
|
},
|
||||||
accountCreate: async (
|
accountCreate: async (
|
||||||
handle: string,
|
handle: string,
|
||||||
password: string,
|
password: string,
|
||||||
|
@ -28,6 +28,9 @@ export const styles = StyleSheet.create({
|
|||||||
height: '100%',
|
height: '100%',
|
||||||
gap: 8,
|
gap: 8,
|
||||||
},
|
},
|
||||||
|
remove: {
|
||||||
|
backgroundColor: Colors.danger,
|
||||||
|
},
|
||||||
surface: {
|
surface: {
|
||||||
padding: 16,
|
padding: 16,
|
||||||
},
|
},
|
||||||
@ -211,6 +214,14 @@ export const styles = StyleSheet.create({
|
|||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
flexGrow: 1,
|
flexGrow: 1,
|
||||||
},
|
},
|
||||||
|
allControl: {
|
||||||
|
flexShrink: 1,
|
||||||
|
flexGrow: 1,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
paddingTop: 16,
|
||||||
|
},
|
||||||
control: {
|
control: {
|
||||||
flexShrink: 1,
|
flexShrink: 1,
|
||||||
flexGrow: 1,
|
flexGrow: 1,
|
||||||
|
@ -18,6 +18,10 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
|
|||||||
const [auth, setAuth] = useState(false);
|
const [auth, setAuth] = useState(false);
|
||||||
const [clear, setClear] = useState(false);
|
const [clear, setClear] = useState(false);
|
||||||
const [change, setChange] = useState(false);
|
const [change, setChange] = useState(false);
|
||||||
|
const [logout, setLogout] = useState(false);
|
||||||
|
const [remove, setRemove] = useState(false);
|
||||||
|
const [applyingLogout, setApplyingLogout] = useState(false);
|
||||||
|
const [applyingRemove, setApplyingRemove] = useState(false);
|
||||||
const [sealDelete, setSealDelete] = useState(false);
|
const [sealDelete, setSealDelete] = useState(false);
|
||||||
const [sealReset, setSealReset] = useState(false);
|
const [sealReset, setSealReset] = useState(false);
|
||||||
const [sealConfig, setSealConfig] = useState(false);
|
const [sealConfig, setSealConfig] = useState(false);
|
||||||
@ -70,6 +74,38 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const applyRemove = async () => {
|
||||||
|
if (!applyingRemove) {
|
||||||
|
setApplyingRemove(true);
|
||||||
|
try {
|
||||||
|
await actions.remove();
|
||||||
|
setRemove(false);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
setRemove(false);
|
||||||
|
setAlert(true);
|
||||||
|
}
|
||||||
|
setApplyingRemove(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const applyLogout = async () => {
|
||||||
|
if (!applyingLogout) {
|
||||||
|
setApplyingLogout(true);
|
||||||
|
try {
|
||||||
|
await actions.logout();
|
||||||
|
setLogout(false);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
setLogout(false);
|
||||||
|
setAlert(true);
|
||||||
|
}
|
||||||
|
setApplyingLogout(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const setMfa = async (flag: boolean) => {
|
const setMfa = async (flag: boolean) => {
|
||||||
if (!savingAuth) {
|
if (!savingAuth) {
|
||||||
setSavingAuth(true);
|
setSavingAuth(true);
|
||||||
@ -404,7 +440,7 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
|
|||||||
<Icon size={24} source="logout" />
|
<Icon size={24} source="logout" />
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.control}>
|
<View style={styles.control}>
|
||||||
<TouchableOpacity activeOpacity={1} onPress={() => manageSeal}>
|
<TouchableOpacity activeOpacity={1} onPress={() => setLogout(true)}>
|
||||||
<Text style={styles.controlLabel}>{state.strings.logout}</Text>
|
<Text style={styles.controlLabel}>{state.strings.logout}</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
@ -415,7 +451,7 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
|
|||||||
<Icon size={24} source="account-remove" />
|
<Icon size={24} source="account-remove" />
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.control}>
|
<View style={styles.control}>
|
||||||
<TouchableOpacity activeOpacity={1} onPress={() => manageSeal}>
|
<TouchableOpacity activeOpacity={1} onPress={() => setRemove(true)}>
|
||||||
<Text style={styles.dangerLabel}>{state.strings.deleteAccount}</Text>
|
<Text style={styles.dangerLabel}>{state.strings.deleteAccount}</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
@ -941,6 +977,75 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
|
|||||||
</KeyboardAwareScrollView>
|
</KeyboardAwareScrollView>
|
||||||
</View>
|
</View>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
<Modal
|
||||||
|
animationType="fade"
|
||||||
|
transparent={true}
|
||||||
|
supportedOrientations={['portrait', 'landscape']}
|
||||||
|
visible={logout}
|
||||||
|
onRequestClose={() => setLogout(false)}>
|
||||||
|
<View style={styles.modal}>
|
||||||
|
<BlurView
|
||||||
|
style={styles.blur}
|
||||||
|
blurType="dark"
|
||||||
|
blurAmount={2}
|
||||||
|
reducedTransparencyFallbackColor="dark"
|
||||||
|
/>
|
||||||
|
<KeyboardAwareScrollView style={styles.container} contentContainerStyle={styles.content}>
|
||||||
|
<Surface elevation={5} mode="flat" style={styles.surface}>
|
||||||
|
<Text style={styles.modalLabel}>{ state.strings.loggingOut }</Text>
|
||||||
|
<IconButton style={styles.modalClose} icon="close" size={24} onPress={() => setLogout(false)} />
|
||||||
|
|
||||||
|
<View style={styles.allControl}>
|
||||||
|
<Text style={styles.controlLabel}>{state.strings.allDevices}</Text>
|
||||||
|
<Switch style={styles.controlSwitch} value={state.all} onValueChange={actions.setAll} />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.modalControls}>
|
||||||
|
<Button mode="outlined" onPress={() => setLogout(false)}>{ state.strings.cancel }</Button>
|
||||||
|
<Button mode="contained" loading={applyingLogout} onPress={applyLogout}>{ state.strings.logout }</Button>
|
||||||
|
</View>
|
||||||
|
</Surface>
|
||||||
|
</KeyboardAwareScrollView>
|
||||||
|
</View>
|
||||||
|
</Modal>
|
||||||
|
<Modal
|
||||||
|
animationType="fade"
|
||||||
|
transparent={true}
|
||||||
|
supportedOrientations={['portrait', 'landscape']}
|
||||||
|
visible={remove}
|
||||||
|
onRequestClose={() => setRemove(false)}>
|
||||||
|
<View style={styles.modal}>
|
||||||
|
<BlurView
|
||||||
|
style={styles.blur}
|
||||||
|
blurType="dark"
|
||||||
|
blurAmount={2}
|
||||||
|
reducedTransparencyFallbackColor="dark"
|
||||||
|
/>
|
||||||
|
<KeyboardAwareScrollView style={styles.container} contentContainerStyle={styles.content}>
|
||||||
|
<Surface elevation={5} mode="flat" style={styles.surface}>
|
||||||
|
<Text style={styles.modalLabel}>{ state.strings.deleteAccount }</Text>
|
||||||
|
<IconButton style={styles.modalClose} icon="close" size={24} onPress={() => setRemove(false)} />
|
||||||
|
|
||||||
|
<TextInput
|
||||||
|
style={styles.input}
|
||||||
|
mode="flat"
|
||||||
|
autoCapitalize="none"
|
||||||
|
autoComplete="off"
|
||||||
|
autoCorrect={false}
|
||||||
|
value={state.remove}
|
||||||
|
label={state.strings.typeDelete}
|
||||||
|
left={<TextInput.Icon style={styles.icon} icon="delete-outline" />}
|
||||||
|
onChangeText={value => actions.setRemove(value)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<View style={styles.modalControls}>
|
||||||
|
<Button mode="outlined" onPress={() => setRemove(false)}>{ state.strings.cancel }</Button>
|
||||||
|
<Button mode="contained" loading={applyingRemove} disabled={state.remove !== state.strings.deleteKey} style={styles.remove} onPress={applyRemove}>{ state.strings.delete }</Button>
|
||||||
|
</View>
|
||||||
|
</Surface>
|
||||||
|
</KeyboardAwareScrollView>
|
||||||
|
</View>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -19,6 +19,7 @@ export function useSettings() {
|
|||||||
all: false,
|
all: false,
|
||||||
password: '',
|
password: '',
|
||||||
confirm: '',
|
confirm: '',
|
||||||
|
remove: '',
|
||||||
username: '',
|
username: '',
|
||||||
taken: false,
|
taken: false,
|
||||||
checked: true,
|
checked: true,
|
||||||
@ -192,6 +193,9 @@ export function useSettings() {
|
|||||||
logout: async () => {
|
logout: async () => {
|
||||||
await app.actions.accountLogout(state.all)
|
await app.actions.accountLogout(state.all)
|
||||||
},
|
},
|
||||||
|
remove: async () => {
|
||||||
|
await app.actions.accountRemove()
|
||||||
|
},
|
||||||
setHandle: (handle: string) => {
|
setHandle: (handle: string) => {
|
||||||
updateState({ handle, taken: false, checked: false })
|
updateState({ handle, taken: false, checked: false })
|
||||||
clearTimeout(debounce.current)
|
clearTimeout(debounce.current)
|
||||||
@ -216,6 +220,9 @@ export function useSettings() {
|
|||||||
setConfirm: (confirm: string) => {
|
setConfirm: (confirm: string) => {
|
||||||
updateState({ confirm })
|
updateState({ confirm })
|
||||||
},
|
},
|
||||||
|
setRemove: (remove: string) => {
|
||||||
|
updateState({ remove });
|
||||||
|
},
|
||||||
setName: (name: string) => {
|
setName: (name: string) => {
|
||||||
updateState({ name })
|
updateState({ name })
|
||||||
},
|
},
|
||||||
|
@ -56,9 +56,9 @@ export function useAppContext() {
|
|||||||
)
|
)
|
||||||
updateState({ session: login })
|
updateState({ session: login })
|
||||||
},
|
},
|
||||||
accountLogout: async () => {
|
accountLogout: async (all: boolean) => {
|
||||||
if (state.session) {
|
if (state.session) {
|
||||||
await sdk.current.logout(state.session, false)
|
await sdk.current.logout(state.session, all)
|
||||||
updateState({ session: null })
|
updateState({ session: null })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -53,6 +53,7 @@ export interface Settings {
|
|||||||
unlockSeal(password: string): Promise<void>;
|
unlockSeal(password: string): Promise<void>;
|
||||||
updaterSeal(password: string): Promise<void>;
|
updaterSeal(password: string): Promise<void>;
|
||||||
forgetSeal(): Promise<void>;
|
forgetSeal(): Promise<void>;
|
||||||
|
deleteAccount(): Promise<void>;
|
||||||
|
|
||||||
addConfigListener(ev: (config: Config) => void): void;
|
addConfigListener(ev: (config: Config) => void): void;
|
||||||
removeConfigListener(ev: (config: Config) => void): void;
|
removeConfigListener(ev: (config: Config) => void): void;
|
||||||
|
@ -5,6 +5,7 @@ import { type Logging, ConsoleLogging } from './logging';
|
|||||||
import { type Store, OfflineStore, OnlineStore, NoStore } from './store';
|
import { type Store, OfflineStore, OnlineStore, NoStore } from './store';
|
||||||
import { setLogin } from './net/setLogin';
|
import { setLogin } from './net/setLogin';
|
||||||
import { clearLogin } from './net/clearLogin';
|
import { clearLogin } from './net/clearLogin';
|
||||||
|
import { removeAccount } from './net/removeAccount';
|
||||||
import { setAccess } from './net/setAccess';
|
import { setAccess } from './net/setAccess';
|
||||||
import { addAccount } from './net/addAccount';
|
import { addAccount } from './net/addAccount';
|
||||||
import { setAdmin } from './net/setAdmin';
|
import { setAdmin } from './net/setAdmin';
|
||||||
@ -79,6 +80,24 @@ export class DatabagSDK {
|
|||||||
return new SessionModule(this.store, this.crypto, this.log, guid, appToken, node, secure, created);
|
return new SessionModule(this.store, this.crypto, this.log, guid, appToken, node, secure, created);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async remove(session: Session): Promise<void> {
|
||||||
|
const sessionModule = session as SessionModule;
|
||||||
|
const params = await sessionModule.close();
|
||||||
|
try {
|
||||||
|
await this.store.clearLogin();
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
this.log.error(err);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const { node, secure, token } = params;
|
||||||
|
await removeAccount(node, secure, token);
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
this.log.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async logout(session: Session, all: boolean): Promise<void> {
|
public async logout(session: Session, all: boolean): Promise<void> {
|
||||||
const sessionModule = session as SessionModule;
|
const sessionModule = session as SessionModule;
|
||||||
const params = await sessionModule.close();
|
const params = await sessionModule.close();
|
||||||
|
7
app/sdk/src/net/removeAccount.ts
Normal file
7
app/sdk/src/net/removeAccount.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
|
export async function removeAccount(node: string, secure: boolean, token: string): Promise<void> {
|
||||||
|
const endpoint = `http${secure ? 's' : ''}://${node}/profile?agent=${token}`;
|
||||||
|
const { status } = await fetchWithTimeout(endpoint, { method: 'DELETE' })
|
||||||
|
checkResponse(status);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user