diff options
Diffstat (limited to 'src/handlers/users.rs')
-rw-r--r-- | src/handlers/users.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/handlers/users.rs b/src/handlers/users.rs index c7bc870..bff532c 100644 --- a/src/handlers/users.rs +++ b/src/handlers/users.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use crate::models::{Member, NewMember}; | 1 | use crate::models::{Customer, NewCustomer}; |
2 | use crate::schema::members::dsl::*; | 2 | use crate::schema::customer::dsl::*; |
3 | use crate::TPool; | 3 | use crate::TPool; |
4 | 4 | ||
5 | use actix_identity::Identity; | 5 | use actix_identity::Identity; |
@@ -11,14 +11,14 @@ use serde::Deserialize; | |||
11 | 11 | ||
12 | pub async fn new_user( | 12 | pub async fn new_user( |
13 | pool: web::Data<TPool>, | 13 | pool: web::Data<TPool>, |
14 | item: web::Json<NewMember>, | 14 | item: web::Json<NewCustomer>, |
15 | ) -> impl Responder { | 15 | ) -> impl Responder { |
16 | let conn = pool.get().unwrap(); | 16 | let conn = pool.get().unwrap(); |
17 | let hashed_item = NewMember { | 17 | let hashed_item = NewCustomer { |
18 | password: hash(&item.password, DEFAULT_COST).unwrap(), | 18 | password: hash(&item.password, DEFAULT_COST).unwrap(), |
19 | ..(item.into_inner()) | 19 | ..(item.into_inner()) |
20 | }; | 20 | }; |
21 | diesel::insert_into(members) | 21 | diesel::insert_into(customer) |
22 | .values(hashed_item) | 22 | .values(hashed_item) |
23 | .execute(&conn) | 23 | .execute(&conn) |
24 | .expect("Coundn't connect to DB"); | 24 | .expect("Coundn't connect to DB"); |
@@ -31,10 +31,10 @@ pub async fn name_exists( | |||
31 | ) -> impl Responder { | 31 | ) -> impl Responder { |
32 | let conn = pool.get().unwrap(); | 32 | let conn = pool.get().unwrap(); |
33 | info!("target: {:?}", item); | 33 | info!("target: {:?}", item); |
34 | if (members | 34 | if (customer |
35 | .filter(username.eq(&item)) | 35 | .filter(username.eq(&item)) |
36 | .limit(1) | 36 | .limit(1) |
37 | .load::<Member>(&conn) | 37 | .load::<Customer>(&conn) |
38 | .expect("Coundn't connect to DB")) | 38 | .expect("Coundn't connect to DB")) |
39 | .len() | 39 | .len() |
40 | > 0 | 40 | > 0 |
@@ -59,10 +59,10 @@ pub async fn login( | |||
59 | info!("Login hit"); | 59 | info!("Login hit"); |
60 | let conn = pool.get().unwrap(); | 60 | let conn = pool.get().unwrap(); |
61 | let entered_pass = &login_details.password; | 61 | let entered_pass = &login_details.password; |
62 | let selected_user = members | 62 | let selected_user = customer |
63 | .filter(username.eq(&login_details.username)) | 63 | .filter(username.eq(&login_details.username)) |
64 | .limit(1) | 64 | .limit(1) |
65 | .first::<Member>(&conn) | 65 | .first::<Customer>(&conn) |
66 | .expect("Couldn't connect to DB"); | 66 | .expect("Couldn't connect to DB"); |
67 | let hashed_pass = selected_user.password; | 67 | let hashed_pass = selected_user.password; |
68 | if verify(entered_pass, &hashed_pass).unwrap() { | 68 | if verify(entered_pass, &hashed_pass).unwrap() { |
@@ -89,10 +89,10 @@ pub async fn user_details( | |||
89 | let conn = pool.get().unwrap(); | 89 | let conn = pool.get().unwrap(); |
90 | let uname = uname.into_inner(); | 90 | let uname = uname.into_inner(); |
91 | info!("Fetching info for: \"{}\"", uname); | 91 | info!("Fetching info for: \"{}\"", uname); |
92 | let selected_user = members | 92 | let selected_user = customer |
93 | .filter(username.eq(&uname)) | 93 | .filter(username.eq(&uname)) |
94 | .limit(1) | 94 | .limit(1) |
95 | .first::<Member>(&conn); | 95 | .first::<Customer>(&conn); |
96 | match selected_user { | 96 | match selected_user { |
97 | Ok(m) => { | 97 | Ok(m) => { |
98 | info!("Found user: {}", uname); | 98 | info!("Found user: {}", uname); |
@@ -121,16 +121,16 @@ pub async fn change_password( | |||
121 | if let Some(uname) = cookie.identity() { | 121 | if let Some(uname) = cookie.identity() { |
122 | let entered_pass = &password_details.old_password; | 122 | let entered_pass = &password_details.old_password; |
123 | let new_password = &password_details.new_password; | 123 | let new_password = &password_details.new_password; |
124 | let selected_user = members | 124 | let selected_user = customer |
125 | .filter(username.eq(&uname)) | 125 | .filter(username.eq(&uname)) |
126 | .limit(1) | 126 | .limit(1) |
127 | .first::<Member>(&conn) | 127 | .first::<Customer>(&conn) |
128 | .expect("Couldn't connect to DB"); | 128 | .expect("Couldn't connect to DB"); |
129 | let hashed_pass = selected_user.password; | 129 | let hashed_pass = selected_user.password; |
130 | if verify(entered_pass, &hashed_pass).unwrap() { | 130 | if verify(entered_pass, &hashed_pass).unwrap() { |
131 | let hashed_new_password = | 131 | let hashed_new_password = |
132 | hash(&new_password, DEFAULT_COST).unwrap(); | 132 | hash(&new_password, DEFAULT_COST).unwrap(); |
133 | diesel::update(members.filter(id.eq(selected_user.id))) | 133 | diesel::update(customer.filter(id.eq(selected_user.id))) |
134 | .set(password.eq(hashed_new_password)) | 134 | .set(password.eq(hashed_new_password)) |
135 | .execute(&conn) | 135 | .execute(&conn) |
136 | .unwrap(); | 136 | .unwrap(); |