ConfigEditFragment: Add extremely basic validation
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
cb48a7be3a
commit
c2189a78b9
@ -73,7 +73,11 @@ public class ConfigEditFragment extends BaseConfigFragment {
|
||||
}
|
||||
|
||||
private void saveConfig() {
|
||||
// FIXME: validate input
|
||||
final String errorMessage = localConfig.validate();
|
||||
if (errorMessage != null) {
|
||||
Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (getCurrentConfig() != null)
|
||||
VpnService.getInstance().update(getCurrentConfig().getName(), localConfig);
|
||||
|
@ -127,4 +127,12 @@ public class Config extends BaseObservable
|
||||
sb.append('\n').append(peer);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String validate() {
|
||||
if (name == null || !isNameValid(name))
|
||||
return "This configuration does not have a valid name.";
|
||||
if (iface.getPublicKey() == null)
|
||||
return "This configuration does not have a valid keypair.";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user