[fractal/fractal-next] login: Add https:// to homeserver if not present
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] login: Add https:// to homeserver if not present
- Date: Tue, 22 Jun 2021 12:48:49 +0000 (UTC)
commit da7642500f4f54c95931b8161fc4e835caaf5743
Author: giusdp <depalma gsp gmail com>
Date: Tue Jun 22 14:15:20 2021 +0200
login: Add https:// to homeserver if not present
Add build_homeserver_url function to check if homeserver string
starts with http:// or https://, if not https:// is added, and
parse it as Url. It is used both to check the url to enable
the Next action and to login the user.
src/login.rs | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/src/login.rs b/src/login.rs
index d8b4e727..e458bf8a 100644
--- a/src/login.rs
+++ b/src/login.rs
@@ -7,6 +7,7 @@ use gtk::subclass::prelude::*;
use gtk::{self, prelude::*};
use gtk::{glib, glib::clone, CompositeTemplate};
use log::debug;
+use url::{ParseError, Url};
mod imp {
use super::*;
@@ -102,7 +103,7 @@ impl Login {
self.action_set_enabled(
"login.next",
homeserver.len() != 0
- && url::Url::parse(homeserver.as_str()).is_ok()
+ && build_homeserver_url(homeserver.as_str()).is_ok()
&& username != 0
&& password != 0,
);
@@ -139,7 +140,7 @@ impl Login {
}));
session.login_with_password(
- url::Url::parse(homeserver.as_str()).unwrap(),
+ build_homeserver_url(homeserver.as_str()).unwrap(),
username,
password,
);
@@ -186,3 +187,11 @@ impl Login {
.unwrap()
}
}
+
+fn build_homeserver_url(server: &str) -> Result<Url, ParseError> {
+ if server.starts_with("http://") || server.starts_with("https://") {
+ Url::parse(server)
+ } else {
+ Url::parse(&format!("https://{}", server))
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]