Auth view enhanchements: check if port and host are valid

This commit is contained in:
veeso
2021-07-15 13:00:55 +02:00
parent 61f6901767
commit 59c6567ff3
4 changed files with 60 additions and 28 deletions

View File

@@ -25,7 +25,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
use super::{AuthActivity, FileTransferProtocol};
use super::{AuthActivity, FileTransferParams, FileTransferProtocol};
impl AuthActivity {
/// ### protocol_opt_to_enum
@@ -80,4 +80,37 @@ impl AuthActivity {
self.umount_size_err();
}
}
/// ### collect_host_params
///
/// Get input values from fields or return an error if fields are invalid
pub(super) fn collect_host_params(&self) -> Result<FileTransferParams, &'static str> {
let (address, port, protocol, username, password): (
String,
u16,
FileTransferProtocol,
String,
String,
) = self.get_input();
if address.is_empty() {
return Err("Invalid host");
}
if port == 0 {
return Err("Invalid port");
}
Ok(FileTransferParams {
address,
port,
protocol,
username: match username.is_empty() {
true => None,
false => Some(username),
},
password: match password.is_empty() {
true => None,
false => Some(password),
},
entry_directory: None,
})
}
}