action_auth 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfb772199a2e02caffc9981547bdaad51ace6468e80bbae4c1123199fb5a23b1
4
- data.tar.gz: 5334fce103771564856a60e164e8d430808bf472f9ec0296e25494e7b7fcb77e
3
+ metadata.gz: 3241fccee9fc330469fa84edd693d48755d96c2d74396c16c101860ffe4cfbc9
4
+ data.tar.gz: 48a479437297feaff6eb40135dd9ae963821950b084a2f19cb877c752ca42261
5
5
  SHA512:
6
- metadata.gz: 79918e0da74283c432ddf797abad040a3fade7923f61c9d5e055d0cc15728b1f975e09ea6e6be669810979a9b3f1d9c054c3a07288c406bfe96c89a42c118a5a
7
- data.tar.gz: 334b0d68ae98187e9b909f34d325cdcaffe051c7ada97045a7d8d90169be60defcd881b09b339764c3791c9ce0b2c326681fd943deeb58165928b696eb34355d
6
+ metadata.gz: f9fa30b51192ab5291349f95d0b49237a09cbd41c85dcea3e7920ae6cad3f889a95661356bce4de4b2bb89be8789e5c9023498aad166580aa7027af4562991b1
7
+ data.tar.gz: c5be4a6316acd4923803bbecd77e0252b438c8ff844983db495f5abf969a26576d280f5c0cd9d0844736620ec0e1cd67c4ed310180ac2bbc1197efb6811d64a2
data/README.md CHANGED
@@ -69,20 +69,64 @@ These are the planned features for ActionAuth. The ones that are checked off are
69
69
 
70
70
  Within your application, you'll have access to these routes. They have been styled to be consistent with Devise.
71
71
 
72
- Method Verb Params Description
73
- user_sessions_path GET Device session management
74
- user_session_path DELETE [:id] Log Out
75
- new_user_session_path GET Log in
76
- new_user_registration_path GET Sign Up
77
- edit_password_path GET Change Password
78
- password_path PATCH Update Password
72
+ Method Verb Params Description
73
+ user_sessions_path GET Device session management
74
+ user_session_path DELETE [:id] Log Out
75
+ new_user_session_path GET Log in
76
+ new_user_registration_path GET Sign Up
77
+ edit_password_path GET Change Password
78
+ password_path PATCH Update Password
79
79
 
80
80
  ### Helper Methods
81
81
 
82
- Method Description
83
- current_user Returns the currently logged in user
84
- user_signed_in? Returns true if the user is logged in
85
- current_session Returns the current session
82
+ Method Description
83
+ current_user Returns the currently logged in user
84
+ user_signed_in? Returns true if the user is logged in
85
+ current_session Returns the current session
86
+
87
+ ### Restricting and Changing Routes with Constraints
88
+
89
+ Sometimes, there could be some routes that you would want to prevent access to unless the
90
+ user is an admin. These routes could be for managing users, or other sensitive data. You
91
+ can create a constraint to restrict access to these routes.
92
+
93
+ # app/constraints/admin_constraint.rb
94
+
95
+ class AdminConstraint
96
+ def self.matches?(request)
97
+ user = current_user(request)
98
+ user && user.admin?
99
+ end
100
+
101
+ def self.current_user(request)
102
+ session_token = request.cookie_jar.signed[:session_token]
103
+ ActionAuth::Session.find_by(id: session_token)&.action_auth_user
104
+ end
105
+ end
106
+
107
+ # config/routes.rb
108
+
109
+ constraints AdminConstraint do
110
+ mount GoodJob::Engine => 'good_job'
111
+ end
112
+
113
+ Other times, you may want to have a different kind of view for a user that is logged in
114
+ versus a user that is not logged in.
115
+
116
+ # app/constraints/authenticated_constraint.rb
117
+ class AuthenticatedConstraint
118
+ def self.matches?(request)
119
+ session_token = request.cookie_jar.signed[:session_token]
120
+ ActionAuth::Session.exists?(session_token)
121
+ end
122
+ end
123
+
124
+ # config/routes.rb
125
+ constraints AuthenticatedConstraint do
126
+ root to: 'dashboard#index'
127
+ end
128
+ root to: 'welcome#index'
129
+
86
130
 
87
131
  ## License
88
132
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -29,6 +29,21 @@ body {
29
29
  background-color: rgb(255, 255, 255) !important;
30
30
  }
31
31
 
32
+ .container-fluid {
33
+ -webkit-text-size-adjust: 100%;
34
+ -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
35
+ box-sizing: border-box;
36
+ width: 100%;
37
+ padding-right: 12px;
38
+ padding-left: 12px;
39
+ margin-right: auto;
40
+ margin-left: auto;
41
+ max-width: 1140px;
42
+ border: solid 1px rgb(222, 226, 230) !important;
43
+ padding-bottom: 1rem !important;
44
+ background-color: rgb(255, 255, 255) !important;
45
+ }
46
+
32
47
  input[type="text"],
33
48
  input[type="email"],
34
49
  input[type="password"] {
@@ -99,3 +114,43 @@ input[type="password"] {
99
114
  background-color: #007bff;
100
115
  border-color: #007bff;
101
116
  }
117
+
118
+ .action-auth--table {
119
+ width: 100%;
120
+ border-collapse: separate;
121
+ border-spacing: 0;
122
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
123
+ font-family: 'Arial', sans-serif;
124
+ overflow: hidden;
125
+ margin: 20px 0;
126
+ }
127
+
128
+ .action-auth--table thead {
129
+ background-color: #007BFF;
130
+ color: #ffffff;
131
+ }
132
+
133
+ .action-auth--table th,
134
+ .action-auth--table td {
135
+ padding: 12px 15px;
136
+ text-align: left;
137
+ border-bottom: 1px solid #dddddd;
138
+ }
139
+
140
+ .action-auth--table tr:last-child {
141
+ border-bottom: none;
142
+ }
143
+
144
+ .action-auth--table th {
145
+ position: sticky;
146
+ top: 0;
147
+ z-index: 10;
148
+ }
149
+
150
+ .action-auth--table tbody tr:hover {
151
+ background-color: #f1f1f1;
152
+ }
153
+
154
+ .action-auth--table td {
155
+ transition: background-color 0.3s;
156
+ }
@@ -1,7 +1,7 @@
1
1
  module ActionAuth
2
2
  class SessionsController < ApplicationController
3
3
  before_action :set_current_request_details
4
-
4
+ layout "action_auth/application-full-width", only: :index
5
5
  def index
6
6
  @sessions = Current.user.action_auth_sessions.order(created_at: :desc)
7
7
  end
@@ -3,27 +3,25 @@
3
3
  <h1>Devices & Sessions</h1>
4
4
 
5
5
  <div id="sessions">
6
- <% @sessions.each do |session| %>
7
- <div id="<%= dom_id session %>">
8
- <p>
9
- <strong>User Agent:</strong>
10
- <%= session.user_agent %>
11
- </p>
12
-
13
- <p>
14
- <strong>Ip Address:</strong>
15
- <%= session.ip_address %>
16
- </p>
17
-
18
- <p>
19
- <strong>Created at:</strong>
20
- <%= session.created_at %>
21
- </p>
22
-
23
- </div>
24
- <p>
25
- <%= button_to "Log out", session, method: :delete %>
26
- </p>
27
- <% end %>
6
+ <table class="action-auth--table">
7
+ <thead>
8
+ <tr>
9
+ <th>User Agent</th>
10
+ <th nowrap>Ip Address</th>
11
+ <th nowrap>Created at</th>
12
+ <th nowrap></th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <% @sessions.each do |session| %>
17
+ <%= content_tag :tr, id: dom_id(session) do %>
18
+ <td><%= session.user_agent %></td>
19
+ <td nowrap><%= session.ip_address %></td>
20
+ <td nowrap><%= session.created_at %></td>
21
+ <td nowrap><%= button_to "Log out", session, method: :delete, class: "btn btn-primary" %></td>
22
+ <% end %>
23
+ <% end %>
24
+ </tbody>
25
+ </table>
28
26
  </div>
29
27
 
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Action Auth</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+ <%= stylesheet_link_tag "action_auth/application", media: "all" %>
8
+ </head>
9
+ <body class="bg-light">
10
+ <div class="container-fluid bg-white border pb-3">
11
+ <%= yield %>
12
+ </div>
13
+ </body>
14
+ </html>
@@ -1,11 +1,10 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>Action auth</title>
4
+ <title>Action Auth</title>
5
5
  <%= csrf_meta_tags %>
6
6
  <%= csp_meta_tag %>
7
-
8
- <%= stylesheet_link_tag "action_auth/application", media: "all" %>
7
+ <%= stylesheet_link_tag "action_auth/application", media: "all" %>
9
8
  </head>
10
9
  <body class="bg-light">
11
10
  <div class="container bg-white border pb-3">
@@ -1,3 +1,3 @@
1
1
  module ActionAuth
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Kimura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-09 00:00:00.000000000 Z
11
+ date: 2023-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -77,6 +77,7 @@ files:
77
77
  - app/views/action_auth/user_mailer/email_verification.text.erb
78
78
  - app/views/action_auth/user_mailer/password_reset.html.erb
79
79
  - app/views/action_auth/user_mailer/password_reset.text.erb
80
+ - app/views/layouts/action_auth/application-full-width.html.erb
80
81
  - app/views/layouts/action_auth/application.html.erb
81
82
  - app/views/layouts/action_auth/mailer.html.erb
82
83
  - app/views/layouts/action_auth/mailer.text.erb