login method
Receive authentication token by username and password
Implementation
Future<void> login(
{required String username,
required String password,
String? totp}) async {
if (headers['authorization'] != null) {
return;
}
var url = Uri.https(basePath, '/auth/login/');
var response = await client.post(url, headers: {
'X-TOTP': totp ?? ''
}, body: {
'username': username,
'password': password,
'remember': 'yes',
'captcha': 'api'
});
var result = jsonDecode(response.body);
if (result['status'] != null && result['status'] == 'success') {
headers['authorization'] = 'Token ' + result['key'];
}
}