diff --git a/README.md b/README.md new file mode 100644 index 0000000..94f3def --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +![rAuth](./banner.png) diff --git a/Rocket.toml b/Rocket.toml new file mode 100644 index 0000000..95a9c13 --- /dev/null +++ b/Rocket.toml @@ -0,0 +1,2 @@ +[debug] +port = 11111 \ No newline at end of file diff --git a/banner.png b/banner.png new file mode 100644 index 0000000..4a4d343 Binary files /dev/null and b/banner.png differ diff --git a/examples/main.rs b/examples/main.rs index 5659a02..da790b7 100644 --- a/examples/main.rs +++ b/examples/main.rs @@ -7,8 +7,11 @@ async fn main() { let client = Client::with_uri_str("mongodb://localhost:27017/") .await .unwrap(); + let col = client.database("rauth").collection("accounts"); - let auth = rauth::auth::Auth::new(col); + let options = rauth::options::Options::new(); + + let auth = rauth::auth::Auth::new(col, options); rauth::routes::mount(rocket::ignite(), "/", auth) .launch() .await diff --git a/src/auth.rs b/src/auth.rs index 8221009..c046536 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,3 +1,4 @@ +use super::options::Options; use super::db::AccountShort; use super::util::{Error, Result}; @@ -14,6 +15,7 @@ use validator::Validate; pub struct Auth { collection: Collection, + pub options: Options } lazy_static! { @@ -61,8 +63,8 @@ pub struct Login { } impl Auth { - pub fn new(collection: Collection) -> Auth { - Auth { collection } + pub fn new(collection: Collection, options: Options) -> Auth { + Auth { collection, options } } pub async fn create_account(&self, data: Create) -> Result { diff --git a/src/lib.rs b/src/lib.rs index 5243a37..bce08fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,3 +10,4 @@ pub mod auth; pub mod db; pub mod routes; pub mod util; +pub mod options; diff --git a/src/options.rs b/src/options.rs new file mode 100644 index 0000000..69ec015 --- /dev/null +++ b/src/options.rs @@ -0,0 +1,27 @@ +pub struct Options { + pub verified_uri: String, + pub base_url: String +} + +impl Options { + pub fn new() -> Options { + Options { + verified_uri: "https://example.com".to_string(), + base_url: "https://example.com".to_string() + } + } + + pub fn verified_uri(self, verified_uri: String) -> Options { + Options { + verified_uri, + ..self + } + } + + pub fn base_url(self, base_url: String) -> Options { + Options { + base_url, + ..self + } + } +} diff --git a/src/routes.rs b/src/routes.rs index 319fa84..ed083bd 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,5 +1,7 @@ use super::auth::{Auth, Create, Login, Session, Verify}; + use rocket::{Rocket, State}; +use rocket::response::Redirect; use rocket_contrib::json::{Json, JsonValue}; #[post("/create", data = "")] @@ -10,9 +12,9 @@ async fn create(auth: State<'_, Auth>, data: Json) -> super::util::Resul } #[get("/verify/")] -async fn verify(auth: State<'_, Auth>, code: String) -> super::util::Result<()> { +async fn verify(auth: State<'_, Auth>, code: String) -> super::util::Result { auth.inner().verify_account(Verify { code }).await?; - unimplemented!() + Ok(Redirect::to(auth.options.verified_uri.clone())) } #[post("/login", data = "")]