register static method
Registers an account using a certain username
, domain
and password
.
The username+domain corresponds to username
@domain
.
If domain
is not provided, the first one received from the mailtm API is used
If username
and password
aren't provided, they are generated using a Random.secure generator
And their length will be randomCharsLength
Implementation
static Future<AuthenticatedUser> register({
String? username,
String? password,
Domain? domain,
int randomCharsLength = 16,
}) async {
username = username == null || username.isEmpty
? randomString(randomCharsLength)
: username;
password = password == null || password.isEmpty
? randomString(randomCharsLength)
: password;
domain ??= (await domains()).first;
final address = '$username@${domain.domain}'.toLowerCase();
final account = await client.createAccount(address, password);
final token = (await client.getToken(address, password)).token;
final user = AuthenticatedUser(
account: account,
password: password,
token: token,
);
addUser(user.account.id, user);
return user;
}