Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // If I have this everything works
- use schema::users::dsl::*;
- use schema::users;
- fn authenticate_user(db: &Db, user_email: &str, password: &str) -> EndpointResult<User> {
- let conn = &*db.pool().get()?;
- let user = match users.filter(users::email.eq(user_email)).first::<User>(conn) {
- Ok(user) => user,
- Err(DieselError::NotFound) => return Err(EndpointError::from(AuthError::Unauthorized)),
- Err(err) => return Err(EndpointError::from(err))
- };
- match verify(password, user.hashed_password.as_ref().expect("hashed password should be there")) {
- Ok(true) => Ok(user),
- Ok(false) => Err(EndpointError::from(AuthError::Unauthorized)),
- Err(err) => Err(EndpointError::from(AuthError::Encryption(err)))
- }
- }
- /////////////////////////////////////////////////////
- // But if i do this always returns me the first user
- fn authenticate_user(db: &Db, email: &str, password: &str) -> EndpointResult<User> {
- use schema::users::dsl::*;
- use schema::users;
- let conn = &*db.pool().get()?;
- let user = match users.filter(users::email.eq(email)).first::<User>(conn) {
- Ok(user) => user,
- Err(DieselError::NotFound) => return Err(EndpointError::from(AuthError::Unauthorized)),
- Err(err) => return Err(EndpointError::from(err))
- };
- match verify(password, user.hashed_password.as_ref().expect("hashed password should be there")) {
- Ok(true) => Ok(user),
- Ok(false) => Err(EndpointError::from(AuthError::Unauthorized)),
- Err(err) => Err(EndpointError::from(AuthError::Encryption(err)))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement