| 1234567891011121314151617181920212223242526272829303132333435 |
- import 'package:e2ee_chat/network/api.dart';
- import 'profile.dart';
- class UserModel extends ProfileChangeNotifier {
- bool get isLogin => profile.isLogin;
- _login(String token) {
- profile.token = token;
- profile.isLogin = true;
- notifyListeners();
- }
- Future<void> login({String? username, String? password}) async {
- String? token;
- if (username != null && password != null) {
- token = await Api().login(username: username, password: password);
- } else if (!profile.isLogin && profile.username != null) {
- if (profile.token != null) {
- token = await Api().login(username: profile.username!, token: profile.token);
- }
- }
- if (token != null) {
- _login(token);
- }
- }
- Future<bool> logout() async {
- if (profile.isLogin) {
- // TODO: logout
- }
- return false;
- }
- }
|