41 lines
1.1 KiB
Dart
41 lines
1.1 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:pcastlivetv/globals.dart';
|
|
|
|
import '../models/auth_model.dart';
|
|
|
|
class AuthService {
|
|
Future<AuthModel> 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:
|
|
var authModel = AuthModel.fromJson(response.data);
|
|
return authModel;
|
|
default:
|
|
print('Erro inesperado no login: ${response.statusCode} - ${response.data.toString()}');
|
|
throw Exception('Erro inesperado no login: ${response.statusCode} - ${response.data.toString()}');
|
|
}
|
|
} on Exception catch (e) {
|
|
print('Exception inesperada no login: $e');
|
|
throw Exception('Exception inesperada no login: $e');
|
|
}
|
|
}
|
|
}
|