]> git.proxmox.com Git - flutter/proxmox_login_manager.git/blob - lib/proxmox_tfa_form.dart
TFA: improve color-readabillity for input
[flutter/proxmox_login_manager.git] / lib / proxmox_tfa_form.dart
1 import 'package:flutter/material.dart';
2 import 'package:proxmox_dart_api_client/proxmox_dart_api_client.dart';
3 import 'package:proxmox_login_manager/proxmox_login_form.dart';
4
5 class ProxmoxTfaForm extends StatefulWidget {
6 final ProxmoxApiClient? apiClient;
7
8 const ProxmoxTfaForm({Key? key, this.apiClient}) : super(key: key);
9
10 @override
11 _ProxmoxTfaFormState createState() => _ProxmoxTfaFormState();
12 }
13
14 class _ProxmoxTfaFormState extends State<ProxmoxTfaForm> {
15 final TextEditingController _codeController = TextEditingController();
16 bool _isLoading = false;
17 @override
18 Widget build(BuildContext context) {
19 return Theme(
20 data: ThemeData.dark().copyWith(
21 colorScheme: ColorScheme.dark().copyWith(
22 secondary: ProxmoxColors.orange,
23 onSecondary: ProxmoxColors.supportGrey)),
24 child: Scaffold(
25 backgroundColor: ProxmoxColors.supportBlue,
26 extendBodyBehindAppBar: true,
27 appBar: AppBar(
28 elevation: 0.0,
29 backgroundColor: Colors.transparent,
30 leading: IconButton(
31 icon: Icon(Icons.close),
32 onPressed: () => Navigator.of(context).pop(),
33 ),
34 ),
35 body: Stack(
36 alignment: Alignment.center,
37 children: [
38 SingleChildScrollView(
39 child: ConstrainedBox(
40 constraints: BoxConstraints.tightFor(
41 height: MediaQuery.of(context).size.height),
42 child: Padding(
43 padding: const EdgeInsets.all(8.0),
44 child: Column(
45 mainAxisAlignment: MainAxisAlignment.start,
46 crossAxisAlignment: CrossAxisAlignment.center,
47 children: <Widget>[
48 Padding(
49 padding: const EdgeInsets.fromLTRB(0, 100.0, 0, 30.0),
50 child: Icon(
51 Icons.lock,
52 size: 48,
53 ),
54 ),
55 Text(
56 'Verify',
57 style: TextStyle(
58 fontSize: 36,
59 color: Colors.white,
60 fontWeight: FontWeight.bold),
61 ),
62 Text(
63 'Check your second factor provider',
64 style: TextStyle(
65 color: Colors.white38, fontWeight: FontWeight.bold),
66 ),
67 Padding(
68 padding: const EdgeInsets.fromLTRB(0, 50.0, 0, 8.0),
69 child: Container(
70 width: 150,
71 child: TextField(
72 controller: _codeController,
73 textAlign: TextAlign.center,
74 decoration: InputDecoration(labelText: 'Code'),
75 autofocus: true,
76 onSubmitted: (value) => _submitTfaCode()),
77 ),
78 ),
79 Expanded(
80 child: Align(
81 alignment: Alignment.bottomCenter,
82 child: Container(
83 width: MediaQuery.of(context).size.width,
84 child: FlatButton(
85 onPressed: () => _submitTfaCode(),
86 color: Color(0xFFE47225),
87 child: Text('Continue'),
88 disabledColor: Colors.grey,
89 ),
90 ),
91 ),
92 ),
93 ],
94 ),
95 ),
96 ),
97 ),
98 if (_isLoading)
99 ProxmoxProgressOverlay(
100 message: 'Verify One-Time password...',
101 )
102 ],
103 ),
104 ),
105 );
106 }
107
108 Future<void> _submitTfaCode() async {
109 setState(() {
110 _isLoading = true;
111 });
112 try {
113 final client =
114 await widget.apiClient!.finishTfaChallenge(_codeController.text);
115 Navigator.of(context).pop(client);
116 } on ProxmoxApiException catch (e) {
117 showDialog(
118 context: context,
119 builder: (context) => ProxmoxApiErrorDialog(
120 exception: e,
121 ),
122 );
123 } catch (e, trace) {
124 print(e);
125 print(trace);
126 showDialog(
127 context: context,
128 builder: (context) => AlertDialog(
129 title: Text('Connection error'),
130 content: Text('Could not establish connection.'),
131 actions: [
132 FlatButton(
133 onPressed: () => Navigator.of(context).pop(),
134 child: Text('Close'),
135 ),
136 ],
137 ),
138 );
139 }
140 setState(() {
141 _isLoading = false;
142 });
143 }
144 }