login method
Logs in a user with the given Voximplant username and password.
username
- Full user name, including Voximplant user, application, and
account name in the format user@application.account.voximplant.com
.
password
- User password.
Throws VIException, if login process failed, otherwise returns VIAuthResult.
Errors:
- VIClientError.ERROR_ACCOUNT_FROZEN - If the account is frozen.
- VIClientError.ERROR_MAU_ACCESS_DENIED - Monthly Active Users (MAU) limit is reached. Payment is required.
- VIClientError.ERROR_INTERNAL - If an internal error occurred.
- VIClientError.ERROR_INVALID_PASSWORD - if the given password is invalid.
- VIClientError.ERROR_INVALID_STATE - If the client is not connected, already logged in, or currently logging in.
- VIClientError.ERROR_INVALID_USERNAME - If the given username is invalid.
- VIClientError.ERROR_NETWORK_ISSUES - If the connection to the Voximplant Cloud is closed while the client is logging in.
- VIClientError.ERROR_TIMEOUT - If timeout occurred.
Implementation
Future<VIAuthResult> login(String username, String password) async {
_changeClientState(VIClientState.LoggingIn);
try {
Map<String, dynamic>? data =
await _channel.invokeMapMethod<String, dynamic>(
'Client.login',
<String, String>{'username': username, 'password': password},
);
if (data == null) {
_VILog._e('VIClient: login: data was null, skipping');
throw VIException(
VIClientError.ERROR_INTERNAL,
'VIClient:login: data was null',
);
}
_saveUsername(username);
return await _processLoginSuccess(data);
} on PlatformException catch (e) {
VIClientState state = await getClientState();
_changeClientState(state);
throw VIException(e.code, e.message);
} catch (e) {
VIClientState state = await getClientState();
_changeClientState(state);
rethrow;
}
}