/// Performs the credential check between the given user input and stored local data.
Performs the credential check between the given user input and stored local data.
Performs the credential check between the given user input and stored local data .
async fn check_credentials(meta_db: &PouchDB, user_hash: &str, mkey: &str) -> bool {
        // Query meta-data
        let result_raw = JsFuture::from(meta_db.find(&JsValue::from_serde(&json!({
            "selector": {
                "$or": [
                    {"type": "user"},
                    {"type": "mkey"}
                ]
            }
        })).unwrap())).await.unwrap();
        // Parse received entry
        let result_raw = result_raw.into_serde::<Value>().unwrap();
        let result_1 = &result_raw["docs"][0];
        let result_2 = &result_raw["docs"][1];
        if result_1.is_object() && result_2.is_object() {
            // Meta-data was found in the database
            // Assign it correctly
            let mut user_val = &Value::Null;
            let mut mkey_val = &Value::Null;
            if result_1["mkey"].is_string() {
                // result_1 is mkey, result_2 is user
                mkey_val = result_1;
                user_val = result_2;
            } else {
                mkey_val = result_2;
                user_val = result_1;
            }
            // Check credentials
            if user_val["user"].as_str().unwrap() == user_hash &&
                mkey_val["mkey"].as_str().unwrap() == mkey {
                true
            } else {
                false
            }
        } else {
            // Full meta-data not found in the database
            // Check cannot be done
            false
        }
    }
async fn check_credentials ( meta_db : & PouchDB , user_hash : & str , mkey : & str ) -> bool { // Query meta-data let result_raw = JsFuture :: from ( meta_db . find ( & JsValue :: from_serde ( & json ! ( { " " { " " [ { " " " " } { " " " " } ] } } ) ) . unwrap ( ) ) ) . await . unwrap ( ) ; // Parse received entry let result_raw = result_raw . into_serde :: < Value > ( ) . unwrap ( ) ; let result_1 = & result_raw [ " " ] [ 0 ] ; let result_2 = & result_raw [ " " ] [ 1 ] ; if result_1 . is_object ( ) && result_2 . is_object ( ) { // Meta-data was found in the database // Assign it correctly let mut user_val = & Value :: Null ; let mut mkey_val = & Value :: Null ; if result_1 [ " " ] . is_string ( ) { // result_1 is mkey, result_2 is user mkey_val = result_1 ; user_val = result_2 ; } else { mkey_val = result_2 ; user_val = result_1 ; } // Check credentials if user_val [ " " ] . as_str ( ) . unwrap ( ) == user_hash && mkey_val [ " " ] . as_str ( ) . unwrap ( ) == mkey { true } else { false } } else { // Full meta-data not found in the database // Check cannot be done false } }
Performs the credential check between the given user input and stored local data.
Performs the credential check between the given user input and stored local data .
meta_db
&PouchDB
user_hash
&str
mkey
&str