summaryrefslogtreecommitdiff
path: root/src/models.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/models.rs')
-rw-r--r--src/models.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/models.rs b/src/models.rs
index 8bee887..28a8b65 100644
--- a/src/models.rs
+++ b/src/models.rs
@@ -1,5 +1,7 @@
+use crate::error::Error;
use crate::schema::config;
use crate::schema::users;
+use bcrypt;
#[derive(Insertable, Queryable)]
#[table_name = "config"]
@@ -11,16 +13,20 @@ pub struct Config<'a> {
#[derive(Insertable, Queryable)]
#[table_name = "users"]
-pub struct User<'a> {
- pub username: &'a str,
- password: &'a str,
+pub struct User {
+ pub username: String,
+ password: String,
}
-impl<'a> User<'a> {
- pub fn new(username: &'a str, password: &'a str) -> User<'a> {
+impl User {
+ pub fn new(username: &str, password: &str) -> User {
User {
- username: username,
- password: password,
+ 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))
+ }
}