mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-11-19 21:33:21 +00:00
f4d549d300
* Verify link ownership with rel="me" * Add explanation about verification to UI * Perform link verifications * Add click-to-copy widget for verification HTML * Redesign edit profile page * Redesign forms * Improve responsive design of settings pages * Restore landing page sign-up form * Fix typo * Support <link> tags, add spec * Fix links not being verified on first discovery and passive updates
33 lines
867 B
Ruby
33 lines
867 B
Ruby
# frozen_string_literal: true
|
|
|
|
class VerifyLinkService < BaseService
|
|
def call(field)
|
|
@link_back = ActivityPub::TagManager.instance.url_for(field.account)
|
|
@url = field.value
|
|
|
|
perform_request!
|
|
|
|
return unless link_back_present?
|
|
|
|
field.mark_verified!
|
|
field.account.save!
|
|
rescue HTTP::Error, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError => e
|
|
Rails.logger.debug "Error fetching link #{@url}: #{e}"
|
|
nil
|
|
end
|
|
|
|
private
|
|
|
|
def perform_request!
|
|
@body = Request.new(:get, @url).add_headers('Accept' => 'text/html').perform do |res|
|
|
res.code != 200 ? nil : res.body_with_limit
|
|
end
|
|
end
|
|
|
|
def link_back_present?
|
|
return false if @body.empty?
|
|
|
|
Nokogiri::HTML(@body).xpath('//a[@rel="me"]|//link[@rel="me"]').any? { |link| link['href'] == @link_back }
|
|
end
|
|
end
|