aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-11-11 01:38:00 +0100
committerTeddy Wing2018-11-11 01:47:54 +0100
commitf21e06fa26880166ec4df467ee4723503dfbad55 (patch)
tree71d3abac51ef0e46deb652b821176325e9919997
parente17cffd340476470546e5c27ff03fa134b6e2236 (diff)
downloaddome-key-web-f21e06fa26880166ec4df467ee4723503dfbad55.tar.bz2
main(): Insert purchaser into datatabase (WIP)
This currently errors on a borrow problem with the `cx` in the closure. Here we get the purchaser name and email from the POST params and insert them as a record in the database. If all goes well, we respond with a 200. Otherwise we log errors and respond with 500.
-rw-r--r--license-generator/src/main.rs41
1 files changed, 34 insertions, 7 deletions
diff --git a/license-generator/src/main.rs b/license-generator/src/main.rs
index 3fe03ed..d18b880 100644
--- a/license-generator/src/main.rs
+++ b/license-generator/src/main.rs
@@ -64,12 +64,6 @@ fn main() -> Result<()> {
},
};
- let test_purchaser = Purchaser::new("Shiki", "shiki@example.com");
- match test_purchaser.insert(&mut cx) {
- Ok(_) => (),
- Err(e) => error!("{}", e),
- }
-
fastcgi::run(|mut req| {
let mut params = String::new();
match req.stdin().read_to_string(&mut params) {
@@ -120,9 +114,42 @@ fn main() -> Result<()> {
};
if is_verified {
+ let name = ps.get("name");
+ let email = ps.get("email");
+
+ if name.is_some() && email.is_some() {
+ let purchaser = Purchaser::new(name.unwrap(), email.unwrap());
+ match purchaser.insert(&mut cx) {
+ Ok(_) => {
+ // TODO: Print message to be appended to user email
+
+ write!(&mut req.stdout(), "Content-Type: text/plain
+
+200 OK")
+ .unwrap_or(());
+
+ return;
+ },
+ Err(e) => {
+ error!("{}", e);
+
+ response::set_500(&mut req.stdout()).unwrap_or(());
+ write!(&mut req.stdout(), "Content-Type: text/plain
+
+500 Internal Server Error")
+ .unwrap_or(());
+
+ return;
+ },
+ }
+ }
+
+ error!("Purchaser name or email not set");
+
+ response::set_500(&mut req.stdout()).unwrap_or(());
write!(&mut req.stdout(), "Content-Type: text/plain
- 200 OK")
+500 Internal Server Error")
.unwrap_or(());
return;