]> git.proxmox.com Git - flutter/proxmox_login_manager.git/commitdiff
catch expired sessions before login
authorTim Marx <t.marx@proxmox.com>
Tue, 22 Sep 2020 10:48:47 +0000 (12:48 +0200)
committerTim Marx <t.marx@proxmox.com>
Tue, 22 Sep 2020 10:48:47 +0000 (12:48 +0200)
Signed-off-by: Tim Marx <t.marx@proxmox.com>
lib/proxmox_login_form.dart
lib/proxmox_login_model.dart
lib/proxmox_tfa_form.dart

index 343348a00d2774021e4a3983eda8da7becb019c5..888ba8f401707bce367fbd68203923ebd99a86a9 100644 (file)
@@ -189,7 +189,7 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
           '${userModel.origin?.host}:${userModel.origin?.port}';
       _accessDomains = _getAccessDomains();
       _usernameController.text = userModel.username;
-      if (widget.ticket.isNotEmpty) {
+      if (widget.ticket.isNotEmpty && userModel.activeSession) {
         _onLoginButtonPressed(ticket: widget.ticket, mRealm: userModel.realm);
       }
     }
@@ -400,6 +400,13 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
             apiClient: client,
           ),
         ));
+
+        if (client == null) {
+          setState(() {
+            _progressModel.inProgress = false;
+          });
+          return;
+        }
       }
 
       final status = await client.getClusterStatus();
index dfc1296298d15dfbea661e646a65b2d449bb6ed4..af7c4fd09529fcad942401e047ad7121fc46d76a 100644 (file)
@@ -73,7 +73,8 @@ abstract class ProxmoxLoginModel
   /// The username with the corresponding realm e.g. root@pam
   String get fullUsername => '$username@$realm';
 
-  bool get activeSession => ticket != null && ticket.isNotEmpty;
+  bool get activeSession =>
+      ticket != null && ticket.isNotEmpty && !ticketExpired();
 
   @nullable
   String get hostname;
@@ -104,6 +105,14 @@ abstract class ProxmoxLoginModel
 
   static Serializer<ProxmoxLoginModel> get serializer =>
       _$proxmoxLoginModelSerializer;
+
+  bool ticketExpired() {
+    final ticketRegex = RegExp(r'(PVE|PMG)(?:QUAR)?:(?:(\S+):)?([A-Z0-9]{8})::')
+        .firstMatch(ticket);
+    final time = DateTime.fromMillisecondsSinceEpoch(
+        int.parse(ticketRegex.group(3), radix: 16) * 1000);
+    return DateTime.now().isAfter(time.add(Duration(hours: 1)));
+  }
 }
 
 class ProxmoxProductType extends EnumClass {
index 71ebddda334da241c38778f3b5e11e8f90ba5329..001cc52c226e37dc13b76e92254a180d460572c5 100644 (file)
@@ -18,9 +18,18 @@ class _ProxmoxTfaFormState extends State<ProxmoxTfaForm> {
   Widget build(BuildContext context) {
     return Theme(
       data: ThemeData.dark().copyWith(accentColor: Color(0xFFE47225)),
-      child: Material(
-        color: Theme.of(context).primaryColor,
-        child: Stack(
+      child: Scaffold(
+        backgroundColor: Theme.of(context).primaryColor,
+        extendBodyBehindAppBar: true,
+        appBar: AppBar(
+          elevation: 0.0,
+          backgroundColor: Colors.transparent,
+          leading: IconButton(
+            icon: Icon(Icons.close),
+            onPressed: () => Navigator.of(context).pop(),
+          ),
+        ),
+        body: Stack(
           alignment: Alignment.center,
           children: [
             SingleChildScrollView(