chatapp
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
use rocket::{post, serde::json::Json};
|
||||
use rocket_db_pools::{Connection, Database, sqlx};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Database)]
|
||||
#[database("postgres_db")]
|
||||
pub struct DbConn(sqlx::PgPool);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct UserCredentials {
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[post("/signup", data = "<cred>")]
|
||||
pub async fn signup(
|
||||
conn: Connection<DbConn>,
|
||||
cred: Json<UserCredentials>,
|
||||
) -> Result<Json<String>, String> {
|
||||
Ok(Json("Signup successful".to_string()))
|
||||
}
|
||||
|
||||
#[post("/login", data = "<cred>")]
|
||||
pub async fn login(
|
||||
conn: Connection<DbConn>,
|
||||
cred: Json<UserCredentials>,
|
||||
) -> Result<Json<String>, String> {
|
||||
// TODO: implement actual login logic, e.g. verify password and generate token
|
||||
Ok(Json("Login successful".to_string()))
|
||||
}
|
||||
Reference in New Issue
Block a user