summaryrefslogtreecommitdiff
path: root/src/models.rs
blob: 10f7d68aca7a4829246b63da6ecfd479d4c44537 (plain)
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
use crate::error::Error;
use crate::schema::config;
use crate::schema::users;
use bcrypt;

#[derive(Insertable, Queryable)]
#[table_name = "config"]
pub struct Config {
    pub strava_client_secret: String,
    pub strava_client_id: String,
    pub rocket_secret_key: String,
    pub singleton: bool,
}

#[derive(Insertable, Queryable)]
#[table_name = "users"]
pub struct User {
    pub username: String,
    password: String,
}

impl User {
    pub fn new(username: &str, password: &str) -> User {
        User {
            username: username.to_string(),
            password: password.to_string(),
        }
    }

    pub fn verify(&self, password: &str) -> Result<bool, Error> {
        bcrypt::verify(password, &self.password).map_err(|e| From::from(e))
    }
}