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