LoginUser static method
Future
LoginUser(
- dynamic body
)
Implementation
static Future LoginUser(body) async {
try {
var storeId = await StoreBountyInit.getStoreId();
final jsonData = await StoreBountyInit.readJsonFromRoot();
var data = {
"app_id": "storebounty",
"business_id": storeId,
"username": body['email'],
"password": body['password'],
"platform": "mobile",
"fingerprint": {
"id": "123",
"model": "SM-G970U1",
"os_version": 11,
"screen_width": 360,
"screen_height": 760,
"manufacturer": "samsung",
"is_physical_device": true,
"screen_resolution": "1080x2280",
"ip": "107.181.180.171"
}
};
final response = await HttpClientClass.postRequestAuth("${jsonData['BASE_URL']}/accounts/api/v1/auth/customers/token", data);
print(response.body);
if (response.statusCode == 200) {
await _saveLoginRecord(response);
return response;
} else if (response.statusCode == 401) {
var error = jsonDecode(response.body);
throw (error['data']['message']);
}
else if (response.statusCode == 412) {
var error = jsonDecode(response.body);
throw (error['message']);
}else if(response.statusCode == 422){
var error = jsonDecode(response.body);
throw (error["msg"]);
} else {
throw ("Unknown error");
}
} catch (e) {
rethrow;
}
}