mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 11:33:34 +08:00
KeyEditors: Add basic validation
This commit is contained in:
74
lib/setup/key_editors.dart
Normal file
74
lib/setup/key_editors.dart
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class PublicKeyEditor extends StatelessWidget {
|
||||||
|
final TextEditingController controller;
|
||||||
|
|
||||||
|
PublicKeyEditor(this.controller);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 80.0,
|
||||||
|
child: Container(
|
||||||
|
color: Theme.of(context).buttonColor,
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: TextFormField(
|
||||||
|
controller: controller,
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
maxLines: null,
|
||||||
|
style: Theme.of(context).textTheme.body1,
|
||||||
|
autovalidate: true,
|
||||||
|
validator: (String val) {
|
||||||
|
if (!val.startsWith("ssh-")) {
|
||||||
|
return "Invalid Public Key";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PrivateKeyEditor extends StatelessWidget {
|
||||||
|
final TextEditingController controller;
|
||||||
|
|
||||||
|
PrivateKeyEditor(this.controller);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 80.0,
|
||||||
|
child: Container(
|
||||||
|
color: Theme.of(context).buttonColor,
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: TextFormField(
|
||||||
|
controller: controller,
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
maxLines: null,
|
||||||
|
style: Theme.of(context).textTheme.body1,
|
||||||
|
autovalidate: true,
|
||||||
|
validator: (String val) {
|
||||||
|
if (!val.startsWith("-----BEGIN RSA PRIVATE KEY-----")) {
|
||||||
|
return "Invalid Private Key";
|
||||||
|
}
|
||||||
|
if (!val.startsWith("-----END RSA PRIVATE KEY-----")) {
|
||||||
|
return "Invalid Private Key";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ import 'package:function_types/function_types.dart';
|
|||||||
|
|
||||||
import 'button.dart';
|
import 'button.dart';
|
||||||
import 'loading.dart';
|
import 'loading.dart';
|
||||||
|
import 'key_editors.dart';
|
||||||
|
|
||||||
class GitHostSetupSshKeyKnownProvider extends StatelessWidget {
|
class GitHostSetupSshKeyKnownProvider extends StatelessWidget {
|
||||||
final Func0<void> doneFunction;
|
final Func0<void> doneFunction;
|
||||||
@ -219,13 +220,14 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
|||||||
style: Theme.of(context).textTheme.headline,
|
style: Theme.of(context).textTheme.headline,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8.0),
|
const SizedBox(height: 8.0),
|
||||||
KeyEditor(_publicKeyController),
|
PublicKeyEditor(_publicKeyController),
|
||||||
const SizedBox(height: 8.0),
|
const SizedBox(height: 8.0),
|
||||||
Text(
|
Text(
|
||||||
"Private Key -",
|
"Private Key -",
|
||||||
style: Theme.of(context).textTheme.headline,
|
style: Theme.of(context).textTheme.headline,
|
||||||
),
|
),
|
||||||
KeyEditor(_privateKeyController),
|
const SizedBox(height: 8.0),
|
||||||
|
PrivateKeyEditor(_privateKeyController),
|
||||||
const SizedBox(height: 16.0),
|
const SizedBox(height: 16.0),
|
||||||
GitHostSetupButton(
|
GitHostSetupButton(
|
||||||
text: "Next",
|
text: "Next",
|
||||||
@ -243,35 +245,6 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: vHanda: Add validation
|
|
||||||
class KeyEditor extends StatelessWidget {
|
|
||||||
final TextEditingController controller;
|
|
||||||
|
|
||||||
KeyEditor(this.controller);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
height: 80.0,
|
|
||||||
child: Container(
|
|
||||||
color: Theme.of(context).buttonColor,
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: TextField(
|
|
||||||
controller: controller,
|
|
||||||
textAlign: TextAlign.left,
|
|
||||||
maxLines: null,
|
|
||||||
style: Theme.of(context).textTheme.body1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PublicKeyWidget extends StatelessWidget {
|
class PublicKeyWidget extends StatelessWidget {
|
||||||
final String publicKey;
|
final String publicKey;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user