Add option struct and README

This commit is contained in:
Paul
2021-01-25 12:56:05 +00:00
parent 7583ebc030
commit c000adcf06
8 changed files with 43 additions and 5 deletions
+1
View File
@@ -0,0 +1 @@
![rAuth](./banner.png)
+2
View File
@@ -0,0 +1,2 @@
[debug]
port = 11111
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

+4 -1
View File
@@ -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
+4 -2
View File
@@ -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<String> {
+1
View File
@@ -10,3 +10,4 @@ pub mod auth;
pub mod db;
pub mod routes;
pub mod util;
pub mod options;
+27
View File
@@ -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
}
}
}
+4 -2
View File
@@ -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 = "<data>")]
@@ -10,9 +12,9 @@ async fn create(auth: State<'_, Auth>, data: Json<Create>) -> super::util::Resul
}
#[get("/verify/<code>")]
async fn verify(auth: State<'_, Auth>, code: String) -> super::util::Result<()> {
async fn verify(auth: State<'_, Auth>, code: String) -> super::util::Result<Redirect> {
auth.inner().verify_account(Verify { code }).await?;
unimplemented!()
Ok(Redirect::to(auth.options.verified_uri.clone()))
}
#[post("/login", data = "<data>")]