mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
More extension points for login buttons, used by OAuth2 plugin
This commit is contained in:
@ -1,9 +1,25 @@
|
||||
class Plugin::AuthProvider
|
||||
attr_accessor :glyph, :background_color, :title,
|
||||
:message, :frame_width, :frame_height, :authenticator
|
||||
|
||||
def self.auth_attributes
|
||||
[:glyph, :background_color, :title, :message, :frame_width, :frame_height, :authenticator,
|
||||
:title_setting, :enabled_setting]
|
||||
end
|
||||
|
||||
attr_accessor(*auth_attributes)
|
||||
|
||||
def name
|
||||
authenticator.name
|
||||
end
|
||||
|
||||
def to_json
|
||||
result = {name: name}
|
||||
result['titleOverride'] = title if title
|
||||
result['titleSetting'] = title_setting if title_setting
|
||||
result['enabledSetting'] = enabled_setting if enabled_setting
|
||||
result['messageOverride'] = message if message
|
||||
result['frameWidth'] = frame_width if frame_width
|
||||
result['frameHeight'] = frame_height if frame_height
|
||||
result.to_json
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -218,13 +218,8 @@ class Plugin::Instance
|
||||
js = javascripts.join("\n")
|
||||
|
||||
auth_providers.each do |auth|
|
||||
overrides = ""
|
||||
overrides = ", titleOverride: '#{auth.title}'" if auth.title
|
||||
overrides << ", messageOverride: '#{auth.message}'" if auth.message
|
||||
overrides << ", frameWidth: '#{auth.frame_width}'" if auth.frame_width
|
||||
overrides << ", frameHeight: '#{auth.frame_height}'" if auth.frame_height
|
||||
|
||||
js << "Discourse.LoginMethod.register(Discourse.LoginMethod.create({name: '#{auth.name}'#{overrides}}));\n"
|
||||
js << "Discourse.LoginMethod.register(Discourse.LoginMethod.create(#{auth.to_json}));\n"
|
||||
|
||||
if auth.glyph
|
||||
css << ".btn-social.#{auth.name}:before{ content: '#{auth.glyph}'; }\n"
|
||||
@ -305,7 +300,8 @@ class Plugin::Instance
|
||||
|
||||
def auth_provider(opts)
|
||||
provider = Plugin::AuthProvider.new
|
||||
[:glyph, :background_color, :title, :message, :frame_width, :frame_height, :authenticator].each do |sym|
|
||||
|
||||
Plugin::AuthProvider.auth_attributes.each do |sym|
|
||||
provider.send "#{sym}=", opts.delete(sym)
|
||||
end
|
||||
auth_providers << provider
|
||||
|
Reference in New Issue
Block a user