diff --git a/Gemfile b/Gemfile index ca88d6247..989feb122 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,7 @@ gem "omniauth" gem "omniauth-twitter" gem "omniauth-facebook" gem "omniauth-linkedin" +gem "omniauth-google-oauth2" gem "twitter" gem "koala" diff --git a/Gemfile.lock b/Gemfile.lock index a522c2d2d..62dfe1f36 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -83,6 +83,9 @@ GEM rack omniauth-facebook (1.2.0) omniauth-oauth2 (~> 1.0.0) + omniauth-google-oauth2 (0.1.9) + omniauth (~> 1.0) + omniauth-oauth2 omniauth-linkedin (0.0.6) omniauth-oauth (~> 1.0.0) omniauth-oauth (1.0.0) @@ -160,6 +163,7 @@ DEPENDENCIES mime-types omniauth omniauth-facebook + omniauth-google-oauth2 omniauth-linkedin omniauth-twitter rails (= 3.2.2) diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 6b2227ea1..2ed5cf323 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -182,14 +182,19 @@ class App.Controller extends Spine.Controller if attribute.tag is 'boolean' # build options list - attribute.options = [ - { name: 'active', value: true } - { name: 'inactive', value: false } - ] || [] + if _.isEmpty(attribute.options) + attribute.options = [ + { name: 'active', value: true } + { name: 'inactive', value: false } + ] + + # update boolean types + for record in attribute.options + record.value = '{boolean}::' + record.value # finde selected item of list for record in attribute.options - if record.value is attribute.value + if record.value is '{boolean}::' + attribute.value record.selected = 'selected' # return item @@ -286,6 +291,15 @@ class App.Controller extends Spine.Controller else param[key.name].push key.value else + + # check boolean + boolean = key.value.split '::' + if boolean[0] is '{boolean}' + if boolean[1] is 'true' + key.value = true + else + key.value = false + param[key.name] = key.value @log 'formParam', form, param diff --git a/app/assets/javascripts/app/controllers/login.js.coffee b/app/assets/javascripts/app/controllers/login.js.coffee index 695a37095..3628921a4 100644 --- a/app/assets/javascripts/app/controllers/login.js.coffee +++ b/app/assets/javascripts/app/controllers/login.js.coffee @@ -28,6 +28,11 @@ class Index extends App.Controller name: 'LinkedIn', config: 'auth_linkedin', }, + google_oauth2: { + url: '/auth/google_oauth2', + name: 'Google', + config: 'auth_google_oauth2', + }, } auth_providers = [] for key, provider of auth_provider_all diff --git a/config/environment.rb b/config/environment.rb index 03f4adb6b..dcf6ca723 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -7,6 +7,8 @@ require 'user_info' # load omniauth strategies with database lookups api keys at runtime require 'twitter_database' require 'facebook_database' +require 'linked_in_database' +require 'google_oauth2_database' # Initialize the rails application Zammad::Application.initialize! diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 90819a036..1f1af61d6 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,13 +1,17 @@ Rails.application.config.middleware.use OmniAuth::Builder do # twitter database connect - provider :twitter_database, 'xx', 'xx', + provider :twitter_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse', :client_options => { :authorize_path => '/oauth/authorize', :site => 'https://api.twitter.com' } # facebook database connect - provider :facebook_database, 'xx', 'xx' + provider :facebook_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse' # linkedin database connect -# provider :linked_in_database, 'xx', 'xx' + provider :linked_in_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse' + + # google database connect + provider :google_oauth2_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse', + :authorize_options => { :access_type => 'online', :approval_prompt => '' } end diff --git a/db/seeds.rb b/db/seeds.rb index 262829308..10a97246b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -157,16 +157,16 @@ Setting.create( :display => '', :null => true, :name => 'user_create_account', - :tag => 'select', - :options => { - 1 => 'yes', - 0 => 'no', + :tag => 'boolean', + :options => { + true => 'yes', + false => 'no', }, }, ], }, :state => { - :value => 1, + :value => true, }, :frontend => true ) @@ -181,16 +181,16 @@ Setting.create( :display => '', :null => true, :name => 'user_lost_password', - :tag => 'select', - :options => { - 1 => 'yes', - 0 => 'no', + :tag => 'boolean', + :options => { + true => 'yes', + false => 'no', }, }, ], }, :state => { - :value => 1, + :value => true, }, :frontend => true ) @@ -205,18 +205,18 @@ Setting.create( :display => '', :null => true, :name => 'switch_to_user', - :tag => 'select', + :tag => 'boolean', :options => { - 1 => 'yes', - 0 => 'no', + true => 'yes', + false => 'no', }, }, ], }, - :state => { - :value => 0, + :state => { + :value => false, }, - :frontend => true + :frontend => true ) Setting.create( :title => 'Autentication via Database', @@ -229,18 +229,18 @@ Setting.create( :display => '', :null => true, :name => 'auth_db', - :tag => 'select', + :tag => 'boolean', :options => { - 1 => 'yes', - 0 => 'no', + true => 'yes', + false => 'no', }, }, ], }, - :state => { - :value => 1, + :state => { + :value => true, }, - :frontend => true + :frontend => true ) Setting.create( :title => 'Autentication via Twitter', @@ -253,7 +253,7 @@ Setting.create( :display => '', :null => true, :name => 'auth_twitter', - :tag => 'select', + :tag => 'boolean', :options => { true => 'yes', false => 'no', @@ -303,7 +303,7 @@ Setting.create( :display => '', :null => true, :name => 'auth_facebook', - :tag => 'select', + :tag => 'boolean', :options => { true => 'yes', false => 'no', @@ -343,6 +343,58 @@ Setting.create( }, :frontend => false ) + +Setting.create( + :title => 'Autentication via Google', + :name => 'auth_google_oauth2', + :area => 'Security::Authentication', + :description => 'Enables user authentication via Google.', + :options => { + :form => [ + { + :display => '', + :null => true, + :name => 'auth_google_oauth2', + :tag => 'boolean', + :options => { + true => 'yes', + false => 'no', + }, + }, + ], + }, + :state => { + :value => false, + }, + :frontend => true +) +Setting.create( + :title => 'Google App Credentials', + :name => 'auth_google_oauth2_credentials', + :area => 'Security::Authentication', + :description => 'Enables user authentication via Google.', + :options => { + :form => [ + { + :display => 'Client ID', + :null => true, + :name => 'client_id', + :tag => 'input', + }, + { + :display => 'Client Secret', + :null => true, + :name => 'client_secret', + :tag => 'input', + }, + ], + }, + :state => { + :value => {}, + }, + :frontend => false +) + Setting.create( :title => 'Autentication via LinkedIn', :name => 'auth_linkedin', @@ -354,8 +406,8 @@ Setting.create( :display => '', :null => true, :name => 'auth_linkedin', - :tag => 'select', - :options => { + :tag => 'boolean', + :options => { true => 'yes', false => 'no', }, @@ -638,17 +690,17 @@ Setting.create( :null => true, :name => 'ticket_number', :tag => 'select', - :options => { + :options => { 'increment' => 'Increment (SystemID.Counter)', 'date' => 'Date (Year.Month.Day.SystemID.Counter)', }, }, ], }, - :state => { + :state => { :value => 'increment', }, - :frontend => false + :frontend => false ) Setting.create( :title => 'Ticket Number Increment', @@ -658,21 +710,21 @@ Setting.create( :options => { :form => [ { - :display => 'Checksum', - :null => true, - :name => 'checksum', - :tag => 'select', - :options => { + :display => 'Checksum', + :null => true, + :name => 'checksum', + :tag => 'boolean', + :options => { true => 'yes', false => 'no', }, }, { - :display => 'Min. size of number', - :null => true, - :name => 'min_size', - :tag => 'select', - :options => { + :display => 'Min. size of number', + :null => true, + :name => 'min_size', + :tag => 'select', + :options => { 1 => 1, 2 => 2, 3 => 3, @@ -696,21 +748,21 @@ Setting.create( }, }, { - :display => 'Logfile', - :null => false, - :name => 'file', - :tag => 'input', + :display => 'Logfile', + :null => false, + :name => 'file', + :tag => 'input', }, ], }, - :state => { + :state => { :value => { :checksum => false, :file => '/tmp/counter.log', :min_size => 5, }, }, - :frontend => false + :frontend => false ) Setting.create( :title => 'Ticket Number Increment Date', @@ -720,30 +772,30 @@ Setting.create( :options => { :form => [ { - :display => 'Checksum', - :null => true, - :name => 'checksum', - :tag => 'select', - :options => { + :display => 'Checksum', + :null => true, + :name => 'checksum', + :tag => 'boolean', + :options => { true => 'yes', false => 'no', }, }, { - :display => 'Logfile', - :null => false, - :name => 'file', - :tag => 'input', + :display => 'Logfile', + :null => false, + :name => 'file', + :tag => 'input', }, ], }, - :state => { + :state => { :value => { :checksum => false, :file => '/tmp/counter.log', } }, - :frontend => false + :frontend => false ) Setting.create( @@ -765,10 +817,10 @@ Setting.create( }, ], }, - :state => { + :state => { :value => 'SystemAddressName', }, - :frontend => false + :frontend => false ) Setting.create( @@ -779,17 +831,17 @@ Setting.create( :options => { :form => [ { - :display => '', - :null => false, - :name => 'ticket_define_email_from_seperator', - :tag => 'input', + :display => '', + :null => false, + :name => 'ticket_define_email_from_seperator', + :tag => 'input', }, ], }, - :state => { + :state => { :value => 'via', }, - :frontend => false + :frontend => false ) Setting.create( @@ -800,21 +852,21 @@ Setting.create( :options => { :form => [ { - :display => '', - :null => true, - :name => 'customer_ticket_create', - :tag => 'select', - :options => { + :display => '', + :null => true, + :name => 'customer_ticket_create', + :tag => 'boolean', + :options => { true => 'yes', false => 'no', }, }, ], }, - :state => { + :state => { :value => true, }, - :frontend => true + :frontend => true ) Setting.create( @@ -825,11 +877,11 @@ Setting.create( :options => { :form => [ { - :display => '', - :null => true, - :name => 'customer_ticket_view', - :tag => 'select', - :options => { + :display => '', + :null => true, + :name => 'customer_ticket_view', + :tag => 'boolean', + :options => { true => 'yes', false => 'no', }, @@ -879,10 +931,10 @@ Setting.create( }, ], }, - :state => { + :state => { :value => 10, }, - :frontend => false + :frontend => false ) Setting.create( @@ -893,11 +945,11 @@ Setting.create( :options => { :form => [ { - :display => '', - :null => true, - :name => 'postmaster_follow_up_search_in', - :tag => 'checkbox', - :options => { + :display => '', + :null => true, + :name => 'postmaster_follow_up_search_in', + :tag => 'checkbox', + :options => { 'references' => 'References', 'body' => 'Body', 'attachment' => 'Attachment', @@ -906,10 +958,10 @@ Setting.create( }, ], }, - :state => { + :state => { :value => ['subject'], }, - :frontend => false + :frontend => false ) Setting.create( @@ -920,17 +972,17 @@ Setting.create( :options => { :form => [ { - :display => '', - :null => false, - :name => 'notification_sender', - :tag => 'input', + :display => '', + :null => false, + :name => 'notification_sender', + :tag => 'input', }, ], }, - :state => { + :state => { :value => 'Notification Master ', }, - :frontend => false + :frontend => false ) Setting.create( @@ -941,17 +993,17 @@ Setting.create( :options => { :form => [ { - :display => '', - :null => false, - :name => 'system_sender', - :tag => 'input', + :display => '', + :null => false, + :name => 'system_sender', + :tag => 'input', }, ], }, - :state => { + :state => { :value => 'Zammad Team ', }, - :frontend => false + :frontend => false ) Setting.create( :title => 'Block Notifications', @@ -961,17 +1013,17 @@ Setting.create( :options => { :form => [ { - :display => '', - :null => false, - :name => 'send_no_auto_response_reg_exp', - :tag => 'input', + :display => '', + :null => false, + :name => 'send_no_auto_response_reg_exp', + :tag => 'input', }, ], }, - :state => { + :state => { :value => '(MAILER-DAEMON|postmaster|abuse)@.+?\..+?', }, - :frontend => false + :frontend => false ) Setting.create( @@ -982,21 +1034,21 @@ Setting.create( :options => { :form => [ { - :display => '', - :null => true, - :name => 'chat', - :tag => 'select', - :options => { + :display => '', + :null => true, + :name => 'chat', + :tag => 'boolean', + :options => { true => 'yes', false => 'no', }, }, ], }, - :state => { + :state => { :value => false, }, - :frontend => true + :frontend => true ) diff --git a/lib/google_oauth2_database.rb b/lib/google_oauth2_database.rb new file mode 100644 index 000000000..b7b4691c3 --- /dev/null +++ b/lib/google_oauth2_database.rb @@ -0,0 +1,20 @@ +module OmniAuth + module Strategies + + class GoogleOauth2Database < OmniAuth::Strategies::GoogleOauth2 + option :name, 'google_oauth2' + + def initialize(app, *args, &block) + + # database lookup + puts 'GoogleOauth2Database -> initialize' + config = Setting.get('auth_google_oauth2_credentials') || {} + args[0] = config['client_id'] + args[1] = config['client_secret'] + super + end + + end + + end +end diff --git a/lib/linked_in_database.rb b/lib/linked_in_database.rb new file mode 100644 index 000000000..265b8d06f --- /dev/null +++ b/lib/linked_in_database.rb @@ -0,0 +1,20 @@ +module OmniAuth + module Strategies + + class LinkedInDatabase < OmniAuth::Strategies::LinkedIn + option :name, 'linkedin' + + def initialize(app, *args, &block) + + # database lookup + puts 'LinkedInDatabase -> initialize' + config = Setting.get('auth_linkedin_credentials') || {} + args[0] = config['app_id'] + args[1] = config['app_secret'] + super + end + + end + + end +end