login static method

Future<bool> login(
  1. dynamic email,
  2. dynamic password
)

Implementation

static Future<bool> login(email, password) async {
  final res = await httpClient.post(
    Config.getURI('/login.json'),
    body: jsonEncode({'email': email, 'password': password}),
  );

  if (res.statusCode != 200) return false;

  dynamic data = jsonDecode(res.body.toString());

  if (data['token'].toString().isEmpty) return false;

  await logout();

  await storage.write(key: 'token', value: data['token'].toString());
  await storage.write(key: 'email', value: email);
  await storage.write(key: 'account_id', value: data['account_id'].toString());

  return true;
}