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