mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
More extension points for login buttons, used by OAuth2 plugin
This commit is contained in:
parent
64598ceaba
commit
c4b1b848bc
@ -1,9 +1,15 @@
|
|||||||
Discourse.LoginMethod = Ember.Object.extend({
|
Discourse.LoginMethod = Ember.Object.extend({
|
||||||
title: function(){
|
title: function() {
|
||||||
|
var titleSetting = this.get('titleSetting');
|
||||||
|
if (!Ember.isEmpty(titleSetting)) {
|
||||||
|
var result = Discourse.SiteSettings[titleSetting];
|
||||||
|
if (!Ember.isEmpty(result)) { return result; }
|
||||||
|
}
|
||||||
|
|
||||||
return this.get("titleOverride") || I18n.t("login." + this.get("name") + ".title");
|
return this.get("titleOverride") || I18n.t("login." + this.get("name") + ".title");
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
message: function(){
|
message: function() {
|
||||||
return this.get("messageOverride") || I18n.t("login." + this.get("name") + ".message");
|
return this.get("messageOverride") || I18n.t("login." + this.get("name") + ".message");
|
||||||
}.property()
|
}.property()
|
||||||
});
|
});
|
||||||
@ -12,8 +18,8 @@ Discourse.LoginMethod = Ember.Object.extend({
|
|||||||
// just Em.get("Discourse.LoginMethod.all") and then
|
// just Em.get("Discourse.LoginMethod.all") and then
|
||||||
// pushObject for any new methods
|
// pushObject for any new methods
|
||||||
Discourse.LoginMethod.reopenClass({
|
Discourse.LoginMethod.reopenClass({
|
||||||
register: function(method){
|
register: function(method) {
|
||||||
if(this.methods){
|
if (this.methods){
|
||||||
this.methods.pushObject(method);
|
this.methods.pushObject(method);
|
||||||
} else {
|
} else {
|
||||||
this.preRegister = this.preRegister || [];
|
this.preRegister = this.preRegister || [];
|
||||||
@ -50,7 +56,14 @@ Discourse.LoginMethod.reopenClass({
|
|||||||
|
|
||||||
if (this.preRegister){
|
if (this.preRegister){
|
||||||
this.preRegister.forEach(function(method){
|
this.preRegister.forEach(function(method){
|
||||||
methods.pushObject(method);
|
var enabledSetting = method.get('enabledSetting');
|
||||||
|
if (enabledSetting) {
|
||||||
|
if (Discourse.SiteSettings[enabledSetting]) {
|
||||||
|
methods.pushObject(method);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
methods.pushObject(method);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
delete this.preRegister;
|
delete this.preRegister;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,25 @@
|
|||||||
class Plugin::AuthProvider
|
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
|
def name
|
||||||
authenticator.name
|
authenticator.name
|
||||||
end
|
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
|
end
|
||||||
|
@ -218,13 +218,8 @@ class Plugin::Instance
|
|||||||
js = javascripts.join("\n")
|
js = javascripts.join("\n")
|
||||||
|
|
||||||
auth_providers.each do |auth|
|
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
|
if auth.glyph
|
||||||
css << ".btn-social.#{auth.name}:before{ content: '#{auth.glyph}'; }\n"
|
css << ".btn-social.#{auth.name}:before{ content: '#{auth.glyph}'; }\n"
|
||||||
@ -305,7 +300,8 @@ class Plugin::Instance
|
|||||||
|
|
||||||
def auth_provider(opts)
|
def auth_provider(opts)
|
||||||
provider = Plugin::AuthProvider.new
|
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)
|
provider.send "#{sym}=", opts.delete(sym)
|
||||||
end
|
end
|
||||||
auth_providers << provider
|
auth_providers << provider
|
||||||
|
@ -295,7 +295,6 @@ describe PostCreator do
|
|||||||
|
|
||||||
expect(whisper_reply).to be_present
|
expect(whisper_reply).to be_present
|
||||||
expect(whisper_reply.post_type).to eq(Post.types[:whisper])
|
expect(whisper_reply.post_type).to eq(Post.types[:whisper])
|
||||||
expect(true).to eq(false)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user