userLogin method

Future<Response> userLogin({
  1. required String password,
  2. required String userName,
})

To login into whitelabel app user needs to use below API

Implementation

Future<http.Response> userLogin({
  required String password,
  required String userName,
}) async {
  Uri url = Uri.parse("$_baseUrl/user/login");

  final body = jsonEncode({
    "password": password,
    "username": userName,
    "business": SharedPreference.getBusinessConfig()!.businessId,
  });

  printMessage(body);

  http.Response response =
      await http.Client().post(url, body: body, headers: kPostRequestHeader);

  if (response.statusCode == 200) {
    printMessage("USEr LOGIN RESPONSE = ${response.body}");
    UserModel userModel = UserModel.fromJson(jsonDecode(response.body));
    SharedPreference.setUser(userModel: userModel);
    kAuthenticatedPostRequestHeader = {
      "Accept": "application/json",
      "Content-Type": "application/json",
      "Authorization": "Token ${SharedPreference.getUser()!.token}"
    };

    kAuthenticatedGetRequestHeader = {
      "Accept": "application/json",
      "Authorization": "Token ${SharedPreference.getUser()!.token}"
    };
    return response;
  } else {
    printMessage("USER LOGIN RESPONSE = ${response.statusCode}");
    printMessage("USER LOGIN RESPONSE = ${response.body}");
    return response;
  }
}