Commit 5208fb9f authored by wyc's avatar wyc

broken templates

parent ede3d415
......@@ -280,6 +280,46 @@ dependencies = [
"nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "askama"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"askama_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"askama_escape 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"askama_shared 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "askama_derive"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"askama_shared 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "askama_escape"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "askama_shared"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"askama_escape 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "autocfg"
version = "0.1.6"
......@@ -765,6 +805,7 @@ version = "0.1.0"
dependencies = [
"actix-session 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-web 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"askama 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -890,6 +931,11 @@ name = "httparse"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "humansize"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hyper"
version = "0.12.35"
......@@ -1178,6 +1224,15 @@ name = "nodrop"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "nom"
version = "4.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-integer"
version = "0.1.41"
......@@ -2097,6 +2152,14 @@ dependencies = [
"tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
version = "0.5.3"
......@@ -2380,6 +2443,10 @@ dependencies = [
"checksum arc-swap 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f1a1eca3195b729bbd64e292ef2f5fff6b1c28504fed762ce2b1013dde4d8e92"
"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba"
"checksum askama 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3dc2a4b6d7f812d2b13d251ae792caecebd635d6401761162d4b71d5ebe1a010"
"checksum askama_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ee2fff0f22ad5d215cace1227cd036c28e81e26206763bb837b6d0e766c87d"
"checksum askama_escape 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0de942230b5beedaa9e1d64df5b76fa1c97002e4c7982897be899cccf40621d"
"checksum askama_shared 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6dfa6b6d254fd066a8bbed9a8f913123e3f701db89216ad4f0aff04ad87718c"
"checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875"
"checksum awc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "364537de6ac9f996780f9dd097d6c4ca7c91dd5735153e9fb545037479becd10"
"checksum backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "346d7644f0b5f9bc73082d3b2236b69a05fd35cce0cfa3724e184e6a5c9e2a2f"
......@@ -2447,6 +2514,7 @@ dependencies = [
"checksum http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "372bcb56f939e449117fb0869c2e8fd8753a8223d92a172c6e808cf123a5b6e4"
"checksum http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d"
"checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
"checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e"
"checksum hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)" = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6"
"checksum hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f"
"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
......@@ -2479,6 +2547,7 @@ dependencies = [
"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
"checksum nibble_vec 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c8d77f3db4bce033f4d04db08079b2ef1c3d02b44e86f25d08886fafa7756ffa"
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
"checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273"
......@@ -2575,6 +2644,7 @@ dependencies = [
"checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e"
"checksum tokio-udp 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f02298505547f73e60f568359ef0d016d5acd6e830ab9bc7c4a5b3403440121b"
"checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445"
"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f"
"checksum toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c7aabe75941d914b72bf3e5d3932ed92ce0664d49d8432305a8b547c37227724"
"checksum trust-dns 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5a97b39064a4786506e855616a0f8869d461a1cb7449c6064a229eaea4e53b45"
"checksum trust-dns-proto 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f1525ca4e26f5a09d81b79584f19225e7dba5606ae3a416311c2751c5cea60bb"
......
......@@ -27,3 +27,4 @@ failure_derive = "0.1"
diesel = { version = "1.0", features = ["postgres"] }
dotenv = "^0.14"
trust-dns = "^0.14"
askama = "^0.8"
......@@ -8,15 +8,23 @@ use oauth::amazon::{AmazonClientData, AmazonUserProfile, make_amazon_client, use
use oauth::facebook::{FacebookClientData, make_facebook_client, user_authorized_facebook_view, redirect_facebook_auth_view};
use oauth::msgraph::{MSGraphClientData, MSGraphUserProfile, make_msgraph_client, user_authorized_msgraph_view, redirect_msgraph_auth_view};
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder};
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder, http};
use actix_web::error::Result;
use actix_session::{Session, CookieSession};
use serde::Deserialize;
use dotenv;
use verify::Verification;
use std::sync::{Arc, Mutex};
use std::collections::HashMap as Map;
use uuid::Uuid;
use askama::Template;
#[derive(Template)]
#[template(path = "index.html")]
struct Index;
#[derive(Deserialize, Clone)]
struct ServerConfig {
......@@ -34,15 +42,69 @@ struct ServerConfig {
fn index() -> impl Responder {
// TODO: use HttpRequest and generate full url
// maybe there are actix helpers to generate urls
let body = Index.render().unwrap();
HttpResponse::Ok().content_type("text/html").body(body)
}
#[derive(Template)]
#[template(path = "verify_sms.html")]
struct VerifySms<'a> {
phone_number: &'a str,
is_complete: bool,
}
#[derive(Deserialize)]
struct VerifySmsFormData {
phone_number: String,
response: String,
}
fn verify_sms(req: HttpRequest, session: Session,
form: web::Form<VerifySmsFormData>
) -> Result<HttpResponse> {
let new_entry: bool;
println!("verify_sms called");
let mut v = match session.get::<Verification>("verify_sms")? {
Some(verification) => {
new_entry = false;
verification
},
None => {
new_entry = true;
let vt = verify::Type::Twilio{phone_number: "".to_string()};
Verification::new(vt)
},
};
println!("got session stuff");
match req.method() {
&http::Method::POST => {
if let verify::Type::Twilio{phone_number: pn} = v.type_() {
if pn == "" {
}
}
},
_ => (),
}
let phone_number = "555";
let tmpl = VerifySms {
phone_number: phone_number,
is_complete: false,
};
let body = tmpl.render().unwrap();
Ok(HttpResponse::Ok().content_type("text/html").body(body))
}
fn verify_email() -> impl Responder {
HttpResponse::Ok().content_type("text/html").body(
"<a href=\"login/google\"> Get Google credential </a> </br> \
<a href=\"login/amazon\"> Get Amazon credential </a> </br> \
<a href=\"login/facebook\"> Get Facebook email credential </a> </br> \
<a href=\"login/msgraph\"> Get Microsoft Graph credential </a>"
"Verify your phone number! <input type=\"text\"/>"
)
}
fn verify_sms() -> impl Responder {
fn verify_domain() -> impl Responder {
HttpResponse::Ok().content_type("text/html").body(
"Verify your phone number! <input type=\"text\"/>"
)
......@@ -151,10 +213,6 @@ fn main() {
let amazon_client = amazon_client.clone();
let facebook_client = facebook_client.clone();
let msgraph_client = msgraph_client.clone();
let session_db: Arc<Mutex<Map<Uuid, session::Session>>> =
Arc::new(Mutex::new(Map::new()));
let session_key = session_key.as_bytes();
App::new()
.wrap(
......@@ -165,7 +223,9 @@ fn main() {
.secure(false),
)
.route("/", web::get().to(index))
.route("/verify/sms", web::get().to(verify_sms))
.route("/verify/sms", web::to(verify_sms))
.route("/verify/email", web::to(verify_email))
.route("/verify/domain", web::to(verify_domain))
// TODO put these routes into actix web Config structs and expose them in each
// provider's mod
//
......@@ -193,7 +253,6 @@ fn main() {
.data(amazon_client)
.data(facebook_client)
.data(msgraph_client)
.data(session_db)
})
.bind((server_config.bind_address.as_str(), server_config.bind_port))
.expect("Can not bind to address or port")
......
......@@ -86,6 +86,8 @@ impl Verification {
}
}
pub fn type_(&self) -> &Type { &self.type_ }
fn send_twilio_challenge(to_phone_number: &str,
challenge: &str) -> Result<String> {
// curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json \
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>freeclaims.org</title>
</head>
<body>
<h1>Welcome to freeclaims.org! I love you.</h1>
<h3>Verifications</h3>
<p>
<a href="verify/sms">Verify SMS</a><br/>
<a href="verify/email">Verify Email</a><br/>
<a href="verify/domain">Verify Domain</a><br/>
</p>
<h3>OAuth 2.0 Providers</h3>
<p>
<a href="login/google"> Get Google credential </a><br/>
<a href="login/amazon"> Get Amazon credential </a><br/>
<a href="login/facebook"> Get Facebook email credential </a><br/>
<a href="login/msgraph"> Get Microsoft Graph credential </a>
</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>freeclaims.org</title>
</head>
<body>
<h1>SMS Verification</h1>
{% if phone_number == "" -%}
<h3>What is your phone number?</h3>
<form action="/verify/sms" method="post">
<input type="text" name="phone_number" /><br/>
<p><input type="submit"></p>
</form>
{% else if !is_complete -%}
<h3>Please enter the verification code sent to {{ phone_number }}.</h3>
<form action="/verify/sms" method="post">
<input type="text" name="response" /><br/>
<p><input type="submit"></p>
</form>
{% else -%}
<h3>Verification for {{ phone_number }} is complete.</h3>
{% endif -%}
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment