any_login 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0dc9ff7dec47ebdcb17659928d9506d65ba25a8c42291a9f15f38bb71503a69
4
- data.tar.gz: 72d8bb2f965b20a3aa10d0008f0ce46034064f8218dc0fc23e78ff1c9cde37ab
3
+ metadata.gz: 26b0fb1dfbe9f3264c85b6c48f4ee21294d89508d85ba97593bddc40e9e54416
4
+ data.tar.gz: 47d03dfbcc2c4de800d0be35da07a932d258b4bc515472fc544386d12f7ba67c
5
5
  SHA512:
6
- metadata.gz: b4a8c6731ce47c9493e7cfd9b2d2689132243ebb8e8709e1958bd2fd25b41ebe1ea435dd941a030671638425e5cf69ac496e9a8ee2892b4fb88aef1d1fb4d213
7
- data.tar.gz: e43dc1fb5665cbc16e3bbc90cc49f4553b840f6c4cd1d91927b5fd1d2a441e4c5fb3aed47de089036192537c86f61541632b9c95191aa63b94730e32919bd438
6
+ metadata.gz: d0731a0d850049fd8e7a8e7e526c9d150657735f1b134b0879b98c2c2336bb4419f5f90f6524fdce44c7593d9efa42958a32e4d1537316d40eaaeeec8b03e9d3
7
+ data.tar.gz: 2e0004a1d244d33b754d2de757d5bab74027811130150689a36c29af3db3d075d31f6beb4f1626b90117196e07685a5257df2a7a96e13b940a130f5200def91c
@@ -0,0 +1,23 @@
1
+ function submitOnChange() {
2
+ document.getElementById('any_login_form').submit();
3
+ }
4
+
5
+ function elementExists(element) {
6
+ return typeof (element) != 'undefined' && element != null;
7
+ }
8
+
9
+ function addChangeListenerTo(elementId) {
10
+ let element = document.getElementById(elementId);
11
+ if (elementExists(element)) {
12
+ element.addEventListener("change", submitOnChange);
13
+ }
14
+ }
15
+
16
+ function setupAnyLoginHandlers() {
17
+ addChangeListenerTo("back_to_previous_id");
18
+ addChangeListenerTo("selected_id");
19
+ }
20
+
21
+ ['DOMContentLoaded', 'turbolinks:load', 'turbo:load'].forEach(function(e) {
22
+ window.addEventListener(e, setupAnyLoginHandlers);
23
+ });
@@ -0,0 +1,96 @@
1
+ #any_login {
2
+ position: fixed;
3
+ opacity: 0.5;
4
+ background: #5c4383;
5
+ color: white;
6
+ font-size: 16px;
7
+ line-height: 20px;
8
+ z-index: 10000;
9
+ }
10
+
11
+ #any_login form {
12
+ margin: 0;
13
+ height: auto;
14
+ padding: 4px 6px;
15
+ }
16
+
17
+ #any_login #any_login_box {
18
+ display: none;
19
+ vertical-align: middle;
20
+ }
21
+
22
+ #any_login_form_toggle {
23
+ display: none;
24
+ }
25
+
26
+ #any_login_form_toggle[type=checkbox]:checked ~ #any_login_box {
27
+ display: inline;
28
+ }
29
+
30
+ #any_login input,
31
+ #any_login select {
32
+ color: black;
33
+ padding: 0;
34
+ margin: 0;
35
+ height: auto;
36
+ float: none;
37
+ text-decoration: none;
38
+ position: unset;
39
+ left: auto;
40
+ top: auto;
41
+ font-size: auto;
42
+ line-height: auto;
43
+ }
44
+
45
+ #any_login.any_login_top_left {
46
+ top: 0;
47
+ left: 0;
48
+ }
49
+
50
+ #any_login.any_login_top_right {
51
+ top: 0;
52
+ right: 0;
53
+ }
54
+
55
+ #any_login.any_login_bottom_left {
56
+ bottom: 0;
57
+ left: 0;
58
+ }
59
+
60
+ #any_login.any_login_bottom_right {
61
+ bottom: 0;
62
+ right: 0;
63
+ }
64
+
65
+ #any_login svg {
66
+ cursor: pointer;
67
+ vertical-align: middle;
68
+ fill: #fff;
69
+ }
70
+
71
+ #any_login:hover {
72
+ opacity: 1;
73
+ }
74
+
75
+ #any_login .any_login_user_information {
76
+ padding-left: 10px;
77
+ color: yellow;
78
+ }
79
+
80
+ #any_login #any_login_id_input {
81
+ width: 30px;
82
+ }
83
+
84
+ #any_login span#current_user_information {
85
+ display: inline;
86
+ }
87
+
88
+ #any_login span#current_user_information span {
89
+ display: inline;
90
+ }
91
+
92
+ #any_login span#anylogin_back_to_user {
93
+ padding-left: 15px;
94
+ color: cyan;
95
+ display: inline;
96
+ }
@@ -1,5 +1,8 @@
1
1
  module AnyLogin
2
2
  class ApplicationController < ActionController::Base
3
+ protect_from_forgery except: :js
4
+ before_action :try_not_to_leak_any_login_is_installed
5
+
3
6
  include AnyLogin.provider.constantize::Controller
4
7
  include ::Clearance::Controller if AnyLogin.provider.eql?("AnyLogin::Provider::Clearance")
5
8
 
@@ -11,12 +14,19 @@ module AnyLogin
11
14
  end
12
15
 
13
16
  def any_login
14
- try_not_to_leak_any_login_is_installed
15
17
  head 403 && return unless AnyLogin.verify_access_proc.call(self)
16
18
  add_to_previous
17
19
  AnyLogin.provider.constantize::Controller.instance_method(:any_login_sign_in).bind(self).call
18
20
  end
19
21
 
22
+ def css
23
+ send_file AnyLogin::Engine.root.join('app', 'assets', 'stylesheets', 'any_login', 'application.css'), content_type: 'text/css'
24
+ end
25
+
26
+ def js
27
+ send_file AnyLogin::Engine.root.join('app', 'assets', 'javascripts', 'any_login', 'application.js'), content_type: 'text/javascript'
28
+ end
29
+
20
30
  private
21
31
 
22
32
  def try_not_to_leak_any_login_is_installed
@@ -1,7 +1,13 @@
1
+ <script src="<%= any_login.js_path %>"></script>
2
+ <link rel="stylesheet" href="<%= any_login.css_path %>">
3
+
1
4
  <div id='any_login' class='<%= any_login_klasses %>'>
2
5
  <%= form_tag any_login.sign_in_path, :method => :post, :id => 'any_login_form' do %>
3
- <%= image_tag 'any_login/person.png', :alt => AnyLogin.klass, :onclick => "AnyLogin.on_image_click();" %>
4
- <span id='any_login_box' class='hidden_box'>
6
+ <label for="any_login_form_toggle" id="any_login_form_toggle_label">
7
+ <%= render 'any_login/svg/user', :title => AnyLogin.klass %>
8
+ </label>
9
+ <input type="checkbox" id="any_login_form_toggle" <%= AnyLogin.auto_show ? "checked" : "" %>>
10
+ <span id='any_login_box'>
5
11
  <%= any_login_select %>
6
12
  or by
7
13
  <%= any_login_id_input %>
@@ -11,136 +17,3 @@
11
17
  </span>
12
18
  <% end %>
13
19
  </div>
14
-
15
- <script type="text/javascript" charset="utf-8">
16
- Element.prototype.hasClass = function (className) {
17
- return new RegExp(' ' + className + ' ').test(' ' + this.className + ' ');
18
- };
19
-
20
- Element.prototype.addClass = function (className) {
21
- if (!this.hasClass(className)) {
22
- this.className += ' ' + className;
23
- }
24
- };
25
-
26
- Element.prototype.removeClass = function (className) {
27
- var newClass = ' ' + this.className.replace(/[\t\r\n]/g, ' ') + ' '
28
- if (this.hasClass(className)) {
29
- while (newClass.indexOf( ' ' + className + ' ') >= 0) {
30
- newClass = newClass.replace(' ' + className + ' ', ' ');
31
- }
32
- this.className = newClass.replace(/^\s+|\s+$/g, ' ');
33
- }
34
- };
35
- Element.prototype.toggleClass = function (className) {
36
- var newClass = ' ' + this.className.replace(/[\t\r\n]/g, " ") + ' ';
37
- if (this.hasClass(className)) {
38
- while (newClass.indexOf(" " + className + " ") >= 0) {
39
- newClass = newClass.replace(" " + className + " ", " ");
40
- }
41
- this.className = newClass.replace(/^\s+|\s+$/g, ' ');
42
- } else {
43
- this.className += ' ' + className;
44
- }
45
- };
46
-
47
- var AnyLogin = {};
48
- AnyLogin.on_image_click = function() {
49
- var elem = document.getElementById('any_login_box');
50
- elem.toggleClass("hidden_box");
51
- elem.toggleClass("visible_box");
52
- };
53
- AnyLogin.on_select_change = function() {
54
- document.getElementById('any_login_form').submit();
55
- };
56
- </script>
57
-
58
- <style type="text/css" media="screen">
59
- #any_login {
60
- position: fixed;
61
- opacity: 0.5;
62
- background: #5c4383;
63
- color: white;
64
- font-size: 16px;
65
- line-height: 20px;
66
- z-index: 10000;
67
- }
68
- #any_login form {
69
- padding: 0;
70
- margin: 0;
71
- height: auto;
72
- }
73
- #any_login input, #any_login select {
74
- color: black;
75
- padding: 0;
76
- margin: 0;
77
- height: auto;
78
- float: none;
79
- text-decoration: none;
80
- position: unset;
81
- left: auto;
82
- top: auto;
83
- font-size: auto;
84
- line-height: auto;
85
- }
86
- #any_login .hidden_box {
87
- display: none;
88
- }
89
- #any_login .visible_box {
90
- display: inline;
91
- }
92
- #any_login.any_login_top_left {
93
- top: 0;
94
- left: 0;
95
- }
96
- #any_login.any_login_top_right {
97
- top: 0;
98
- right: 0;
99
- }
100
- #any_login.any_login_bottom_left {
101
- bottom: 0;
102
- left: 0;
103
- }
104
- #any_login.any_login_bottom_right {
105
- bottom: 0;
106
- right: 0;
107
- }
108
- #any_login.any_login_visible {
109
- opacity: 1;
110
- }
111
- #any_login img {
112
- cursor: pointer;
113
- vertical-align: middle;
114
- }
115
- #any_login:hover {
116
- opacity: 1;
117
- }
118
- #any_login form {
119
- padding: 4px 6px;
120
- }
121
- #any_login span {
122
- display: none;
123
- vertical-align: middle;
124
- }
125
- #any_login.any_login_auto_show span {
126
- display: inline;
127
- }
128
- #any_login .any_login_user_information {
129
- padding-left: 10px;
130
- color: yellow;
131
- }
132
- #any_login #any_login_id_input {
133
- width: 30px;
134
- }
135
- #any_login span#current_user_information {
136
- display: inline;
137
- }
138
- #any_login span#current_user_information span {
139
- display: inline;
140
- }
141
- #any_login span#anylogin_back_to_user {
142
- padding-left: 15px;
143
- color: cyan;
144
- display: inline;
145
- }
146
- </style>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" ?>
2
+ <svg style="enable-background:new 0 0 24 24;" version="1.1" viewBox="0 0 24 24" height="16" width="16" role="img"
3
+ xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
4
+ <title><%= title %></title>
5
+ <g id="info" />
6
+ <g id="icons">
7
+ <g id="user">
8
+ <ellipse cx="12" cy="8" rx="5" ry="6" />
9
+ <path
10
+ d="M21.8,19.1c-0.9-1.8-2.6-3.3-4.8-4.2c-0.6-0.2-1.3-0.2-1.8,0.1c-1,0.6-2,0.9-3.2,0.9s-2.2-0.3-3.2-0.9 C8.3,14.8,7.6,14.7,7,15c-2.2,0.9-3.9,2.4-4.8,4.2C1.5,20.5,2.6,22,4.1,22h15.8C21.4,22,22.5,20.5,21.8,19.1z" />
11
+ </g>
12
+ </g>
13
+ </svg>
data/config/routes.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  AnyLogin::Engine.routes.draw do
2
+ get '/any_login/js' => 'application#js', as: :js
3
+ get '/any_login/css' => 'application#css', as: :css
2
4
  post '/any_login/sign_in' => 'application#any_login', as: :sign_in
3
5
  end
4
6
 
@@ -2,10 +2,6 @@ module AnyLogin
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace AnyLogin
4
4
 
5
- initializer 'any_login.assets_precompile', :group => :all do |app|
6
- app.config.assets.precompile += ['any_login/person.png']
7
- end
8
-
9
5
  initializer 'any_login.helpers' do
10
6
  load_provider
11
7
  ActiveSupport.on_load :action_controller do
@@ -53,7 +53,6 @@ module AnyLogin
53
53
 
54
54
  def select_html_options(prompt = AnyLogin.select_prompt)
55
55
  options = {}
56
- options[:onchange] = 'AnyLogin.on_select_change();' if AnyLogin.login_on == :both
57
56
  options[:prompt] = prompt
58
57
  options
59
58
  end
@@ -61,7 +60,6 @@ module AnyLogin
61
60
  def any_login_klasses
62
61
  klasses = []
63
62
  klasses << "any_login_#{AnyLogin.position || 'bottom_left'}"
64
- klasses << 'any_login_auto_show' if AnyLogin.auto_show
65
63
  klasses.join(' ')
66
64
  end
67
65
 
@@ -1,3 +1,3 @@
1
1
  module AnyLogin
2
- VERSION = '1.5.0'
2
+ VERSION = '1.5.1'
3
3
  end
@@ -15,7 +15,7 @@ class NavigationTest < ActionDispatch::IntegrationTest
15
15
  test "it properly logs users in and allows access to the secret page" do
16
16
  visit "/"
17
17
 
18
- find("#any_login_form").click
18
+ find("#any_login_form_toggle_label").click
19
19
  find('#selected_id option:last-of-type').select_option
20
20
 
21
21
  visit "/about"
@@ -14,7 +14,7 @@ class NavigationTest < ActionDispatch::IntegrationTest
14
14
  test "it properly logs users in and allows access to the secret page" do
15
15
  visit "/"
16
16
 
17
- find("#any_login_form").click
17
+ find("#any_login_form_toggle_label").click
18
18
  find('#selected_id option:last-of-type').select_option
19
19
 
20
20
  visit "/about"
@@ -14,7 +14,7 @@ class NavigationTest < ActionDispatch::IntegrationTest
14
14
  test "it properly logs users in and allows access to the secret page" do
15
15
  visit "/"
16
16
 
17
- find("#any_login_form").click
17
+ find("#any_login_form_toggle_label").click
18
18
  # There is an instability in the test suite where the option on the dropdown sometimes shows
19
19
  # up as `1` and sometimes shows up as `test@test.com`. This works around the issue.
20
20
  find('#selected_id option:last-of-type').select_option
@@ -14,7 +14,7 @@ class NavigationTest < ActionDispatch::IntegrationTest
14
14
  test "it properly logs users in and allows access to the secret page" do
15
15
  visit "/"
16
16
 
17
- find("#any_login_form").click
17
+ find("#any_login_form_toggle_label").click
18
18
  find('#selected_id option:last-of-type').select_option
19
19
 
20
20
  visit "/about"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: any_login
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-29 00:00:00.000000000 Z
11
+ date: 2022-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -48,9 +48,11 @@ extra_rdoc_files: []
48
48
  files:
49
49
  - MIT-LICENSE
50
50
  - Rakefile
51
- - app/assets/images/any_login/person.png
51
+ - app/assets/javascripts/any_login/application.js
52
+ - app/assets/stylesheets/any_login/application.css
52
53
  - app/controllers/any_login/application_controller.rb
53
54
  - app/views/any_login/_any_login.html.erb
55
+ - app/views/any_login/svg/_user.html.erb
54
56
  - config/routes.rb
55
57
  - lib/any_login.rb
56
58
  - lib/any_login/collection.rb
Binary file