split auth-login & reg-register in dedicated windows
This commit is contained in:
parent
b5f9e6e30e
commit
62a8209064
6 changed files with 223 additions and 95 deletions
|
@ -1,10 +1,15 @@
|
|||
home-menu =
|
||||
.window-title = Home
|
||||
.auth-login = Log in
|
||||
.reg-register = Register a domain
|
||||
|
||||
auth-login =
|
||||
.window-title = Log in
|
||||
.label-username = Username
|
||||
.label-password = Password
|
||||
.submit-button = Log in
|
||||
|
||||
reg-register =
|
||||
.window-title = Register a domain
|
||||
.label-username = Username
|
||||
.label-password = Password
|
||||
.label-domain = Domain
|
||||
.submit-button = Register domain
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
home-menu =
|
||||
.window-title = Accueil
|
||||
.auth-login = Se connecter
|
||||
.reg-register = Enregistrer un domaine
|
||||
|
||||
auth-login =
|
||||
.window-title = Se connecter
|
||||
.label-username = Identifiant
|
||||
.label-password = Clé de passe
|
||||
.submit-button = Connexion
|
||||
|
||||
reg-register =
|
||||
.window-title = Enregistrer un domaine
|
||||
.label-username = Identifiant
|
||||
.label-password = Clé de passe
|
||||
.label-domain = Domaine
|
||||
.submit-button = Enregistrer le domaine
|
||||
|
|
10
src/app.ui
10
src/app.ui
|
@ -10,7 +10,15 @@
|
|||
<property name="valign">GTK_ALIGN_CENTER</property>
|
||||
<property name="halign">GTK_ALIGN_CENTER</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="button-register-domain">
|
||||
<object class="GtkButton" id="button-reg-register">
|
||||
<property name="margin-top">12</property>
|
||||
<property name="margin-bottom">12</property>
|
||||
<property name="margin-start">12</property>
|
||||
<property name="margin-end">12</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="button-auth-login">
|
||||
<property name="margin-top">12</property>
|
||||
<property name="margin-bottom">12</property>
|
||||
<property name="margin-start">12</property>
|
||||
|
|
42
src/auth-login.ui
Normal file
42
src/auth-login.ui
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow" id="window">
|
||||
<child>
|
||||
<object class="GtkBox" id="box">
|
||||
<property name="margin-top">12</property>
|
||||
<property name="margin-bottom">12</property>
|
||||
<property name="margin-start">12</property>
|
||||
<property name="margin-end">12</property>
|
||||
<property name="valign">GTK_ALIGN_CENTER</property>
|
||||
<property name="halign">GTK_ALIGN_CENTER</property>
|
||||
<property name="orientation">GTK_ORIENTATION_VERTICAL</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="username-label">
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="username-entry">
|
||||
<property name="show-emoji-icon">true</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="password-label">
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkPasswordEntry" id="password-entry">
|
||||
<property name="show-peek-icon">true</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="button">
|
||||
<property name="margin-top">12</property>
|
||||
<property name="margin-bottom">12</property>
|
||||
<property name="margin-start">12</property>
|
||||
<property name="margin-end">12</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
230
src/main.rs
230
src/main.rs
|
@ -1,5 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, rc::Rc};
|
||||
|
||||
use glib::clone;
|
||||
use gtk::{
|
||||
glib, prelude::*, Application, ApplicationWindow, Builder, Button, Entry, Label, PasswordEntry,
|
||||
Window,
|
||||
|
@ -23,56 +24,151 @@ fn main() -> glib::ExitCode {
|
|||
app.run()
|
||||
}
|
||||
|
||||
fn build_ui_app(app: &Application) {
|
||||
let ll: FluentLanguageLoader = fluent_language_loader!();
|
||||
i18n_embed::select(
|
||||
&ll,
|
||||
&Localizations,
|
||||
&DesktopLanguageRequester::requested_languages(),
|
||||
)
|
||||
.unwrap();
|
||||
fn build_ui_app(app_init: &Application) {
|
||||
let app = Rc::new(app_init.clone());
|
||||
|
||||
let builder = Builder::from_string(include_str!("app.ui"));
|
||||
|
||||
let button = builder.object::<Button>("button-register-domain").unwrap();
|
||||
|
||||
button.set_label(fl!(ll, "home-menu", "reg-register").as_str());
|
||||
|
||||
let window = builder.object::<ApplicationWindow>("window").unwrap();
|
||||
|
||||
window.set_title(Some(fl!(ll, "home-menu", "window-title").as_str()));
|
||||
|
||||
let app_cloned = app.clone();
|
||||
let window_cloned = window.clone();
|
||||
button.connect_clicked(move |_| {
|
||||
build_ui_login(&ll, &app_cloned, &window_cloned);
|
||||
let ll = Rc::new({
|
||||
let ll_init: FluentLanguageLoader = fluent_language_loader!();
|
||||
i18n_embed::select(
|
||||
&ll_init,
|
||||
&Localizations,
|
||||
&DesktopLanguageRequester::requested_languages(),
|
||||
)
|
||||
.unwrap();
|
||||
ll_init
|
||||
});
|
||||
|
||||
window.set_application(Some(app));
|
||||
let value = std::fs::read_to_string("sn-client.toml")
|
||||
.expect("Unable to read configuration file \"sn-client.toml\".")
|
||||
.parse::<toml::Table>()
|
||||
.unwrap();
|
||||
let installation = Rc::new(value["url"].as_str().unwrap().to_owned());
|
||||
let language = match value.contains_key("language") {
|
||||
false => "en",
|
||||
true => match value["language"].as_str().unwrap() {
|
||||
"en" => "en",
|
||||
"fr" => "fr",
|
||||
_ => panic!("Unsupported language."),
|
||||
},
|
||||
};
|
||||
|
||||
let client = Rc::new({
|
||||
let mut client_builder = reqwest::blocking::Client::builder();
|
||||
if value.contains_key("proxy") {
|
||||
client_builder = client_builder
|
||||
.proxy(reqwest::Proxy::all(value["proxy"].as_str().unwrap()).unwrap());
|
||||
}
|
||||
client_builder
|
||||
.cookie_store(true)
|
||||
.http1_only()
|
||||
.https_only(true)
|
||||
.min_tls_version(reqwest::tls::Version::TLS_1_3)
|
||||
.build()
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
let builder = Builder::from_string(include_str!("app.ui"));
|
||||
let window = Rc::new(builder.object::<ApplicationWindow>("window").unwrap());
|
||||
|
||||
let button_auth_login = builder.object::<Button>("button-auth-login").unwrap();
|
||||
button_auth_login.set_label(fl!(ll, "home-menu", "auth-login").as_str());
|
||||
button_auth_login.connect_clicked(
|
||||
clone!(@strong ll, @strong app, @strong window, @strong client, @strong installation => move |_| {
|
||||
build_ui_auth_login(
|
||||
&ll,
|
||||
&app,
|
||||
&window,
|
||||
&client,
|
||||
&installation,
|
||||
language,
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
let button_reg_register = builder.object::<Button>("button-reg-register").unwrap();
|
||||
button_reg_register.set_label(fl!(ll, "home-menu", "reg-register").as_str());
|
||||
button_reg_register.connect_clicked(
|
||||
clone!(@strong ll, @strong app, @strong window, @strong client, @strong installation => move |_| {
|
||||
build_ui_reg_register(
|
||||
&ll,
|
||||
&app,
|
||||
&window,
|
||||
&client,
|
||||
&installation,
|
||||
language,
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
window.set_title(Some(fl!(ll, "home-menu", "window-title").as_str()));
|
||||
window.set_application(Some(app_init));
|
||||
window.present();
|
||||
}
|
||||
|
||||
fn build_ui_login(ll: &FluentLanguageLoader, app: &Application, transient_for: &ApplicationWindow) {
|
||||
fn build_ui_auth_login(
|
||||
ll: &FluentLanguageLoader,
|
||||
app: &Application,
|
||||
transient_for: &ApplicationWindow,
|
||||
client: &reqwest::blocking::Client,
|
||||
installation: &str,
|
||||
language: &str,
|
||||
) {
|
||||
let builder = Builder::from_string(include_str!("auth-login.ui"));
|
||||
|
||||
let window = builder.object::<Window>("window").unwrap();
|
||||
|
||||
window.set_title(Some(fl!(ll, "auth-login", "window-title").as_str()));
|
||||
|
||||
let username_entry = builder.object::<Entry>("username-entry").unwrap();
|
||||
let password_entry = builder.object::<PasswordEntry>("password-entry").unwrap();
|
||||
|
||||
builder
|
||||
.object::<Label>("username-label")
|
||||
.unwrap()
|
||||
.set_label(fl!(ll, "auth-login", "label-username").as_str());
|
||||
|
||||
builder
|
||||
.object::<Label>("password-label")
|
||||
.unwrap()
|
||||
.set_label(fl!(ll, "auth-login", "label-password").as_str());
|
||||
|
||||
let button = builder.object::<Button>("button").unwrap();
|
||||
button.set_label(fl!(ll, "auth-login", "submit-button").as_str());
|
||||
|
||||
let client_owned = client.to_owned();
|
||||
let installation_owned = installation.to_owned();
|
||||
let language_owned = language.to_owned();
|
||||
button.connect_clicked(move |_| {
|
||||
auth_login(
|
||||
client_owned.to_owned(),
|
||||
installation_owned.to_owned(),
|
||||
language_owned.to_owned(),
|
||||
username_entry.text().to_string(),
|
||||
password_entry.text().to_string(),
|
||||
);
|
||||
});
|
||||
|
||||
window.set_application(Some(app));
|
||||
window.set_transient_for(Some(transient_for));
|
||||
window.present();
|
||||
}
|
||||
|
||||
fn build_ui_reg_register(
|
||||
ll: &FluentLanguageLoader,
|
||||
app: &Application,
|
||||
transient_for: &ApplicationWindow,
|
||||
client: &reqwest::blocking::Client,
|
||||
installation: &str,
|
||||
language: &str,
|
||||
) {
|
||||
let builder = Builder::from_string(include_str!("reg-register.ui"));
|
||||
|
||||
let window = builder.object::<Window>("window").unwrap();
|
||||
|
||||
window.set_title(Some(fl!(ll, "reg-register", "window-title").as_str()));
|
||||
|
||||
let username_entry = builder.object::<Entry>("username-entry").unwrap();
|
||||
let password_entry = builder.object::<PasswordEntry>("password-entry").unwrap();
|
||||
let domain_entry = builder.object::<Entry>("domain-entry").unwrap();
|
||||
|
||||
builder
|
||||
.object::<Label>("username-label")
|
||||
.unwrap()
|
||||
.set_label(fl!(ll, "reg-register", "label-username").as_str());
|
||||
|
||||
builder
|
||||
.object::<Label>("password-label")
|
||||
.unwrap()
|
||||
.set_label(fl!(ll, "reg-register", "label-password").as_str());
|
||||
|
||||
builder
|
||||
.object::<Label>("domain-label")
|
||||
.unwrap()
|
||||
|
@ -81,10 +177,14 @@ fn build_ui_login(ll: &FluentLanguageLoader, app: &Application, transient_for: &
|
|||
let button = builder.object::<Button>("button").unwrap();
|
||||
|
||||
button.set_label(fl!(ll, "reg-register", "submit-button").as_str());
|
||||
let client_owned = client.to_owned();
|
||||
let installation_owned = installation.to_owned();
|
||||
let language_owned = language.to_owned();
|
||||
button.connect_clicked(move |_| {
|
||||
orchestrator(
|
||||
username_entry.text().to_string(),
|
||||
password_entry.text().to_string(),
|
||||
reg_register(
|
||||
client_owned.to_owned(),
|
||||
installation_owned.to_owned(),
|
||||
language_owned.to_owned(),
|
||||
domain_entry.text().to_string(),
|
||||
);
|
||||
});
|
||||
|
@ -94,34 +194,13 @@ fn build_ui_login(ll: &FluentLanguageLoader, app: &Application, transient_for: &
|
|||
window.present();
|
||||
}
|
||||
|
||||
fn orchestrator(username: String, password: String, domain: String) {
|
||||
let value = std::fs::read_to_string("sn-client.toml")
|
||||
.expect("Unable to read configuration file \"sn-client.toml\".")
|
||||
.parse::<toml::Table>()
|
||||
.unwrap();
|
||||
|
||||
let installation = value["url"].as_str().unwrap();
|
||||
let language = match value.contains_key("language") {
|
||||
false => "en",
|
||||
true => match value["language"].as_str().unwrap() {
|
||||
"en" => "en",
|
||||
"fr" => "fr",
|
||||
_ => panic!("Unsupported language."),
|
||||
},
|
||||
};
|
||||
let mut client_builder = reqwest::blocking::Client::builder();
|
||||
if value.contains_key("proxy") {
|
||||
client_builder =
|
||||
client_builder.proxy(reqwest::Proxy::all(value["proxy"].as_str().unwrap()).unwrap());
|
||||
}
|
||||
let client = client_builder
|
||||
.cookie_store(true)
|
||||
.http1_only()
|
||||
.https_only(true)
|
||||
.min_tls_version(reqwest::tls::Version::TLS_1_3)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
fn auth_login(
|
||||
client: reqwest::blocking::Client,
|
||||
installation: String,
|
||||
language: String,
|
||||
username: String,
|
||||
password: String,
|
||||
) {
|
||||
request(
|
||||
"auth/login",
|
||||
HashMap::from([
|
||||
|
@ -129,10 +208,17 @@ fn orchestrator(username: String, password: String, domain: String) {
|
|||
("password", password.clone()),
|
||||
]),
|
||||
&client,
|
||||
installation,
|
||||
language,
|
||||
&installation,
|
||||
&language,
|
||||
);
|
||||
}
|
||||
|
||||
fn reg_register(
|
||||
client: reqwest::blocking::Client,
|
||||
installation: String,
|
||||
language: String,
|
||||
domain: String,
|
||||
) {
|
||||
request(
|
||||
"reg/register",
|
||||
HashMap::from([
|
||||
|
@ -141,8 +227,8 @@ fn orchestrator(username: String, password: String, domain: String) {
|
|||
("action", "register".to_owned()),
|
||||
]),
|
||||
&client,
|
||||
installation,
|
||||
language,
|
||||
&installation,
|
||||
&language,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,24 +10,6 @@
|
|||
<property name="valign">GTK_ALIGN_CENTER</property>
|
||||
<property name="halign">GTK_ALIGN_CENTER</property>
|
||||
<property name="orientation">GTK_ORIENTATION_VERTICAL</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="username-label">
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="username-entry">
|
||||
<property name="show-emoji-icon">true</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="password-label">
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkPasswordEntry" id="password-entry">
|
||||
<property name="show-peek-icon">true</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="domain-label">
|
||||
</object>
|
||||
|
|
Loading…
Add table
Reference in a new issue