Авторизация-8
This commit is contained in:
parent
0c06f60ab1
commit
7c619d38ac
40
README.md
40
README.md
@ -1,39 +1 @@
|
|||||||
<!--
|
# matule_query
|
||||||
This README describes the package. If you publish this package to pub.dev,
|
|
||||||
this README's contents appear on the landing page for your package.
|
|
||||||
|
|
||||||
For information about how to write a good package README, see the guide for
|
|
||||||
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
|
|
||||||
|
|
||||||
For general information about developing packages, see the Dart guide for
|
|
||||||
[creating packages](https://dart.dev/guides/libraries/create-packages)
|
|
||||||
and the Flutter guide for
|
|
||||||
[developing packages and plugins](https://flutter.dev/to/develop-packages).
|
|
||||||
-->
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
@ -13,4 +13,15 @@ class Client extends Repository {
|
|||||||
? {"Authorization": "Bearer ${_authModel!.token}"}
|
? {"Authorization": "Bearer ${_authModel!.token}"}
|
||||||
: null,
|
: null,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<AuthModel> login(String identity, String password) async {
|
||||||
|
Response response = await dio.post(
|
||||||
|
"$apiUrl/collections/users/auth-with-password",
|
||||||
|
data: {"identity": identity, "password": password},
|
||||||
|
options: options,
|
||||||
|
);
|
||||||
|
_authModel = AuthModel.fromJSON(response.data);
|
||||||
|
return _authModel!;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:matule_query/matule_query.dart';
|
||||||
|
|
||||||
abstract class Repository {
|
abstract class Repository {
|
||||||
final Dio dio = Dio();
|
final Dio dio = Dio();
|
||||||
abstract final String apiUrl;
|
abstract final String apiUrl;
|
||||||
|
|
||||||
|
Future<AuthModel> login(String identity, String password);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ class BaseUseCase {
|
|||||||
final Function(Object?) onResponse;
|
final Function(Object?) onResponse;
|
||||||
final Function(Exception) onError;
|
final Function(Exception) onError;
|
||||||
final QueryHelper helper;
|
final QueryHelper helper;
|
||||||
|
final Client client = Client();
|
||||||
|
|
||||||
BaseUseCase({
|
BaseUseCase({
|
||||||
required this.startLoading,
|
required this.startLoading,
|
||||||
@ -13,4 +14,12 @@ class BaseUseCase {
|
|||||||
required this.onResponse,
|
required this.onResponse,
|
||||||
required this.onError,
|
required this.onError,
|
||||||
}) : helper = QueryHelper(startLoading: startLoading, endLoading: endLoading);
|
}) : helper = QueryHelper(startLoading: startLoading, endLoading: endLoading);
|
||||||
|
|
||||||
|
Future<void> login(String identity, String password) async {
|
||||||
|
await helper.request(
|
||||||
|
() => client.login(identity, password),
|
||||||
|
onResponse,
|
||||||
|
onError,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,13 @@ BaseUseCase useCase = BaseUseCase(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final String _email = "example@test.russ";
|
||||||
|
final String _password = "stringss";
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group("Query", () {
|
group("Query", () {
|
||||||
test("Authorization", () async {});
|
test("Authorization", () async {
|
||||||
|
await useCase.login(_email, _password);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user