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:
parent
587b77e70b
commit
2bf764f560
1 changed files with 18 additions and 0 deletions
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue