mirror of
https://github.com/git-touch/git-touch
synced 2025-01-31 16:14:49 +01:00
feat: login by access token
This commit is contained in:
parent
206e533463
commit
8869c6b456
@ -75,10 +75,10 @@ class AuthModel with ChangeNotifier {
|
||||
}),
|
||||
);
|
||||
final token = json.decode(res.body)['access_token'] as String;
|
||||
await _loginWithToken(token);
|
||||
await loginWithToken(token);
|
||||
}
|
||||
|
||||
Future<void> _loginWithToken(String token) async {
|
||||
Future<void> loginWithToken(String token) async {
|
||||
// Get login and avatar url
|
||||
final queryData = await query('''
|
||||
{
|
||||
|
@ -117,14 +117,14 @@ class ThemeModel with ChangeNotifier {
|
||||
return Navigator.of(context).pushReplacement(StaticRoute(builder: builder));
|
||||
}
|
||||
|
||||
Future<bool> showConfirm(BuildContext context, String text) {
|
||||
Future<bool> showConfirm(BuildContext context, Widget content) {
|
||||
switch (theme) {
|
||||
case AppThemeType.cupertino:
|
||||
return showCupertinoDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return CupertinoAlertDialog(
|
||||
title: Text(text),
|
||||
title: content,
|
||||
actions: <Widget>[
|
||||
CupertinoDialogAction(
|
||||
child: const Text('cancel'),
|
||||
@ -148,10 +148,7 @@ class ThemeModel with ChangeNotifier {
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
content: Text(
|
||||
text,
|
||||
// style: dialogTextStyle
|
||||
),
|
||||
content: content,
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: const Text('CANCEL'),
|
||||
|
@ -66,7 +66,7 @@ class _IssueFormScreenState extends State<IssueFormScreen> {
|
||||
throw 'Create fail, response: ${res.body}';
|
||||
}
|
||||
await Provider.of<ThemeModel>(context)
|
||||
.showConfirm(context, 'Issue created');
|
||||
.showConfirm(context, Text('Issue created'));
|
||||
Navigator.of(context).pop();
|
||||
} catch (err) {
|
||||
print(err); // TODO:
|
||||
|
@ -1,8 +1,11 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/scaffolds/single.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:primer/primer.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../widgets/link.dart';
|
||||
import '../widgets/loading.dart';
|
||||
@ -15,6 +18,8 @@ class LoginScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen> {
|
||||
String _token = '';
|
||||
|
||||
Widget _buildAccountItem(int index) {
|
||||
final settings = Provider.of<AuthModel>(context);
|
||||
final account = settings.accounts[index];
|
||||
@ -73,20 +78,61 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final settings = Provider.of<AuthModel>(context);
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
|
||||
return SingleScaffold(
|
||||
title: AppBarTitle('Select account'),
|
||||
body: settings.loading
|
||||
body: auth.loading
|
||||
? Center(child: Loading())
|
||||
: Container(
|
||||
child: Column(
|
||||
children: [
|
||||
...List.generate(settings.accounts.length, _buildAccountItem),
|
||||
...List.generate(auth.accounts.length, _buildAccountItem),
|
||||
_buildAddItem(
|
||||
text: 'GitHub Account',
|
||||
onTap: settings.redirectToGithubOauth,
|
||||
text: 'GitHub Account by OAuth',
|
||||
onTap: auth.redirectToGithubOauth,
|
||||
),
|
||||
_buildAddItem(
|
||||
text: 'GitHub Account by Token',
|
||||
onTap: () async {
|
||||
var result =
|
||||
await Provider.of<ThemeModel>(context).showConfirm(
|
||||
context,
|
||||
Column(
|
||||
children: <Widget>[
|
||||
CupertinoTextField(
|
||||
placeholder: 'Access token',
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
_token = v;
|
||||
});
|
||||
},
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'GitTouch needs these permissions',
|
||||
style: TextStyle(
|
||||
fontSize: 14, fontWeight: FontWeight.w400),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'user, repo, read:org',
|
||||
style: TextStyle(
|
||||
fontSize: 16, color: PrimerColors.blue500),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
if (result == true) {
|
||||
try {
|
||||
await auth.loginWithToken(_token);
|
||||
} catch (err) {
|
||||
Provider.of<ThemeModel>(context).showConfirm(
|
||||
context, Text('Token invalid: $err'));
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
// _buildAddItem(
|
||||
// text: 'GitLab Account',
|
||||
// screenBuilder: (_) => LoginGitlabScreen(),
|
||||
|
@ -162,7 +162,7 @@ $key: pullRequest(number: ${item.number}) {
|
||||
iconData: Icons.done_all,
|
||||
onTap: () async {
|
||||
var value = await Provider.of<ThemeModel>(context)
|
||||
.showConfirm(context, 'Mark all as read?');
|
||||
.showConfirm(context, Text('Mark all as read?'));
|
||||
if (value) {
|
||||
await Provider.of<AuthModel>(context)
|
||||
.putWithCredentials('/notifications');
|
||||
|
Loading…
x
Reference in New Issue
Block a user