43 lines
1.2 KiB
Dart
43 lines
1.2 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:get/get.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import '../models/user_model.dart';
|
|
|
|
class ServiceRepos{
|
|
final http.Client httpClient;
|
|
final String baseUrl = 'https://node.joshihomeserver.ipv64.net/api';
|
|
|
|
ServiceRepos({required this.httpClient});
|
|
|
|
Future<http.Response> getUsersList() {
|
|
return httpClient.get(
|
|
Uri.parse('$baseUrl/GetFilamentUsers'),
|
|
headers: {'Content-Type': 'application/json'},
|
|
);
|
|
}
|
|
|
|
Future<UserModel> loginService(String username, String password) async {
|
|
|
|
final responseUser = await getUsersList();
|
|
|
|
if (responseUser.statusCode != 200) {
|
|
return UserModel(uuid: '', username: '', passwort: '');
|
|
}
|
|
|
|
final users = responseUser.body.isNotEmpty
|
|
? List<Map<String, dynamic>>.from(json.decode(responseUser.body))
|
|
: <Map<String, dynamic>>[];
|
|
|
|
List<UserModel> userModels = users.map((u) => UserModel.fromMap(u)).toList();
|
|
|
|
final UserModel? searchUser = userModels.firstWhereOrNull(
|
|
(u) => u.username == username && u.passwort == password);
|
|
|
|
if (searchUser == null || searchUser.uuid.isEmpty) {
|
|
return UserModel(uuid: '', username: '', passwort: '');
|
|
}
|
|
|
|
return searchUser;
|
|
}
|
|
} |