Initial commit: family safety frontend project setup
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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) async {
|
||||
final response = await _client.post(
|
||||
Uri.parse(ApiConfig.regUrl),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: jsonEncode({'login': login, 'password': password}),
|
||||
);
|
||||
|
||||
if (response.statusCode != 201) {
|
||||
throw Exception('Registration failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user