From f5a75e3fdfbc5f93dada4cbce63838c29b2cf996 Mon Sep 17 00:00:00 2001 From: User3 Date: Tue, 27 May 2025 12:18:26 +0300 Subject: [PATCH] #sprint-1 changed readme added token service and maked handleLogout service --- README.md | 42 +++--------------------------------------- lib/apis/auth.dart | 1 + lib/apis/tokens.dart | 21 +++++++++++++++++++++ test/server_test.dart | 13 +++++++++++++ 4 files changed, 38 insertions(+), 39 deletions(-) create mode 100644 lib/apis/tokens.dart diff --git a/README.md b/README.md index 4a260d8..70ba3a7 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,3 @@ - - -TODO: Put a short description of the package here that helps potential users -know whether this package might be useful for them. - -## Features - -TODO: List what your package can do. Maybe include images, gifs, or videos. - -## Getting started - -TODO: List prerequisites and provide or point to information on how to -start using the package. - -## Usage - -TODO: Include short and useful examples for package users. Add longer examples -to `/example` folder. - -```dart -const like = 'sample'; -``` - -## Additional information - -TODO: Tell users more about the package: where to find more information, how to -contribute to the package, how to file issues, what response they can expect -from the package authors, and more. +// Тесты в server_test.dart +// Запускать встроенными экшенами +// в apis Лежат все апи структурированно \ No newline at end of file diff --git a/lib/apis/auth.dart b/lib/apis/auth.dart index 10664f0..1dcd906 100644 --- a/lib/apis/auth.dart +++ b/lib/apis/auth.dart @@ -4,6 +4,7 @@ import 'package:server/server.dart'; class Auth { String lastError = ''; + login(String email, String password) async { try { final response = await api.post( diff --git a/lib/apis/tokens.dart b/lib/apis/tokens.dart new file mode 100644 index 0000000..9401294 --- /dev/null +++ b/lib/apis/tokens.dart @@ -0,0 +1,21 @@ +import 'package:dio/dio.dart'; +import 'package:server/client.dart'; + +class Tokens { + String lastError = ''; + + getAccessToken() async { + try { + final response = await api.get('/collections/_authOrigins/records'); + return response.data['items'][0]['id']; + } on DioException catch (e) { + if (e.type == DioExceptionType.connectionError) { + lastError = 'Internet Connection Error'; + } else { + lastError = e.response!.data['message']; + } + } + } +} + +final tokens = Tokens(); diff --git a/test/server_test.dart b/test/server_test.dart index 2b1746b..42b8ee3 100644 --- a/test/server_test.dart +++ b/test/server_test.dart @@ -2,6 +2,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:server/apis/auth.dart'; import 'package:server/apis/cart.dart'; import 'package:server/apis/shop.dart'; +import 'package:server/apis/tokens.dart'; void main() { test('Спринт 2. Авторизация', () async { @@ -72,4 +73,16 @@ void main() { return Error(); } }); + test('Спринт 2.Логаут пользователя', () async { + try { + final currentId = await tokens.getAccessToken(); + if (currentId != null) { + final response = await auth.userLogout(currentId); + return response.data; + } + } catch (e) { + print(e); + return Error(); + } + }); }