Add password based login

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2022-03-23 10:47:41 +05:30
parent a30df28b62
commit 49d4dbfc81

View file

@ -102,47 +102,76 @@ function DeviceManage() {
}; };
const handleRemove = async (device, auth = undefined) => { const handleRemove = async (device, auth = undefined) => {
if (confirm(`You are about to logout "${device.display_name}" session?`)) { if (auth === undefined
addToProcessing(device, auth); ? window.confirm(`You are about to logout "${device.display_name}" session?`)
: true
) {
addToProcessing(device);
try { try {
await mx.deleteDevice(device.device_id); await mx.deleteDevice(device.device_id, auth);
} catch (e) { } catch (e) {
if (e.httpStatus === 401 && e.data?.flows) {
const { flows } = e.data;
const flow = flows.find((f) => f.stages.includes('m.login.password'));
if (flow) {
const password = window.prompt('Please enter account password', '');
if (password && password.trim() !== '') {
handleRemove(device, {
session: e.data.session,
type: 'm.login.password',
password,
identifier: {
type: 'm.id.user',
user: mx.getUserId(),
},
});
return;
}
}
}
window.alert('Failed to remove session!');
if (!mountStore.getItem()) return; if (!mountStore.getItem()) return;
removeFromProcessing(device); removeFromProcessing(device);
} }
} }
}; };
const renderDevice = (device, isVerified) => ( const renderDevice = (device, isVerified) => {
<SettingTile const deviceId = device.device_id;
key={device.device_id} const displayName = device.display_name;
title={( const lastIP = device.last_seen_ip;
<Text style={{ color: isVerified ? '' : 'var(--tc-danger-high)' }}> const lastTS = device.last_seen_ts;
{device.display_name} return (
<Text variant="b3" span>{`${device.device_id}${mx.deviceId === device.device_id ? ' (current)' : ''}`}</Text> <SettingTile
</Text> key={deviceId}
)} title={(
options={ <Text style={{ color: isVerified ? '' : 'var(--tc-danger-high)' }}>
processing.includes(device.device_id) {displayName}
? <Spinner size="small" /> <Text variant="b3" span>{`${deviceId}${mx.deviceId === deviceId ? ' (current)' : ''}`}</Text>
: ( </Text>
<> )}
<IconButton size="small" onClick={() => handleRename(device)} src={PencilIC} tooltip="Rename" /> options={
<IconButton size="small" onClick={() => handleRemove(device)} src={BinIC} tooltip="Remove session" /> processing.includes(deviceId)
</> ? <Spinner size="small" />
) : (
} <>
content={( <IconButton size="small" onClick={() => handleRename(device)} src={PencilIC} tooltip="Rename" />
<Text variant="b3"> <IconButton size="small" onClick={() => handleRemove(device)} src={BinIC} tooltip="Remove session" />
Last activity </>
<span style={{ color: 'var(--tc-surface-normal)' }}> )
{dateFormat(new Date(device.last_seen_ts), ' hh:MM TT, dd/mm/yyyy')} }
</span> content={(
{` at ${device.last_seen_ip}`} <Text variant="b3">
</Text> Last activity
)} <span style={{ color: 'var(--tc-surface-normal)' }}>
/> {dateFormat(new Date(lastTS), ' hh:MM TT, dd/mm/yyyy')}
); </span>
{lastIP ? ` at ${lastIP}` : ''}
</Text>
)}
/>
);
};
const unverified = []; const unverified = [];
const verified = []; const verified = [];
@ -167,6 +196,9 @@ function DeviceManage() {
? verified.map((device) => renderDevice(device, true)) ? verified.map((device) => renderDevice(device, true))
: <Text className="device-manage__info">No verified session</Text> : <Text className="device-manage__info">No verified session</Text>
} }
{ deviceList.length > 0 && (
<Text className="device-manage__info" variant="b3">Session names are visible to everyone, so do not put any private info here.</Text>
)}
</div> </div>
</div> </div>
); );