integrated with previous
This commit is contained in:
45
lib/screens/auth/controller/auth_controller.dart
Normal file
45
lib/screens/auth/controller/auth_controller.dart
Normal file
@ -0,0 +1,45 @@
|
||||
import 'dart:convert' as convert;
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:rogapp/model/user.dart';
|
||||
import 'package:rogapp/utils/const.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class AuthController extends GetxController{
|
||||
var isLoading = false.obs;
|
||||
var authList = List<AuthResponse>.empty(growable: true).obs;
|
||||
|
||||
void signinUser(String email, String password) async {
|
||||
try{
|
||||
isLoading(true);
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/login/';
|
||||
final http.Response response = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: convert.jsonEncode(<String, String>{
|
||||
'email': email,
|
||||
'password': password
|
||||
}),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
print(response.body);
|
||||
AuthResponse authResponse = AuthResponse.fromJson(convert.jsonDecode(convert.utf8.decode(response.body.codeUnits)));
|
||||
print(authResponse.user.eventCode.toString());
|
||||
authList.assign(authResponse);
|
||||
}
|
||||
else{
|
||||
throw("Unable to Login, please check your creadentials");
|
||||
}
|
||||
}
|
||||
catch(e){
|
||||
Get.snackbar("Error", e.toString(), snackPosition: SnackPosition.BOTTOM);
|
||||
}
|
||||
finally{
|
||||
isLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user