40 lines
1004 B
Dart
40 lines
1004 B
Dart
import 'dart:convert';
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:pcastlivetv/globals.dart';
|
|
|
|
import '../models/login_model.dart';
|
|
|
|
class AuthService {
|
|
Future<LoginModel> login(String email, String password) async {
|
|
final dio = Dio();
|
|
try {
|
|
final data = {
|
|
"email": email,
|
|
"password": password,
|
|
};
|
|
|
|
final response = await dio.post(
|
|
Endpoints.login,
|
|
options: Options(
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
),
|
|
data: jsonEncode(data),
|
|
);
|
|
|
|
switch (response.statusCode) {
|
|
case 200:
|
|
print(jsonDecode(response.data));
|
|
var authModel = LoginModel.fromJson(jsonDecode(response.data));
|
|
return authModel;
|
|
default:
|
|
throw Exception('Erro inesperado no login: ${response.statusCode} - ${response.data.toString()}');
|
|
}
|
|
} on Exception catch (e) {
|
|
throw Exception('Exception inesperada no login: $e');
|
|
}
|
|
}
|
|
}
|