token_service = $token_service; } /** * Get check name. */ public function get_name(): string { return 'javascript_token'; } /** * Whether the check is enabled. * * @param SettingsSnapshot $settings Immutable settings snapshot. */ public function is_enabled( SettingsSnapshot $settings ): bool { return $settings->is_check_enabled( 'javascript_token_check_enabled' ); } /** * Evaluate submitted token. * * @param SubmissionContext $context Normalized submission context. * @param SettingsSnapshot $settings Immutable settings snapshot. */ public function evaluate( SubmissionContext $context, SettingsSnapshot $settings ): CheckResult { if ( '' === trim( $context->get_token() ) ) { return CheckResult::suspicious( ReasonCodeRegistry::MISSING_TOKEN ); } if ( ! $this->token_service->validate_token( $context->get_token(), $context->get_form_id(), $context->get_timestamp(), $settings->get_token_lifetime_seconds() ) ) { return CheckResult::block( ReasonCodeRegistry::INVALID_TOKEN ); } return CheckResult::pass(); } }