Interface de connexion avec connexion réussie au serveur
This commit is contained in:
@@ -10,6 +10,30 @@ class UserRemoteDataSource {
|
||||
|
||||
UserRemoteDataSource(this.client);
|
||||
|
||||
Future<UserModel> authenticateUser(String email, String password) async {
|
||||
if (email.isEmpty || password.isEmpty) {
|
||||
throw Exception('Email ou mot de passe vide');
|
||||
}
|
||||
|
||||
final response = await client.post(
|
||||
Uri.parse('${Urls.baseUrl}/users/authenticate'),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: jsonEncode({
|
||||
'email': email,
|
||||
'motDePasse': password,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final jsonResponse = json.decode(response.body);
|
||||
return UserModel.fromJson(jsonResponse);
|
||||
} else if (response.statusCode == 401) {
|
||||
throw AuthenticationException('Email ou mot de passe incorrect');
|
||||
} else {
|
||||
throw ServerException();
|
||||
}
|
||||
}
|
||||
|
||||
Future<UserModel> getUser(String id) async {
|
||||
final response = await client.get(Uri.parse('${Urls.baseUrl}/user/$id'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user