forked from jmug/stoatchat
no
This commit is contained in:
@@ -1,22 +1,40 @@
|
||||
use crate::auth::User;
|
||||
use crate::database;
|
||||
use bson::{ bson, doc, ordered::OrderedDocument };
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use rocket_contrib::json::{ Json, JsonValue };
|
||||
use bson::{ bson, doc };
|
||||
|
||||
#[get("/")]
|
||||
pub fn root() -> String {
|
||||
let client = database::get_connection();
|
||||
let cursor = client.database("revolt").collection("users").find(None, None).unwrap();
|
||||
pub fn root(user: User) -> String {
|
||||
let User ( id, username, _doc ) = user;
|
||||
|
||||
let results: Vec<Result<OrderedDocument, mongodb::error::Error>> = cursor.collect();
|
||||
|
||||
format!("ok boomer, users: {}", results.len())
|
||||
format!("hello, {}! [id: {}]", username, id)
|
||||
}
|
||||
|
||||
#[get("/reg")]
|
||||
pub fn reg() -> String {
|
||||
let client = database::get_connection();
|
||||
let col = client.database("revolt").collection("users");
|
||||
|
||||
col.insert_one(doc! { "username": "test" }, None).unwrap();
|
||||
|
||||
format!("inserted")
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Create {
|
||||
username: String,
|
||||
password: String,
|
||||
email: String,
|
||||
}
|
||||
|
||||
#[post("/create", data = "<info>")]
|
||||
pub fn create(info: Json<Create>) -> JsonValue {
|
||||
let col = database::get_db().collection("users");
|
||||
|
||||
if let Some(_) =
|
||||
col.find_one(Some(
|
||||
doc! { "email": info.email.clone() }
|
||||
), None).unwrap() {
|
||||
|
||||
return json!({
|
||||
"success": false,
|
||||
"error": "Email already in use!"
|
||||
})
|
||||
}
|
||||
|
||||
json!({
|
||||
"success": true
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,5 +4,5 @@ mod account;
|
||||
|
||||
pub fn mount(rocket: Rocket) -> Rocket {
|
||||
rocket
|
||||
.mount("/api/v1", routes![account::root, account::reg])
|
||||
.mount("/api/account", routes![ account::root, account::create ])
|
||||
}
|
||||
|
||||
22
src/routes/old.rs
Normal file
22
src/routes/old.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use crate::database;
|
||||
use bson::{ bson, doc, ordered::OrderedDocument };
|
||||
|
||||
#[get("/")]
|
||||
pub fn root() -> String {
|
||||
let client = database::get_connection();
|
||||
let cursor = client.database("revolt").collection("users").find(None, None).unwrap();
|
||||
|
||||
let results: Vec<Result<OrderedDocument, mongodb::error::Error>> = cursor.collect();
|
||||
|
||||
format!("ok boomer, users: {}", results.len())
|
||||
}
|
||||
|
||||
#[get("/reg")]
|
||||
pub fn reg() -> String {
|
||||
let client = database::get_connection();
|
||||
let col = client.database("revolt").collection("users");
|
||||
|
||||
col.insert_one(doc! { "username": "test" }, None).unwrap();
|
||||
|
||||
format!("inserted")
|
||||
}
|
||||
Reference in New Issue
Block a user