add login flow
This commit is contained in:
parent
ec40e76178
commit
f307fad074
3 changed files with 84 additions and 64 deletions
|
|
@ -7,35 +7,44 @@ import "package:sqflite_common_ffi/sqflite_ffi.dart";
|
|||
|
||||
class ClientController extends AsyncNotifier<Client> {
|
||||
@override
|
||||
Future<Client> build() async {
|
||||
final client = Client(
|
||||
Future<Client> build() async => Client(
|
||||
"nexus",
|
||||
logLevel: kReleaseMode ? Level.warning : Level.verbose,
|
||||
importantStateEvents: {"im.ponies.room_emotes"},
|
||||
supportedLoginTypes: {AuthenticationTypes.password},
|
||||
database: await MatrixSdkDatabase.init(
|
||||
"nexus",
|
||||
logLevel: kReleaseMode ? Level.warning : Level.verbose,
|
||||
importantStateEvents: {"im.ponies.room_emotes"},
|
||||
supportedLoginTypes: {AuthenticationTypes.password},
|
||||
database: await MatrixSdkDatabase.init(
|
||||
"nexus",
|
||||
database: await databaseFactoryFfi.openDatabase(
|
||||
join((await getApplicationSupportDirectory()).path, "database.db"),
|
||||
),
|
||||
database: await databaseFactoryFfi.openDatabase(
|
||||
join((await getApplicationSupportDirectory()).path, "database.db"),
|
||||
),
|
||||
);
|
||||
),
|
||||
);
|
||||
|
||||
// TODO: Save info
|
||||
// if (client.homeserver == null) {
|
||||
// await client.checkHomeserver(Uri.https("federated.nexus"));
|
||||
// }
|
||||
// if (client.accessToken == null) {
|
||||
// await client.login(
|
||||
// LoginType.mLoginPassword,
|
||||
// initialDeviceDisplayName: "Nexus Client",
|
||||
// deviceId: "temp", // TODO
|
||||
// identifier: AuthenticationUserIdentifier(user: "quadradical"),
|
||||
// password: File("./password.txt").readAsStringSync(),
|
||||
// );
|
||||
// }
|
||||
Future<bool> setHomeserver(Uri homeserverUrl) async {
|
||||
final client = await future;
|
||||
try {
|
||||
await client.checkHomeserver(homeserverUrl);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return client;
|
||||
Future<bool> login(String username, String password) async {
|
||||
final client = await future;
|
||||
try {
|
||||
await client.login(
|
||||
LoginType.mLoginPassword,
|
||||
initialDeviceDisplayName:
|
||||
"Nexus Client login at ${DateTime.now().toIso8601String()}",
|
||||
identifier: AuthenticationUserIdentifier(user: username),
|
||||
password: password,
|
||||
);
|
||||
//TODO: refresh
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static final provider = AsyncNotifierProvider<ClientController, Client>(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue