changeset 7:ebcf9edce874

Add 'secret' column
author Lewin Bormann <lbo@spheniscida.de>
date Tue, 01 Dec 2020 20:28:22 +0100
parents 6b97ebb6ee9c
children a5de18a5e99e
files TODO pgsql_schema.sql src/main.rs
diffstat 3 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/TODO	Tue Dec 01 20:20:59 2020 +0100
+++ b/TODO	Tue Dec 01 20:28:22 2020 +0100
@@ -1,4 +1,5 @@
 * notify via dynamic channels? static channels? polling?
+* password/secret protection
 
 FEATURES
 
--- a/pgsql_schema.sql	Tue Dec 01 20:20:59 2020 +0100
+++ b/pgsql_schema.sql	Tue Dec 01 20:28:22 2020 +0100
@@ -28,6 +28,7 @@
 
 CREATE TABLE geohub.geodata (
     id text not null,
+    secret text,
     lat double precision,
     long double precision,
     spd double precision,
--- a/src/main.rs	Tue Dec 01 20:20:59 2020 +0100
+++ b/src/main.rs	Tue Dec 01 20:28:22 2020 +0100
@@ -31,14 +31,15 @@
     None
 }
 
-/// lat, long are floats
 /// time is like 2020-11-30T20:12:36.444Z (ISO 8601). By default, server time is set.
-#[rocket::get("/geo/<name>/log?<lat>&<longitude>&<time>&<s>&<ele>")]
-fn hello(
+/// secret can be used to protect points.
+#[rocket::get("/geo/<name>/log?<lat>&<longitude>&<time>&<s>&<ele>&<secret>")]
+fn log(
     db: DBConn,
     name: String,
     lat: f64,
     longitude: f64,
+    secret: Option<String>,
     time: Option<String>,
     s: Option<f64>,
     ele: Option<f64>,
@@ -51,8 +52,8 @@
         ts = flexible_timestamp_parse(time).unwrap_or(ts);
     }
     db.0.execute(
-        "INSERT INTO geohub.geodata (id, lat, long, spd, t, ele) VALUES ($1, $2, $3, $4, $5, $6)",
-        &[&name, &lat, &longitude, &s, &ts, &ele],
+        "INSERT INTO geohub.geodata (id, lat, long, spd, t, ele, secret) VALUES ($1, $2, $3, $4, $5, $6, $7)",
+        &[&name, &lat, &longitude, &s, &ts, &ele, &secret],
     )
     .unwrap();
     rocket::http::Status::Ok
@@ -61,6 +62,6 @@
 fn main() {
     rocket::ignite()
         .attach(DBConn::fairing())
-        .mount("/", rocket::routes![hello])
+        .mount("/", rocket::routes![log])
         .launch();
 }