routes.rs 1.02 KB
Newer Older
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use serde::{Serialize, Deserialize};
use rocket_contrib::json::Json;
use diesel::prelude::*;
use crate::DbConn;
use crate::models::users::{UserInfo, LocalUser, User};

#[derive(Debug, Serialize, Deserialize)]
struct AuthClaims {
    jti: String,
    sub: String,
    exp: usize,
    iat: usize,
}

#[derive(Debug, Serialize)]
pub struct AuthTokenResponse {
    token: String
}

#[derive(Debug, Deserialize)]
pub struct AuthTokenRequest {
    user: String,
    password: String,
}

#[post("/users/me/token", data = "<auth_request>")]
pub fn create_auth_token(conn: DbConn, auth_request: Json<AuthTokenRequest>) -> Json<AuthTokenResponse> {
    use crate::schema::localuser::dsl::*;
    use crate::schema::user::dsl::*;

    let client_user: Result<(User, LocalUser), _> = user.inner_join(localuser).filter(username.eq(&auth_request.user)).get_result(&*conn);
    println!("{:?}", client_user);
    Json(AuthTokenResponse { token: "".into() })
}

/*
GET /users -> list all users
POST /users
{
    provider: local
    ...
}
/users/<uuid or me>/
*/