f1e88b1ac3
- Add shared_preferences for persisting server URL - Add SettingsService and PlatformService - Add server URL input field on non-web platforms - Make ApiConfig baseUrl configurable at runtime - Add Android location permissions (ACCESS_FINE/COURSE_LOCATION, INTERNET) - Request location permission on login and map init - Fix geo_id type: use String instead of int (UUID format) - Align share_service with API spec: remove unique_id, use share_id only - Fix watch endpoint response: last_update instead of created_at - Add error handling with SnackBars for geo operations - Wrap login screen in SingleChildScrollView for keyboard handling - Update map tile layer with userAgentPackageName for OSM
44 lines
1.1 KiB
Dart
44 lines
1.1 KiB
Dart
import 'dart:convert';
|
|
import 'package:http/http.dart' as http;
|
|
import '../config/api.dart';
|
|
|
|
class AuthService {
|
|
final http.Client _client;
|
|
|
|
AuthService({http.Client? client}) : _client = client ?? http.Client();
|
|
|
|
Future<String> login(String login, String password) async {
|
|
final response = await _client.post(
|
|
Uri.parse(ApiConfig.loginUrl),
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: jsonEncode({'login': login, 'password': password}),
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
return response.body;
|
|
} else {
|
|
throw Exception('Invalid credentials');
|
|
}
|
|
}
|
|
|
|
Future<void> register(
|
|
String login,
|
|
String password,
|
|
String secretKeyHash,
|
|
) async {
|
|
final response = await _client.post(
|
|
Uri.parse(ApiConfig.regUrl),
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: jsonEncode({
|
|
'login': login,
|
|
'password': password,
|
|
'secret_key_hash': secretKeyHash,
|
|
}),
|
|
);
|
|
|
|
if (response.statusCode != 201) {
|
|
throw Exception('Registration failed');
|
|
}
|
|
}
|
|
}
|