30a19fcc1e
Added: - changePassword to change the password NOTE: this requires the old password, just to prevent account hijacking. - some basic user limit information - theme selector NOTE: the system theme is meant to function like auto-theme, and is directly translated into a flutter ThemeMode, however, this does not appear to be working on the web. This commit also adds the logout and delete account buttons, but they do not yet delete all rooms, nor do they properly logout the user. BUG: User is not logged out correctly, reloading the page fixes this. Maybe localstore.listen does not detect deletion?
75 lines
1.9 KiB
Dart
75 lines
1.9 KiB
Dart
import 'package:localstore/localstore.dart';
|
|
import './resolve_url.dart';
|
|
|
|
class User {
|
|
const User(
|
|
{required this.username, required this.password, required this.server});
|
|
|
|
final String username;
|
|
final String password;
|
|
final OutbagServer server;
|
|
|
|
Future<void> toDisk() async {
|
|
final db = Localstore.instance;
|
|
await db
|
|
.collection('meta')
|
|
.doc('auth')
|
|
.set({'username': username, 'password': password});
|
|
await server.toDisk();
|
|
}
|
|
|
|
static Future<User> fromDisk() async {
|
|
final db = Localstore.instance;
|
|
final data = await db.collection('meta').doc('auth').get();
|
|
final server = await OutbagServer.fromDisk();
|
|
|
|
return User(
|
|
username: data?['username'],
|
|
password: data?['password'],
|
|
server: server,
|
|
);
|
|
}
|
|
|
|
static Future<void> removeDisk() async {
|
|
final db = Localstore.instance;
|
|
await db.collection('meta').doc('auth').delete();
|
|
return;
|
|
}
|
|
|
|
static listen(Function(Map<String, dynamic>) cb) async {
|
|
final db = Localstore.instance;
|
|
final stream = db.collection('meta').stream;
|
|
stream.listen(cb);
|
|
}
|
|
|
|
String get humanReadable {
|
|
return '$username@${server.tag}';
|
|
}
|
|
}
|
|
|
|
class AccountMeta {
|
|
final int permissions;
|
|
final String username;
|
|
final bool discoverable;
|
|
final int maxRoomCount;
|
|
final int maxRoomSize;
|
|
final int maxRoomMemberCount;
|
|
|
|
const AccountMeta(
|
|
{required this.permissions,
|
|
required this.username,
|
|
required this.maxRoomSize,
|
|
required this.maxRoomCount,
|
|
required this.maxRoomMemberCount,
|
|
required this.discoverable});
|
|
|
|
factory AccountMeta.fromJSON(dynamic json) {
|
|
return AccountMeta(
|
|
permissions: json['rights'],
|
|
username: json['name'],
|
|
maxRoomSize: json['maxRoomSize'],
|
|
maxRoomCount: json['maxRooms'],
|
|
maxRoomMemberCount: json['maxUsersPerRoom'],
|
|
discoverable: json['viewable'] == 1);
|
|
}
|
|
}
|