This repository has been archived on 2022-04-20. You can view files and clone it, but cannot push or open issues or pull requests.
app/lib/api/user_implementation.dart

37 lines
1.1 KiB
Dart

import 'dart:async';
import 'package:vikunja_app/api/client.dart';
import 'package:vikunja_app/api/service.dart';
import 'package:vikunja_app/models/user.dart';
import 'package:vikunja_app/service/services.dart';
class UserAPIService extends APIService implements UserService {
UserAPIService(Client client) : super(client);
@override
Future<UserTokenPair> login(String username, password) async {
var token = await client.post('/login', body: {
'username': username,
'password': password
}).then((map) => map['token']);
return UserAPIService(Client(token, client.base))
.getCurrentUser()
.then((user) => UserTokenPair(user, token));
}
@override
Future<UserTokenPair> register(String username, email, password) async {
var newUser = await client.post('/register', body: {
'username': username,
'email': email,
'password': password
}).then((resp) => resp['username']);
return login(newUser, password);
}
@override
Future<User> getCurrentUser() {
return client.get('/user').then((map) => User.fromJson(map));
}
}