mirror of
https://github.com/zoriya/Aeris.git
synced 2026-06-07 12:26:13 +00:00
Mobile Client: connected Service filter: fix
This commit is contained in:
@@ -64,6 +64,16 @@ class AerisAPI {
|
||||
return createConnection(username, password);
|
||||
}
|
||||
|
||||
Future<bool> createConnectionFromService(Service service, String code) async {
|
||||
http.Response response = await _requestAPI(
|
||||
'/auth/${service.name.toLowerCase()}/signin?code=$code',
|
||||
AerisAPIRequestType.post, {});
|
||||
if (!response.ok) {
|
||||
return false;
|
||||
}
|
||||
return await registerJWT(jsonDecode(response.body)['jwt']);
|
||||
}
|
||||
|
||||
/// On success, sets API as connected to given user. Returns false if connection false
|
||||
Future<bool> createConnection(String username, String password) async {
|
||||
http.Response response =
|
||||
@@ -74,8 +84,11 @@ class AerisAPI {
|
||||
if (!response.ok) {
|
||||
return false;
|
||||
}
|
||||
return await registerJWT(jsonDecode(response.body)['jwt']);
|
||||
}
|
||||
|
||||
Future<bool> registerJWT(String jwt) async {
|
||||
try {
|
||||
final String jwt = jsonDecode(response.body)['jwt'];
|
||||
await GetIt.I<SharedPreferences>().setString('jwt', jwt);
|
||||
_connected = true;
|
||||
_jwt = jwt;
|
||||
@@ -134,6 +147,13 @@ class AerisAPI {
|
||||
return "$baseRoute/auth/$serviceName/url?redirect_uri=$deepLinkRoute/authorization/$serviceName";
|
||||
}
|
||||
|
||||
String getServiceSignInURL(Service service) {
|
||||
final serviceName = service == const Service.youtube()
|
||||
? "google"
|
||||
: service.name.toLowerCase();
|
||||
return "$baseRoute/auth/$serviceName/url?redirect_uri=$deepLinkRoute/authorization/signin/$serviceName";
|
||||
}
|
||||
|
||||
/// Send PUT request to update Pipeline, returns false if failed
|
||||
Future<bool> editPipeline(Pipeline updatedPipeline) async {
|
||||
var res = await _requestAPI('/workflow/${updatedPipeline.id}',
|
||||
|
||||
@@ -29,6 +29,9 @@ class Service {
|
||||
/// Get full url for OAuth2
|
||||
String get authUrl => GetIt.I<AerisAPI>().getServiceAuthURL(this);
|
||||
|
||||
/// Get full url for OAuth2 to register
|
||||
String get authSignInUrl => GetIt.I<AerisAPI>().getServiceSignInURL(this);
|
||||
|
||||
const Service.spotify()
|
||||
: name = "Spotify",
|
||||
url = "https://www.spotify.com",
|
||||
@@ -78,6 +81,7 @@ class Service {
|
||||
static Service factory(String name) {
|
||||
if (name.toLowerCase() == "git") return const Service.github();
|
||||
if (name.toLowerCase() == "ani") return const Service.anilist();
|
||||
if (name.toLowerCase() == "google") return const Service.youtube();
|
||||
for (Service service in Service.all()) {
|
||||
if (service.name.toLowerCase() == name.toLowerCase()) return service;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:aeris/src/aeris_api.dart';
|
||||
import 'package:aeris/src/models/service.dart';
|
||||
import 'package:aeris/src/providers/services_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:loading_indicator/loading_indicator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -11,13 +13,18 @@ class AuthorizationPage extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final route = ModalRoute.of(context)!.settings.name!;
|
||||
final code = Uri.parse(route).queryParameters['code']!;
|
||||
final serviceName = Uri.parse(route).pathSegments.last;
|
||||
final segments = Uri.parse(route).pathSegments;
|
||||
final serviceName = segments.removeLast();
|
||||
final service = Service.factory(serviceName);
|
||||
|
||||
Provider.of<ServiceProvider>(context, listen: false).addService(service, code).then((_) {
|
||||
Provider.of<ServiceProvider>(context, listen: false).notifyListeners();
|
||||
Navigator.pop(context);
|
||||
});
|
||||
if (segments.removeLast() == 'signin') {
|
||||
GetIt.I<AerisAPI>().createConnectionFromService(service, code).then((value) => Navigator.pop(context));
|
||||
} else {
|
||||
Provider.of<ServiceProvider>(context, listen: false).addService(service, code).then((_) {
|
||||
Provider.of<ServiceProvider>(context, listen: false).notifyListeners();
|
||||
Navigator.pop(context);
|
||||
});
|
||||
}
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
child: LoadingIndicator(
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import 'package:aeris/src/aeris_api.dart';
|
||||
import 'package:aeris/main.dart';
|
||||
import 'package:aeris/src/models/service.dart';
|
||||
import 'package:aeris/src/widgets/aeris_page.dart';
|
||||
import 'package:flutter_login/flutter_login.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:line_icons/line_icon.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
/// Login Page Widget
|
||||
class LoginPage extends StatelessWidget {
|
||||
@@ -56,6 +59,17 @@ class LoginPage extends StatelessWidget {
|
||||
},
|
||||
onSubmitAnimationCompleted: () {
|
||||
Navigator.of(context).pushNamedAndRemoveUntil('/home', (route) => false);
|
||||
}));
|
||||
},
|
||||
loginProviders: [
|
||||
for (var service in Service.all().where((element) => element != const Service.utils()).toList())
|
||||
LoginProvider(
|
||||
icon: LineIcon.alternateGithub().icon,
|
||||
label: service.name,
|
||||
callback: () {
|
||||
launch(Uri.parse(service.authSignInUrl).toString(), forceSafariVC: false);
|
||||
}
|
||||
)
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,26 +40,26 @@ class SetupActionPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SetupActionPageState extends State<SetupActionPage> {
|
||||
Service? serviceState;
|
||||
late Service serviceState;
|
||||
List<ActionTemplate>? availableActions;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
serviceState = widget.action.service;
|
||||
availableActions = GetIt.I<AerisAPI>().getActionsFor(serviceState!, widget.action);
|
||||
availableActions = GetIt.I<AerisAPI>().getActionsFor(serviceState, widget.action);
|
||||
}
|
||||
|
||||
Widget serviceDropdown(List<Service> services) {
|
||||
return DropdownButton<Service>(
|
||||
value: serviceState,
|
||||
value: services.contains(serviceState) ? serviceState : services[0],
|
||||
elevation: 8,
|
||||
underline: Container(),
|
||||
onChanged: (service) {
|
||||
setState(() {
|
||||
serviceState = service;
|
||||
serviceState = service!;
|
||||
availableActions =
|
||||
GetIt.I<AerisAPI>().getActionsFor(service!, widget.action);
|
||||
GetIt.I<AerisAPI>().getActionsFor(service, widget.action);
|
||||
});
|
||||
},
|
||||
items: services.map<DropdownMenuItem<Service>>((Service service) {
|
||||
@@ -176,7 +176,7 @@ class _SetupActionPageState extends State<SetupActionPage> {
|
||||
parameters:
|
||||
availableAction.parameters.map((param) {
|
||||
if (widget.action.service.name ==
|
||||
serviceState!.name &&
|
||||
serviceState.name &&
|
||||
widget.action.name ==
|
||||
availableAction.name) {
|
||||
var previousParams = widget.action.parameters
|
||||
@@ -189,7 +189,7 @@ class _SetupActionPageState extends State<SetupActionPage> {
|
||||
return param;
|
||||
}).toList(),
|
||||
onValidate: (parameters) {
|
||||
widget.action.service = serviceState!;
|
||||
widget.action.service = serviceState;
|
||||
widget.action.parameters =
|
||||
ActionParameter.fromJSON(parameters);
|
||||
widget.action.name = availableAction.name;
|
||||
|
||||
@@ -322,6 +322,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.3"
|
||||
line_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: line_icons
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -61,6 +61,7 @@ dependencies:
|
||||
flutter_typeahead: ^3.2.4
|
||||
simple_autocomplete_formfield: ^0.3.0
|
||||
positioned_tap_detector_2: ^1.0.4
|
||||
line_icons: ^2.0.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_launcher_icons: "^0.9.2"
|
||||
|
||||
Reference in New Issue
Block a user