mirror of
https://github.com/git-touch/git-touch
synced 2025-01-29 07:10:28 +01:00
improvement: save gitlab id
This commit is contained in:
parent
396fe550c4
commit
259d25d376
@ -10,6 +10,7 @@ class Account {
|
||||
String token;
|
||||
String login;
|
||||
String avatarUrl;
|
||||
int gitlabId;
|
||||
|
||||
equals(Account a) {
|
||||
final uri = Uri.parse(domain);
|
||||
@ -18,6 +19,7 @@ class Account {
|
||||
// Treat domains as the same if they have the same hosts and ports
|
||||
return a.platform == platform &&
|
||||
a.login == login &&
|
||||
a.gitlabId == gitlabId &&
|
||||
uri.host == uriA.host &&
|
||||
uri.port == uriA.port;
|
||||
}
|
||||
@ -28,6 +30,7 @@ class Account {
|
||||
@required this.token,
|
||||
@required this.login,
|
||||
@required this.avatarUrl,
|
||||
this.gitlabId,
|
||||
});
|
||||
|
||||
factory Account.fromJson(Map<String, dynamic> json) =>
|
||||
|
@ -13,6 +13,7 @@ Account _$AccountFromJson(Map<String, dynamic> json) {
|
||||
token: json['token'] as String,
|
||||
login: json['login'] as String,
|
||||
avatarUrl: json['avatarUrl'] as String,
|
||||
gitlabId: json['gitlabId'] as int,
|
||||
);
|
||||
}
|
||||
|
||||
@ -22,4 +23,5 @@ Map<String, dynamic> _$AccountToJson(Account instance) => <String, dynamic>{
|
||||
'token': instance.token,
|
||||
'login': instance.login,
|
||||
'avatarUrl': instance.avatarUrl,
|
||||
'gitlabId': instance.gitlabId,
|
||||
};
|
||||
|
@ -15,6 +15,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../utils/constants.dart';
|
||||
import '../utils/utils.dart';
|
||||
import 'account.dart';
|
||||
import 'gitlab.dart';
|
||||
|
||||
class PlatformType {
|
||||
static const github = 'github';
|
||||
@ -111,17 +112,18 @@ class AuthModel with ChangeNotifier {
|
||||
final res = await http
|
||||
.get('$domain/api/v4/user', headers: {'Private-Token': token});
|
||||
final info = json.decode(res.body);
|
||||
|
||||
if (info['message'] != null) {
|
||||
throw info['message'];
|
||||
}
|
||||
final user = GitlabUser.fromJson(info);
|
||||
|
||||
await _addAccount(Account(
|
||||
platform: PlatformType.gitlab,
|
||||
domain: domain,
|
||||
token: token,
|
||||
login: info['username'] as String,
|
||||
avatarUrl: info['avatar_url'] as String,
|
||||
login: user.username,
|
||||
avatarUrl: user.avatarUrl,
|
||||
gitlabId: user.id,
|
||||
));
|
||||
} catch (err) {
|
||||
Fimber.e('loginToGitlab failed', ex: err);
|
||||
|
Loading…
x
Reference in New Issue
Block a user