|
@@ -19,6 +19,11 @@ pub struct FormChangePasswd {
|
|
|
new_password_conf: String,
|
|
new_password_conf: String,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#[derive(Deserialize)]
|
|
|
|
|
+pub struct FormSSHKey {
|
|
|
|
|
+ new_ssh_key: String,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
async fn get_template(template_name: String, session: Session) -> String {
|
|
async fn get_template(template_name: String, session: Session) -> String {
|
|
|
let error_message: Option<String> = session.get("error_message")
|
|
let error_message: Option<String> = session.get("error_message")
|
|
|
.unwrap_or(None);
|
|
.unwrap_or(None);
|
|
@@ -201,10 +206,37 @@ pub async fn form_ssh(ldap_wrapper: web::Data<LdapWrapper>, session: Session) ->
|
|
|
.body(body)
|
|
.body(body)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-pub async fn add_ssh_key(session: Session) -> impl Responder {
|
|
|
|
|
- let body = get_template("sshhomepage.html".to_string(), session).await;
|
|
|
|
|
- HttpResponse::Ok().content_type("text/html")
|
|
|
|
|
- .body(body)
|
|
|
|
|
|
|
+pub async fn add_ssh_key(ldap_wrapper: web::Data<LdapWrapper>, form: web::Form<FormSSHKey>,session: Session) -> impl Responder {
|
|
|
|
|
+ if !validate_session(&session) {
|
|
|
|
|
+ return HttpResponse::Ok()
|
|
|
|
|
+ .status(StatusCode::FOUND)
|
|
|
|
|
+ .append_header((header::LOCATION, "/"))
|
|
|
|
|
+ .finish();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let is_ssh: bool = session.get("user_is_ssh").unwrap_or(None).unwrap();
|
|
|
|
|
+ if !is_ssh {
|
|
|
|
|
+ return HttpResponse::Ok()
|
|
|
|
|
+ .status(StatusCode::FOUND)
|
|
|
|
|
+ .append_header((header::LOCATION, "/"))
|
|
|
|
|
+ .finish();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let uid = session.get("user_id").unwrap().unwrap();
|
|
|
|
|
+
|
|
|
|
|
+ match ldap_wrapper.add_ssh_key(uid, form.new_ssh_key.clone()).await {
|
|
|
|
|
+ Ok(_) => return HttpResponse::Ok()
|
|
|
|
|
+ .status(StatusCode::FOUND)
|
|
|
|
|
+ .append_header((header::LOCATION, "/ssh"))
|
|
|
|
|
+ .finish(),
|
|
|
|
|
+ Err(e) => {
|
|
|
|
|
+ session.insert("error_message", e.to_string()).unwrap();
|
|
|
|
|
+ return HttpResponse::Ok()
|
|
|
|
|
+ .status(StatusCode::FOUND)
|
|
|
|
|
+ .append_header((header::LOCATION, "/ssh"))
|
|
|
|
|
+ .finish()
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
pub async fn del_ssh_key(session: Session) -> impl Responder {
|
|
pub async fn del_ssh_key(session: Session) -> impl Responder {
|