/** * Retrieve a user according to email and api key * * @param string $email The email of the user wanted * @param string $api_key The api key of the user wanted * @return ApiPrintUser The user object or null if it doesn't exist * @access public * @static * @since 1.0.0 */ public static function retrieveByEmailAndKey($email, $api_key) { if (is_string($email) === false || is_string($api_key) === false) { throw new Exception('email and api_key must be string'); } $api_print_user = new ApiPrintUser(); $sql = 'SELECT * FROM ' . $api_print_user->getTableName() . ' '; $sql .= 'WHERE email = :email AND api_key = :api_key'; $stmt = Database::getSingleton()->prepare($sql); $stmt->bindValue(':email', $email, PDO::PARAM_STR); $stmt->bindValue(':api_key', $api_key, PDO::PARAM_STR); $res = $stmt->execute(); if ($res === false) { if (DEBUG === true) { ob_start(); $stmt->debugDumpParams(); $error = ob_get_contents(); ob_end_clean(); throw new Exception('Error in the query : ' . $error); } return null; } $result = $stmt->fetch(PDO::FETCH_ASSOC); if ($result === false) { return null; } $api_print_user->load($result); return $api_print_user; }