|
@@ -17,10 +17,25 @@ pub struct FormChangePasswd {
|
|
|
new_password_conf: String,
|
|
new_password_conf: String,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async fn get_template(template_name: String) -> String {
|
|
|
|
|
|
|
+async fn get_template(template_name: String, session: Session) -> String {
|
|
|
|
|
+ let username: Option<String> = session.get("user_id")
|
|
|
|
|
+ .unwrap_or(None);
|
|
|
|
|
+ let user_is_ssh: Option<bool> = session.get("user_is_ssh")
|
|
|
|
|
+ .unwrap_or(None);
|
|
|
|
|
+
|
|
|
let tera = Tera::new("templates/*.html")
|
|
let tera = Tera::new("templates/*.html")
|
|
|
.expect("Failed to parse template files");
|
|
.expect("Failed to parse template files");
|
|
|
- let ctx = tera::Context::new();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ let mut ctx = tera::Context::new();
|
|
|
|
|
+ match username {
|
|
|
|
|
+ Some(username) => ctx.insert("username", &username),
|
|
|
|
|
+ None => (),
|
|
|
|
|
+ }
|
|
|
|
|
+ match user_is_ssh {
|
|
|
|
|
+ Some(user_is_ssh) => ctx.insert("user_is_ssh", &user_is_ssh),
|
|
|
|
|
+ None => (),
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
tera.render(&template_name, &ctx)
|
|
tera.render(&template_name, &ctx)
|
|
|
.expect(format!("Faile to render template {}", template_name).as_str())
|
|
.expect(format!("Faile to render template {}", template_name).as_str())
|
|
|
}
|
|
}
|
|
@@ -47,7 +62,7 @@ pub async fn index(session: Session) -> impl Responder {
|
|
|
.finish();
|
|
.finish();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let body = get_template("signin.html".to_string()).await;
|
|
|
|
|
|
|
+ let body = get_template("signin.html".to_string(), session).await;
|
|
|
HttpResponse::Ok().content_type("text/html")
|
|
HttpResponse::Ok().content_type("text/html")
|
|
|
.body(body)
|
|
.body(body)
|
|
|
}
|
|
}
|
|
@@ -58,6 +73,8 @@ pub async fn auth(ldap_wrapper: web::Data<LdapWrapper>, form: web::Form<FormLogi
|
|
|
.await {
|
|
.await {
|
|
|
Ok(user) => {
|
|
Ok(user) => {
|
|
|
session.insert("user_id", user.uid).unwrap();
|
|
session.insert("user_id", user.uid).unwrap();
|
|
|
|
|
+ session.insert("user_is_ssh", user.is_ssh).unwrap();
|
|
|
|
|
+ session.insert("user_groups", user.groups).unwrap();
|
|
|
return HttpResponse::Ok()
|
|
return HttpResponse::Ok()
|
|
|
.status(StatusCode::FOUND)
|
|
.status(StatusCode::FOUND)
|
|
|
.append_header((header::LOCATION, "/home"))
|
|
.append_header((header::LOCATION, "/home"))
|
|
@@ -74,7 +91,7 @@ pub async fn home(session: Session) -> impl Responder {
|
|
|
.append_header((header::LOCATION, "/"))
|
|
.append_header((header::LOCATION, "/"))
|
|
|
.finish();
|
|
.finish();
|
|
|
}
|
|
}
|
|
|
- let body = get_template("home.html".to_string()).await;
|
|
|
|
|
|
|
+ let body = get_template("home.html".to_string(), session).await;
|
|
|
HttpResponse::Ok().content_type("text/html")
|
|
HttpResponse::Ok().content_type("text/html")
|
|
|
.body(body)
|
|
.body(body)
|
|
|
}
|
|
}
|
|
@@ -86,7 +103,7 @@ pub async fn form_password(session: Session) -> impl Responder {
|
|
|
.append_header((header::LOCATION, "/"))
|
|
.append_header((header::LOCATION, "/"))
|
|
|
.finish();
|
|
.finish();
|
|
|
}
|
|
}
|
|
|
- let body = get_template("formpassword.html".to_string()).await;
|
|
|
|
|
|
|
+ let body = get_template("formpassword.html".to_string(), session).await;
|
|
|
HttpResponse::Ok().content_type("text/html")
|
|
HttpResponse::Ok().content_type("text/html")
|
|
|
.body(body)
|
|
.body(body)
|
|
|
}
|
|
}
|