ConfigEditFragment: Add extremely basic validation

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-08-17 03:32:01 -05:00
parent cb48a7be3a
commit c2189a78b9
2 changed files with 13 additions and 1 deletions

View File

@ -73,7 +73,11 @@ public class ConfigEditFragment extends BaseConfigFragment {
} }
private void saveConfig() { private void saveConfig() {
// FIXME: validate input final String errorMessage = localConfig.validate();
if (errorMessage != null) {
Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show();
return;
}
try { try {
if (getCurrentConfig() != null) if (getCurrentConfig() != null)
VpnService.getInstance().update(getCurrentConfig().getName(), localConfig); VpnService.getInstance().update(getCurrentConfig().getName(), localConfig);

View File

@ -127,4 +127,12 @@ public class Config extends BaseObservable
sb.append('\n').append(peer); sb.append('\n').append(peer);
return sb.toString(); 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;
}
} }