WebSockets and tokio working
This commit is contained in:
34
src/usimp/handler/authenticate.rs
Normal file
34
src/usimp/handler/authenticate.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use crate::usimp::*;
|
||||
use crate::database;
|
||||
|
||||
use serde_json::{Value, from_value, to_value};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use std::ops::Deref;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
struct Input {
|
||||
name: String,
|
||||
password: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
struct Output {
|
||||
session: String,
|
||||
token: String,
|
||||
}
|
||||
|
||||
pub async fn handle(input: &InputEnvelope, session: &Session) -> Result<Value, Error> {
|
||||
Ok(to_value(authenticate(from_value(input.data.clone())?).await?)?)
|
||||
}
|
||||
|
||||
async fn authenticate(input: Input) -> Result<Output, Error> {
|
||||
match database::client().await? {
|
||||
database::Client::Postgres(client) => {
|
||||
client.execute("SELECT * FROM asdf;", &[]).await?;
|
||||
}
|
||||
}
|
||||
Ok(Output {
|
||||
session: "".to_string(),
|
||||
token: "".to_string(),
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user