Validate website ownership in rails

前端 未结 5 1805
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 10:17

For a more recent discussion about a similar topic check this question out.

What\'s the best way to validate whether a particular user has ownership of a website?

5条回答
  •  旧时难觅i
    2021-01-14 11:03

    Google Website tools allows you to just upload a file with a very specific name. so, you could require that the user create a file in order for you to verify that they own the website

    require 'digest/sha1'
    require 'net/http'
    
    # you may want to store a unique value in the website table instead
    unique_id = Digest::SHA1.hexdigest("#{website.id}/#{website.created_at}")
    response = Net::HTTP.start(website.url, 80) {|http| http.head("/verify_#{unique_id}.html") }
    website.verified = true if response.code == "200"
    

提交回复
热议问题