re factor rog

This commit is contained in:
2024-04-01 09:26:56 +05:30
parent dd36ab8399
commit edbf52825b
54 changed files with 2597 additions and 435 deletions

View File

@ -0,0 +1,44 @@
import 'package:rogapp/features/data/user.dart';
import '../utils/const.dart';
import 'package:dio/dio.dart';
class AuthService {
Dio dio = Dio();
Future<User?> userLogin(String email, String password) async {
final String serverUrl = ConstValues.currentServer();
final String url = '$serverUrl/api/login/';
try {
final response = await dio.post(
url,
data: {
'email': email,
'password': password,
},
options: Options(
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
),
);
if (response.statusCode == 200 && response.data != null) {
final data = response.data;
User user = User.fromMap(data["user"]);
final String token = data["token"];
user.auth_token = token;
return user;
}
return null;
} on DioException catch (e) {
print("Dio error: ${e.response?.statusCode} - ${e.message}");
return null;
} catch (e) {
print("Unexpected error: $e");
return null;
}
}
}