diff --git a/app/assets/javascripts/casino/application.js b/app/assets/javascripts/casino/application.js new file mode 100644 index 00000000..deb8738d --- /dev/null +++ b/app/assets/javascripts/casino/application.js @@ -0,0 +1 @@ +// Place all the behaviors and hooks related to the matching controller here. diff --git a/app/assets/javascripts/casino/application.js.coffee b/app/assets/javascripts/casino/application.js.coffee deleted file mode 100644 index 564c402c..00000000 --- a/app/assets/javascripts/casino/application.js.coffee +++ /dev/null @@ -1,5 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ -jQuery -> - $("input[type='text']:first", document.forms[0]).focus() diff --git a/app/assets/javascripts/casino/index.js b/app/assets/javascripts/casino/index.js index 9097d830..15ebed94 100644 --- a/app/assets/javascripts/casino/index.js +++ b/app/assets/javascripts/casino/index.js @@ -10,6 +10,4 @@ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. // -//= require jquery -//= require jquery_ujs //= require_tree . diff --git a/app/assets/javascripts/casino/sessions.js b/app/assets/javascripts/casino/sessions.js new file mode 100644 index 00000000..7a558737 --- /dev/null +++ b/app/assets/javascripts/casino/sessions.js @@ -0,0 +1,23 @@ +(function(win, doc) { + var url = '/login', + cookie_regex = /(^|;)\s*tgt=/; + + function checkCookieExists() { + var serviceEl = doc.getElementById('service'), + svcValue = serviceEl ? serviceEl.getAttribute('value') : null; + + if(svcValue) { + if(cookie_regex.test(doc.cookie)) { + win.location = url + '?service=' + encodeURIComponent(svcValue); + } + } else { + setTimeout(checkCookieExists, 1000); + } + } + + // Auto-login when logged-in in other browser window (9887c4e) + if(doc.getElementById('login-form')) { + checkCookieExists(); + } + +})(this, document); diff --git a/app/assets/javascripts/casino/sessions.js.coffee b/app/assets/javascripts/casino/sessions.js.coffee deleted file mode 100644 index 088c46bc..00000000 --- a/app/assets/javascripts/casino/sessions.js.coffee +++ /dev/null @@ -1,15 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ -jQuery -> - if $('#login-form').length - cookie_regex = /(^|;)\s*tgt=/ - checkCookieExists = -> - if(cookie_regex.test(document.cookie)) - service = $('#service').val() - url = '/login' - url += ('?service=' + encodeURIComponent(service)) if service - window.location = url - else - setTimeout(checkCookieExists, 1000) - checkCookieExists() diff --git a/app/views/casino/sessions/new.html.erb b/app/views/casino/sessions/new.html.erb index a7a77f6a..4ad033c0 100644 --- a/app/views/casino/sessions/new.html.erb +++ b/app/views/casino/sessions/new.html.erb @@ -16,7 +16,7 @@ <%= hidden_field_tag :lt, @login_ticket.ticket %> <%= hidden_field_tag :service, params[:service] unless params[:service].nil? %> <%= label_tag :username, t('login.label_username') %> - <%= text_field_tag :username, params[:username] %> + <%= text_field_tag :username, params[:username], autofocus:true %> <%= label_tag :password, t('login.label_password') %> <%= password_field_tag :password %> <%= label_tag :rememberMe do %> @@ -28,3 +28,7 @@ <%= render 'footer' %> + +<%= javascript_tag do %> + <%= Rails.application.assets.find_asset('casino/sessions').to_s.html_safe %> +<% end %> diff --git a/app/views/casino/sessions/validate_otp.html.erb b/app/views/casino/sessions/validate_otp.html.erb index 47c5e4c3..c3122cfc 100644 --- a/app/views/casino/sessions/validate_otp.html.erb +++ b/app/views/casino/sessions/validate_otp.html.erb @@ -8,7 +8,7 @@ <%= hidden_field_tag :tgt, @ticket_granting_ticket || params[:tgt] %> <%= hidden_field_tag :service, params[:service] %> <%= label_tag :code, t('validate_otp.code') %> - <%= text_field_tag :otp, nil, maxlength: 6 %> + <%= text_field_tag :otp, nil, maxlength: 6, autofocus:true %> <%= button_tag t('validate_otp.submit'), :class => 'button' %> <% end %> diff --git a/app/views/casino/two_factor_authenticators/new.html.erb b/app/views/casino/two_factor_authenticators/new.html.erb index ae4d7e9f..c09eebcd 100644 --- a/app/views/casino/two_factor_authenticators/new.html.erb +++ b/app/views/casino/two_factor_authenticators/new.html.erb @@ -22,7 +22,7 @@ <%= form_tag(two_factor_authenticators_path, method: :post, id: 'two_factor_authenticators-form') do %> <%= hidden_field_tag :id, @two_factor_authenticator.id %> <%= label_tag :code, t('two_factor_authenticators.code') %> - <%= text_field_tag :otp, nil, maxlength: 6 %> + <%= text_field_tag :otp, nil, maxlength: 6, autofocus:true %> <%= link_to t('two_factor_authenticators.cancel'), sessions_path, :class => 'secondary button' %> <%= button_tag t('two_factor_authenticators.submit'), :class => 'button' %> <% end %> diff --git a/casino.gemspec b/casino.gemspec index 2e3b068a..5733a22c 100644 --- a/casino.gemspec +++ b/casino.gemspec @@ -33,7 +33,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'coveralls', '~> 0.7' s.add_runtime_dependency 'rails', '~> 3.2.9' - s.add_runtime_dependency 'jquery-rails', '~> 2.1' s.add_runtime_dependency 'http_accept_language', '~> 2.0.0.pre' s.add_runtime_dependency 'addressable', '~> 2.3' s.add_runtime_dependency 'terminal-table', '~> 1.4'