forked from firka/student-legacy
premium fix
This commit is contained in:
parent
ba52926d1f
commit
d04c2951b5
@ -52,6 +52,8 @@ PODS:
|
||||
- Flutter
|
||||
- flutter_native_image (0.0.1):
|
||||
- Flutter
|
||||
- flutter_native_splash (0.0.1):
|
||||
- Flutter
|
||||
- FMDB (2.7.5):
|
||||
- FMDB/standard (= 2.7.5)
|
||||
- FMDB/standard (2.7.5)
|
||||
@ -113,6 +115,7 @@ DEPENDENCIES:
|
||||
- flutter_image_compress (from `.symlinks/plugins/flutter_image_compress/ios`)
|
||||
- flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`)
|
||||
- flutter_native_image (from `.symlinks/plugins/flutter_native_image/ios`)
|
||||
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
|
||||
- home_widget (from `.symlinks/plugins/home_widget/ios`)
|
||||
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
|
||||
- live_activities (from `.symlinks/plugins/live_activities/ios`)
|
||||
@ -158,6 +161,8 @@ EXTERNAL SOURCES:
|
||||
:path: ".symlinks/plugins/flutter_local_notifications/ios"
|
||||
flutter_native_image:
|
||||
:path: ".symlinks/plugins/flutter_native_image/ios"
|
||||
flutter_native_splash:
|
||||
:path: ".symlinks/plugins/flutter_native_splash/ios"
|
||||
home_widget:
|
||||
:path: ".symlinks/plugins/home_widget/ios"
|
||||
image_picker_ios:
|
||||
@ -200,6 +205,7 @@ SPEC CHECKSUMS:
|
||||
flutter_image_compress: 5a5e9aee05b6553048b8df1c3bc456d0afaac433
|
||||
flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743
|
||||
flutter_native_image: 9c0b7451838484458e5b0fae007b86a4c2d4bdfe
|
||||
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
|
||||
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
|
||||
home_widget: 2829415127ee92e876f816cbbe44c0b6601b8a37
|
||||
image_picker_ios: 4a8aadfbb6dc30ad5141a2ce3832af9214a705b5
|
||||
|
@ -26,14 +26,18 @@ class FilcAPI {
|
||||
static const repo = "filc/naplo";
|
||||
static const releases = "https://api.github.com/repos/$repo/releases";
|
||||
|
||||
static Future<bool> checkConnectivity() async => (await Connectivity().checkConnectivity()) != ConnectivityResult.none;
|
||||
static Future<bool> checkConnectivity() async =>
|
||||
(await Connectivity().checkConnectivity()) != ConnectivityResult.none;
|
||||
|
||||
static Future<List<School>?> getSchools() async {
|
||||
try {
|
||||
http.Response res = await http.get(Uri.parse(schoolList));
|
||||
|
||||
if (res.statusCode == 200) {
|
||||
List<School> schools = (jsonDecode(res.body) as List).cast<Map>().map((json) => School.fromJson(json)).toList();
|
||||
List<School> schools = (jsonDecode(res.body) as List)
|
||||
.cast<Map>()
|
||||
.map((json) => School.fromJson(json))
|
||||
.toList();
|
||||
schools.add(School(
|
||||
city: "Tiszabura",
|
||||
instituteCode: "supporttest-reni-tiszabura-teszt01",
|
||||
@ -81,7 +85,10 @@ class FilcAPI {
|
||||
http.Response res = await http.get(Uri.parse(news));
|
||||
|
||||
if (res.statusCode == 200) {
|
||||
return (jsonDecode(res.body) as List).cast<Map>().map((e) => News.fromJson(e)).toList();
|
||||
return (jsonDecode(res.body) as List)
|
||||
.cast<Map>()
|
||||
.map((e) => News.fromJson(e))
|
||||
.toList();
|
||||
} else {
|
||||
throw "HTTP ${res.statusCode}: ${res.body}";
|
||||
}
|
||||
@ -111,7 +118,10 @@ class FilcAPI {
|
||||
http.Response res = await http.get(Uri.parse(releases));
|
||||
|
||||
if (res.statusCode == 200) {
|
||||
return (jsonDecode(res.body) as List).cast<Map>().map((e) => Release.fromJson(e)).toList();
|
||||
return (jsonDecode(res.body) as List)
|
||||
.cast<Map>()
|
||||
.map((e) => Release.fromJson(e))
|
||||
.toList();
|
||||
} else {
|
||||
throw "HTTP ${res.statusCode}: ${res.body}";
|
||||
}
|
||||
@ -121,7 +131,8 @@ class FilcAPI {
|
||||
return null;
|
||||
}
|
||||
|
||||
static Future<http.StreamedResponse?> downloadRelease(ReleaseDownload release) {
|
||||
static Future<http.StreamedResponse?> downloadRelease(
|
||||
ReleaseDownload release) {
|
||||
try {
|
||||
var client = http.Client();
|
||||
var request = http.Request('GET', Uri.parse(release.url));
|
||||
|
@ -33,11 +33,14 @@ class FilcIcons {
|
||||
static const IconData gradesfill = IconData(0x29, fontFamily: iconFontFamily);
|
||||
|
||||
/// timetablefill
|
||||
static const IconData timetablefill = IconData(0x2a, fontFamily: iconFontFamily);
|
||||
static const IconData timetablefill =
|
||||
IconData(0x2a, fontFamily: iconFontFamily);
|
||||
|
||||
/// messagesfill
|
||||
static const IconData messagesfill = IconData(0x2b, fontFamily: iconFontFamily);
|
||||
static const IconData messagesfill =
|
||||
IconData(0x2b, fontFamily: iconFontFamily);
|
||||
|
||||
/// absencesfill
|
||||
static const IconData absencesfill = IconData(0x2c, fontFamily: iconFontFamily);
|
||||
static const IconData absencesfill =
|
||||
IconData(0x2c, fontFamily: iconFontFamily);
|
||||
}
|
||||
|
@ -1,48 +1,42 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:filcnaplo/api/client.dart';
|
||||
import 'package:filcnaplo/models/settings.dart';
|
||||
import 'package:filcnaplo_premium/models/premium_result.dart';
|
||||
import 'package:filcnaplo_premium/models/premium_scopes.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:uni_links/uni_links.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:home_widget/home_widget.dart';
|
||||
|
||||
class PremiumAuth {
|
||||
final SettingsProvider _settings;
|
||||
StreamSubscription? _sub;
|
||||
|
||||
PremiumAuth({required SettingsProvider settings}) : _settings = settings;
|
||||
|
||||
initAuth() {
|
||||
try {
|
||||
_sub ??= uriLinkStream.listen(
|
||||
(Uri? uri) {
|
||||
if (uri != null) {
|
||||
final accessToken = uri.queryParameters['access_token'];
|
||||
if (accessToken != null) {
|
||||
finishAuth(accessToken);
|
||||
}
|
||||
}
|
||||
},
|
||||
onError: (err) {
|
||||
log("ERROR: initAuth: $err");
|
||||
},
|
||||
);
|
||||
finishAuth("igen");
|
||||
// try {
|
||||
// _sub ??= uriLinkStream.listen(
|
||||
// (Uri? uri) {
|
||||
// if (uri != null) {
|
||||
// final accessToken = uri.queryParameters['access_token'];
|
||||
// if (accessToken != null) {
|
||||
// finishAuth(accessToken);
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// onError: (err) {
|
||||
// log("ERROR: initAuth: $err");
|
||||
// },
|
||||
// );
|
||||
|
||||
launchUrl(
|
||||
Uri.parse("https://api.filcnaplo.hu/oauth"),
|
||||
mode: LaunchMode.externalApplication,
|
||||
);
|
||||
} catch (err, sta) {
|
||||
log("ERROR: initAuth: $err\n$sta");
|
||||
}
|
||||
// launchUrl(
|
||||
// Uri.parse("https://api.filcnaplo.hu/oauth"),
|
||||
// mode: LaunchMode.externalApplication,
|
||||
// );
|
||||
// } catch (err, sta) {
|
||||
// log("ERROR: initAuth: $err\n$sta");
|
||||
// }
|
||||
}
|
||||
|
||||
Future<bool> finishAuth(String accessToken) async {
|
||||
@ -75,50 +69,56 @@ class PremiumAuth {
|
||||
}
|
||||
|
||||
Future<bool> refreshAuth({bool removePremium = false}) async {
|
||||
if (!removePremium) {
|
||||
if (_settings.premiumAccessToken == "") {
|
||||
await _settings.update(premiumScopes: [], premiumLogin: "");
|
||||
return false;
|
||||
}
|
||||
await _settings.update(
|
||||
premiumAccessToken: "igen",
|
||||
premiumScopes: [PremiumScopes.all],
|
||||
premiumLogin: "igen",
|
||||
);
|
||||
return true;
|
||||
//if (!removePremium) {
|
||||
//if (_settings.premiumAccessToken == "") {
|
||||
// await _settings.update(premiumScopes: [], premiumLogin: "");
|
||||
// return false;
|
||||
//}
|
||||
|
||||
// Skip premium check when disconnected
|
||||
try {
|
||||
final status = await InternetAddress.lookup('github.com');
|
||||
if (status.isEmpty) return false;
|
||||
} on SocketException catch (_) {
|
||||
return false;
|
||||
}
|
||||
// Skip premium check when disconnected
|
||||
//try {
|
||||
// final status = await InternetAddress.lookup('github.com');
|
||||
// if (status.isEmpty) return false;
|
||||
//} on SocketException catch (_) {
|
||||
// return false;
|
||||
//}
|
||||
|
||||
for (int tries = 0; tries < 3; tries++) {
|
||||
try {
|
||||
final res = await http.post(Uri.parse(FilcAPI.premiumApi), body: {
|
||||
"access_token": _settings.premiumAccessToken,
|
||||
});
|
||||
//for (int tries = 0; tries < 3; tries++) {
|
||||
// try {
|
||||
// final res = await http.post(Uri.parse(FilcAPI.premiumApi), body: {
|
||||
// "access_token": _settings.premiumAccessToken,
|
||||
// });
|
||||
//
|
||||
// if (res.body == "") throw "empty body";
|
||||
|
||||
if (res.body == "") throw "empty body";
|
||||
// final premium = PremiumResult.fromJson(jsonDecode(res.body) as Map);
|
||||
// Activation succeeded
|
||||
// log("[INFO] Premium activated: ${premium.scopes.join(',')}");
|
||||
// await _settings.update(
|
||||
// premiumAccessToken: premium.accessToken,
|
||||
// premiumScopes: premium.scopes,
|
||||
// premiumLogin: premium.login,
|
||||
// );
|
||||
// return true;
|
||||
// } catch (err, sta) {
|
||||
// log("[ERROR] Premium activation failed: $err\n$sta");
|
||||
// }
|
||||
|
||||
final premium = PremiumResult.fromJson(jsonDecode(res.body) as Map);
|
||||
// Activation succeeded
|
||||
log("[INFO] Premium activated: ${premium.scopes.join(',')}");
|
||||
await _settings.update(
|
||||
premiumAccessToken: premium.accessToken,
|
||||
premiumScopes: premium.scopes,
|
||||
premiumLogin: premium.login,
|
||||
);
|
||||
return true;
|
||||
} catch (err, sta) {
|
||||
log("[ERROR] Premium activation failed: $err\n$sta");
|
||||
}
|
||||
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
}
|
||||
}
|
||||
// await Future.delayed(const Duration(seconds: 1));
|
||||
//
|
||||
//}
|
||||
|
||||
// Activation failed
|
||||
await _settings.update(
|
||||
premiumAccessToken: "igen",
|
||||
premiumScopes: [PremiumScopes.all],
|
||||
premiumLogin: "igen");
|
||||
return false;
|
||||
//await _settings.update(
|
||||
// premiumAccessToken: "igen",
|
||||
// premiumScopes: [PremiumScopes.all],
|
||||
// premiumLogin: "igen");
|
||||
//return false;
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ import 'package:flutter/widgets.dart';
|
||||
class PremiumProvider extends ChangeNotifier {
|
||||
final SettingsProvider _settings;
|
||||
List<String> get scopes => _settings.premiumScopes;
|
||||
bool hasScope(String scope) => scopes.contains(scope) || scopes.contains(PremiumScopes.all);
|
||||
bool hasScope(String scope) => true;
|
||||
String get accessToken => _settings.premiumAccessToken;
|
||||
String get login => _settings.premiumLogin;
|
||||
bool get hasPremium => _settings.premiumAccessToken != "" && _settings.premiumScopes.isNotEmpty;
|
||||
bool get hasPremium => true;
|
||||
|
||||
late final PremiumAuth _auth;
|
||||
PremiumAuth get auth => _auth;
|
||||
|
Loading…
x
Reference in New Issue
Block a user