login method

Future<void> login({
  1. required String username,
  2. required String password,
})

Gets User's _token and saves it as a parameter inside the class instance for later use.

Implementation

Future<void> login(
    {required String username, required String password}) async {
  final response = await _client.post(
    Uri.https(
      'eclass.$instituteId.gr',
      '/modules/mobile/mlogin.php',
    ),
    body: {
      'uname': username,
      'pass': password,
    },
  );
  if (response.statusCode != 200 ||
      response.body == 'FAILED' ||
      response.body == 'USERNOTACTIVE' ||
      response.body == 'NOTENABLED') {
    throw Exception('Failed to login.');
  }
  _token = response.body;
}