Redesign forms, verify link ownership with rel="me" (#8703)
* 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
This commit is contained in:
parent
f8b54d229f
commit
f4d549d300
46 changed files with 764 additions and 313 deletions
|
@ -223,11 +223,19 @@ class Account < ApplicationRecord
|
|||
end
|
||||
|
||||
def fields_attributes=(attributes)
|
||||
fields = []
|
||||
fields = []
|
||||
old_fields = self[:fields] || []
|
||||
|
||||
if attributes.is_a?(Hash)
|
||||
attributes.each_value do |attr|
|
||||
next if attr[:name].blank?
|
||||
|
||||
previous = old_fields.find { |item| item['value'] == attr[:value] }
|
||||
|
||||
if previous && previous['verified_at'].present?
|
||||
attr[:verified_at] = previous['verified_at']
|
||||
end
|
||||
|
||||
fields << attr
|
||||
end
|
||||
end
|
||||
|
@ -235,13 +243,18 @@ class Account < ApplicationRecord
|
|||
self[:fields] = fields
|
||||
end
|
||||
|
||||
def build_fields
|
||||
return if fields.size >= 4
|
||||
DEFAULT_FIELDS_SIZE = 4
|
||||
|
||||
raw_fields = self[:fields] || []
|
||||
add_fields = 4 - raw_fields.size
|
||||
add_fields.times { raw_fields << { name: '', value: '' } }
|
||||
self.fields = raw_fields
|
||||
def build_fields
|
||||
return if fields.size >= DEFAULT_FIELDS_SIZE
|
||||
|
||||
tmp = self[:fields] || []
|
||||
|
||||
(DEFAULT_FIELDS_SIZE - tmp.size).times do
|
||||
tmp << { name: '', value: '' }
|
||||
end
|
||||
|
||||
self.fields = tmp
|
||||
end
|
||||
|
||||
def magic_key
|
||||
|
@ -294,17 +307,32 @@ class Account < ApplicationRecord
|
|||
end
|
||||
|
||||
class Field < ActiveModelSerializers::Model
|
||||
attributes :name, :value, :account, :errors
|
||||
attributes :name, :value, :verified_at, :account, :errors
|
||||
|
||||
def initialize(account, attr)
|
||||
@account = account
|
||||
@name = attr['name'].strip[0, 255]
|
||||
@value = attr['value'].strip[0, 255]
|
||||
@errors = {}
|
||||
def initialize(account, attributes)
|
||||
@account = account
|
||||
@attributes = attributes
|
||||
@name = attributes['name'].strip[0, 255]
|
||||
@value = attributes['value'].strip[0, 255]
|
||||
@verified_at = attributes['verified_at']&.to_datetime
|
||||
@errors = {}
|
||||
end
|
||||
|
||||
def verified?
|
||||
verified_at.present?
|
||||
end
|
||||
|
||||
def verifiable?
|
||||
value.present? && /\A#{FetchLinkCardService::URL_PATTERN}\z/ =~ value
|
||||
end
|
||||
|
||||
def mark_verified!
|
||||
@verified_at = Time.now.utc
|
||||
@attributes['verified_at'] = @verified_at
|
||||
end
|
||||
|
||||
def to_h
|
||||
{ name: @name, value: @value }
|
||||
{ name: @name, value: @value, verified_at: @verified_at }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue