1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 07:01:59 +00:00

Input validation for email and server endpoint in mobile app (#211)

This commit is contained in:
Matthias Rupp 2022-06-12 05:12:20 +02:00 committed by GitHub
parent 587b77e70b
commit 2bf764f560
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -96,12 +96,20 @@ class ServerEndpointInput extends StatelessWidget {
const ServerEndpointInput({Key? key, required this.controller}) : super(key: key);
String? _validateInput(String? url) {
if (url == null) return null;
if (!url.startsWith(RegExp(r'https?://'))) return 'Please specify http:// or https://';
return null;
}
@override
Widget build(BuildContext context) {
return TextFormField(
controller: controller,
decoration: const InputDecoration(
labelText: 'Server Endpoint URL', border: OutlineInputBorder(), hintText: 'http://your-server-ip:port'),
validator: _validateInput,
autovalidateMode: AutovalidateMode.always,
);
}
}
@ -111,12 +119,22 @@ class EmailInput extends StatelessWidget {
const EmailInput({Key? key, required this.controller}) : super(key: key);
String? _validateInput(String? email) {
if (email == null || email == '') return null;
if (email.endsWith(' ')) return 'Trailing whitespace';
if (email.startsWith(' ')) return 'Leading whitespace';
if (email.contains(' ') || !email.contains('@')) return 'Invalid Email';
return null;
}
@override
Widget build(BuildContext context) {
return TextFormField(
controller: controller,
decoration:
const InputDecoration(labelText: 'Email', border: OutlineInputBorder(), hintText: 'youremail@email.com'),
validator: _validateInput,
autovalidateMode: AutovalidateMode.always,
);
}
}