79 lines
3.1 KiB
Dart
79 lines
3.1 KiB
Dart
|
|
import 'dart:convert';
|
|
import 'dart:developer';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:crypto/crypto.dart';
|
|
import 'package:fast_rsa/fast_rsa.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:persistent_bottom_nav_bar/persistent_tab_view.dart';
|
|
|
|
import '../../../model/endpointData.dart';
|
|
import '../../../widget/ListItem.dart';
|
|
import '../../../widget/debug/debugTile.dart';
|
|
import '../../settings/settings.dart';
|
|
import 'gradeAverages/gradeAverage.dart';
|
|
import 'holidays/holidays.dart';
|
|
import 'message/message.dart';
|
|
import 'roomplan/roomplan.dart';
|
|
|
|
class Overhang extends StatelessWidget {
|
|
const Overhang({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text("Mehr"),
|
|
actions: [
|
|
IconButton(onPressed: () => PersistentNavBarNavigator.pushNewScreen(context, screen: const Settings(), withNavBar: false), icon: const Icon(Icons.settings))
|
|
],
|
|
),
|
|
body: ListView(
|
|
children: [
|
|
const ListItemNavigator(icon: Icons.newspaper, text: "Marianum Message", target: Message()),
|
|
const ListItemNavigator(icon: Icons.room, text: "Raumplan", target: Roomplan()),
|
|
const ListItemNavigator(icon: Icons.calculate, text: "Notendurschnittsrechner", target: GradeAverage()),
|
|
const ListItemNavigator(icon: Icons.calendar_month, text: "Schulferien", target: Holidays()),
|
|
DebugTile(context, onlyInDebug: true).callback(onTab: () async {
|
|
log("Starting");
|
|
log("Generate keys");
|
|
final rsaKey = await RSA.generate(2048);
|
|
final devicePrivateKey = rsaKey.privateKey.toString();
|
|
final devicePublicKey = rsaKey.publicKey.toString();
|
|
log("Private: \n$devicePrivateKey");
|
|
log("Public: \n$devicePublicKey");
|
|
final pushToken = await FirebaseMessaging.instance.getToken();
|
|
log("PushToken: $pushToken}");
|
|
final pushTokenHash = sha512.convert(utf8.encode(pushToken!));
|
|
log("PushTokenHash: $pushTokenHash");
|
|
|
|
final requestMap = {
|
|
"format": "json",
|
|
"pushTokenHash": pushTokenHash.toString(),
|
|
"devicePublicKey": devicePublicKey.toString(),
|
|
"proxyServer": "https://push-notifications.nextcloud.com/devices"
|
|
};
|
|
|
|
log(jsonEncode(requestMap));
|
|
http.post(
|
|
//${AccountData().buildHttpAuthString()}@
|
|
Uri.parse("https://${EndpointData().nextcloud().full()}/ocs/v2.php/apps/notifications/api/v2/push"),
|
|
headers: {
|
|
"OCS-APIRequest": "true",
|
|
"Content-Type": "application/json",
|
|
"Accept": "application/json",
|
|
"Authorization": "Bearer Fv3g7g9jW91FXNjZLaJmyprClfy8pX1jEM3hJGbXjPEFcx4oGIEVcpwEnuT4mPs39D9xT063"
|
|
},
|
|
body: jsonEncode(requestMap),
|
|
).then((response) {
|
|
log("Response: ${response.statusCode}\n${response.body}");
|
|
});
|
|
}),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|