Compare View

switch
from
...
to
 
Commits (3)
plugins/oauth_client/controllers/oauth_client_plugin_admin_controller.rb
1 class OauthClientPluginAdminController < AdminController 1 class OauthClientPluginAdminController < AdminController
2 2
3 def index 3 def index
  4 + @config = OauthClientPlugin::Config.instance
4 end 5 end
5 6
6 def new 7 def new
@@ -13,6 +14,11 @@ class OauthClientPluginAdminController &lt; AdminController @@ -13,6 +14,11 @@ class OauthClientPluginAdminController &lt; AdminController
13 redirect_to :action => 'index' 14 redirect_to :action => 'index'
14 end 15 end
15 16
  17 + def update_configs
  18 + OauthClientPlugin::Config.instance.update_attributes(params[:oauth_client_config])
  19 + redirect_to :action => 'index'
  20 + end
  21 +
16 def edit 22 def edit
17 @provider = params[:id] ? environment.oauth_providers.find(params[:id]) : environment.oauth_providers.new 23 @provider = params[:id] ? environment.oauth_providers.find(params[:id]) : environment.oauth_providers.new
18 if request.post? 24 if request.post?
@@ -24,4 +30,8 @@ class OauthClientPluginAdminController &lt; AdminController @@ -24,4 +30,8 @@ class OauthClientPluginAdminController &lt; AdminController
24 end 30 end
25 end 31 end
26 32
  33 + def edit_login_option
  34 + option = params['oauth_client_plugin_option']
  35 + end
  36 +
27 end 37 end
plugins/oauth_client/db/migrate/20160714113820_create_oauth_client_plugin_config.rb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +class CreateOauthClientPluginConfig < ActiveRecord::Migration
  2 +
  3 + def change
  4 + create_table :oauth_client_plugin_configs do |t|
  5 + t.belongs_to :environment
  6 + t.boolean :create_account_for_login, :default => false
  7 + end
  8 + end
  9 +end
plugins/oauth_client/lib/ext/environment.rb
1 require_dependency 'environment' 1 require_dependency 'environment'
2 2
3 class Environment 3 class Environment
4 - 4 + has_one :oauth_client_plugin_configs, :class_name => 'OauthClientPlugin::Config'
5 has_many :oauth_providers, :class_name => 'OauthClientPlugin::Provider' 5 has_many :oauth_providers, :class_name => 'OauthClientPlugin::Provider'
6 -  
7 end 6 end
plugins/oauth_client/models/oauth_client_plugin/config.rb 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +class OauthClientPlugin::Config < ApplicationRecord
  2 +
  3 + belongs_to :environment
  4 + attr_accessible :create_account_for_login, :environment_id
  5 +
  6 + class << self
  7 + def instance
  8 + environment = Environment.default
  9 + environment.oauth_client_plugin_configs || create(environment_id: environment.id)
  10 + end
  11 +
  12 + private :new
  13 + end
  14 +
  15 +end
plugins/oauth_client/views/auth/_generate_providers_links.html.erb 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +<% providers.each do |provider| %>
  2 + <span class="provider">
  3 + <%= link_to provider.image ? image_tag(provider.image.public_filename) : provider.name, "/plugin/oauth_client/#{provider.strategy}?id=#{provider.id}&action=#{action}", :class => provider.strategy, :title => provider.name %>
  4 + </span>
  5 +<% end %>
plugins/oauth_client/views/auth/_oauth_login.html.erb
1 <div class="oauth-login"> 1 <div class="oauth-login">
2 <% unless providers.empty? %> 2 <% unless providers.empty? %>
3 - <%= _('Login with:') %>  
4 - <% end %>  
5 - <% providers.each do |provider| %>  
6 - <span class="provider">  
7 - <%= link_to provider.image ? image_tag(provider.image.public_filename) : provider.name, "/plugin/oauth_client/#{provider.strategy}?id=#{provider.id}&action=external_login", :class => provider.strategy, :title => provider.name %>  
8 - </span> 3 + <div class="providers-links">
  4 + <%= _('Create an account from:') %>
  5 + <div>
  6 + <%= render :partial => 'auth/generate_providers_links', :locals => {:providers => providers, :action => ""} %>
  7 + </div>
  8 + <% if OauthClientPlugin::Config.instance.create_account_for_login %>
  9 + <%= _('Login with:') %>
  10 + <div>
  11 + <%= render :partial => 'auth/generate_providers_links', :locals => {:providers => providers, :action => "external_login"} %>
  12 + </div>
  13 + <% end %>
  14 + </div>
9 <% end %> 15 <% end %>
10 16
11 <span class="provider"> 17 <span class="provider">
plugins/oauth_client/views/oauth_client_plugin_admin/index.html.erb
1 <h1><%= _('Oauth Client Settings') %></h1> 1 <h1><%= _('Oauth Client Settings') %></h1>
  2 +
  3 +<%= labelled_form_for @config, url: { action: "update_configs" } do |f| %>
  4 + <table>
  5 + <tr>
  6 + <%= hidden_field_tag "oauth_client_config[create_account_for_login]", false %>
  7 + <td><%= _('Only allow login with creation of new account') %></td>
  8 + <td><%= check_box_tag "oauth_client_config[create_account_for_login]", true, @config.create_account_for_login %></td>
  9 + </tr>
  10 + </table>
  11 +
  12 + <div>
  13 + <%= button_bar do %>
  14 + <%= submit_button('save', _('Save changes')) %>
  15 + <%= button :back, _('Back to plugins panel'), :controller => 'plugins', :action => 'index' %>
  16 + <% end %>
  17 + </div>
  18 +<% end %>
  19 +
2 <h3><%= _('Providers') %></h3> 20 <h3><%= _('Providers') %></h3>
3 <%= button :add, _('New'), {:action => 'new'} %> 21 <%= button :add, _('New'), {:action => 'new'} %>
4 <table> 22 <table>