feat: basic user token check

This commit is contained in:
2022-03-15 15:03:58 +08:00
parent a9d7576ed4
commit e4fbbb1b7b
6 changed files with 92 additions and 38 deletions

View File

@@ -4,7 +4,7 @@ use chrono::NaiveDateTime;
use diesel::{insert_into, Connection, ExpressionMethods, QueryDsl, RunQueryDsl, SqliteConnection};
use std::env;
use crate::schema::posts;
use crate::schema::*;
type MR<T> = Result<T, diesel::result::Error>;
@@ -80,3 +80,17 @@ impl Post {
insert_into(posts::table).values(&new_post).execute(conn)
}
}
#[derive(Queryable, Debug)]
pub struct User {
pub id: i32,
pub name: String,
pub token: String,
pub is_admin: bool,
}
impl User {
pub fn get_by_token(conn: &SqliteConnection, token: &str) -> Option<Self> {
users::table.filter(users::token.eq(token)).first(conn).ok()
}
}