(
store: Store,
login: Account,
)
| 37 | } |
| 38 | |
| 39 | pub async fn login( |
| 40 | store: Store, |
| 41 | login: Account, |
| 42 | ) -> Result<impl warp::Reply, warp::Rejection> { |
| 43 | match store.get_account(login.email).await { |
| 44 | Ok(account) => match verify_password( |
| 45 | &account.password, |
| 46 | login.password.as_bytes(), |
| 47 | ) { |
| 48 | Ok(verified) => { |
| 49 | if verified { |
| 50 | Ok(warp::reply::json(&issue_token( |
| 51 | account.id.expect("id not found"), |
| 52 | ))) |
| 53 | } else { |
| 54 | Err(warp::reject::custom( |
| 55 | handle_errors::Error::WrongPassword, |
| 56 | )) |
| 57 | } |
| 58 | } |
| 59 | Err(e) => Err(warp::reject::custom( |
| 60 | handle_errors::Error::ArgonLibraryError(e), |
| 61 | )), |
| 62 | }, |
| 63 | Err(e) => Err(warp::reject::custom(e)), |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | fn hash_password(password: &[u8]) -> String { |
| 68 | let salt = SaltString::generate(&mut OsRng); |
nothing calls this directly
no test coverage detected