2023-03-29 18:02:00 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2023-03-18 20:24:48 +01:00
|
|
|
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 {
|
2023-03-29 18:02:00 +02:00
|
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
await prefs.setString('username', username);
|
|
|
|
await prefs.setString('password', password);
|
2023-03-18 20:24:48 +01:00
|
|
|
await server.toDisk();
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<User> fromDisk() async {
|
2023-03-29 18:02:00 +02:00
|
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
|
2023-03-18 20:24:48 +01:00
|
|
|
final server = await OutbagServer.fromDisk();
|
|
|
|
|
|
|
|
return User(
|
2023-03-29 18:02:00 +02:00
|
|
|
username: prefs.getString('username')!,
|
|
|
|
password: prefs.getString('password')!,
|
|
|
|
server: server);
|
2023-03-18 20:24:48 +01:00
|
|
|
}
|
|
|
|
|
2023-03-23 14:48:53 +01:00
|
|
|
static Future<void> removeDisk() async {
|
2023-03-29 18:02:00 +02:00
|
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
2023-03-23 14:48:53 +01:00
|
|
|
|
2023-03-29 18:02:00 +02:00
|
|
|
await prefs.remove('username');
|
|
|
|
await prefs.remove('password');
|
|
|
|
await OutbagServer.removeDisk();
|
2023-03-18 20:24:48 +01:00
|
|
|
}
|
2023-03-25 14:29:28 +01:00
|
|
|
|
|
|
|
String get humanReadable {
|
|
|
|
return '$username@${server.tag}';
|
|
|
|
}
|
2023-03-18 20:24:48 +01:00
|
|
|
}
|
2023-03-23 10:51:34 +01:00
|
|
|
|
|
|
|
class AccountMeta {
|
|
|
|
final int permissions;
|
|
|
|
final String username;
|
2023-03-25 14:29:28 +01:00
|
|
|
final bool discoverable;
|
2023-03-23 10:51:34 +01:00
|
|
|
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,
|
2023-03-25 14:29:28 +01:00
|
|
|
required this.discoverable});
|
2023-03-23 10:51:34 +01:00
|
|
|
|
|
|
|
factory AccountMeta.fromJSON(dynamic json) {
|
|
|
|
return AccountMeta(
|
2023-03-23 14:48:53 +01:00
|
|
|
permissions: json['rights'],
|
|
|
|
username: json['name'],
|
|
|
|
maxRoomSize: json['maxRoomSize'],
|
|
|
|
maxRoomCount: json['maxRooms'],
|
|
|
|
maxRoomMemberCount: json['maxUsersPerRoom'],
|
2023-03-25 14:29:28 +01:00
|
|
|
discoverable: json['viewable'] == 1);
|
2023-03-23 10:51:34 +01:00
|
|
|
}
|
|
|
|
}
|