Create SendToken on login

This commit is contained in:
Mike Schwörer 2025-04-13 02:16:24 +02:00
parent e96be86314
commit aac34ef738
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
6 changed files with 42 additions and 7 deletions

View File

@ -413,6 +413,22 @@ class APIClient {
);
}
static Future<KeyTokenWithToken> createKeyToken(TokenSource auth, String name, String perm, bool allChannels, {List<String>? channels}) async {
return await _request(
name: 'createKeyToken',
method: 'POST',
relURL: 'users/${auth.getUserID()}/keys',
jsonBody: {
'name': name,
'pem': perm,
'all_channels': allChannels,
if (channels != null) 'channels': channels,
},
fn: KeyTokenWithToken.fromJson,
authToken: auth.getToken(),
);
}
static Future<List<SenderNameStatistics>> getSenderNameList(TokenSource auth) async {
return await _request(
name: 'getSenderNameList',

View File

@ -40,6 +40,23 @@ class KeyToken {
}
}
class KeyTokenWithToken {
final KeyToken keyToken;
final String token;
KeyTokenWithToken({
required this.keyToken,
required this.token,
});
factory KeyTokenWithToken.fromJson(Map<String, dynamic> json) {
return KeyTokenWithToken(
keyToken: KeyToken.fromJson(json),
token: json['token'] as String,
);
}
}
class KeyTokenPreview {
final String keytokenID;
final String name;

View File

@ -503,7 +503,7 @@ class _AccountRootPageState extends State<AccountRootPage> {
}
void _deleteAccount() async {
//TODO
Toaster.info("Not Implemented", "Account Upgrading will be implemented in a later version"); // TODO
}
void _changeUsername() async {

View File

@ -122,9 +122,9 @@ class _AccountLoginPageState extends State<AccountLoginPage> {
try {
setState(() => loading = true);
final uid = _ctrlUserID.text;
final atokv = _ctrlTokenAdmin.text;
final stokv = _ctrlTokenSend.text;
var uid = _ctrlUserID.text;
var atokv = _ctrlTokenAdmin.text;
var stokv = _ctrlTokenSend.text;
final fcmToken = await FirebaseMessaging.instance.getToken();
@ -147,8 +147,12 @@ class _AccountLoginPageState extends State<AccountLoginPage> {
Toaster.error("Error", 'Send token does not have required permissions');
return;
}
} else {
final toks = await APIClient.createKeyToken(DirectTokenSource(uid, atokv), "SendKey (auto generated by SCN)", "CS", true);
stokv = toks.token;
}
final user = await APIClient.getUser(DirectTokenSource(uid, atokv), uid);
final client = await APIClient.addClient(DirectTokenSource(uid, atokv), fcmToken, Globals().deviceModel, Globals().version, Globals().hostname, Globals().clientType);

View File

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
import 'package:simplecloudnotifier/api/api_client.dart';
import 'package:simplecloudnotifier/models/channel.dart';
import 'package:simplecloudnotifier/models/keytoken.dart';
import 'package:simplecloudnotifier/models/scan_result.dart';
import 'package:simplecloudnotifier/models/user.dart';

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:simplecloudnotifier/state/application_log.dart';
import 'package:simplecloudnotifier/utils/notifier.dart';
import 'package:simplecloudnotifier/utils/toaster.dart';
import 'package:simplecloudnotifier/utils/ui.dart';