rails_mvp_authentication 0.1.0 → 1.0.0
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 +4 -4
- data/README.md +33 -11
- data/lib/generators/rails_mvp_authentication/install_generator.rb +24 -2
- data/lib/generators/rails_mvp_authentication/templates/README +9 -3
- data/lib/generators/rails_mvp_authentication/templates/active_session.rb.tt +5 -0
- data/lib/generators/rails_mvp_authentication/templates/active_sessions_controller.rb.tt +25 -0
- data/lib/generators/rails_mvp_authentication/templates/test/integration/user_interface_test.rb.tt +3 -7
- data/lib/generators/rails_mvp_authentication/templates/test/system/logins_test.rb.tt +2 -0
- data/lib/generators/rails_mvp_authentication/templates/views/users/edit.html.erb.tt +15 -2
- data/lib/generators/rails_mvp_authentication/templates/views/users/new.html.erb.tt +7 -1
- data/lib/rails_mvp_authentication/version.rb +1 -1
- metadata +3 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73ab6be1f27e0a53a60a138930af4d42221df4c65f40b4cb7e0549baaf9dcb38
|
4
|
+
data.tar.gz: 5ba7c94f3dddd7a2875a69ea533618b411bdc4d76fce5fb9568281a0e6211fae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4ef564bf90800390e20304d3fbfed6d7546d4a0168f95442b7ec1a2920aa4ec460ad96f3632f21e18aedb46e389f401733b72c38e3eda7b49ee6c269dacb9f9
|
7
|
+
data.tar.gz: 94a0c77ecbd01adf56d026b0ab357815bfe2726336fddf76739fc6ac406825f8e433486a02c0aa961fb0f0bb0d3c4f6fdd8826a6c542c7c8c13cb9c140f03344
|
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
#
|
2
|
-
Short description and motivation.
|
1
|
+
# 🔐 Rails MVP Authentication
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
An authentication generator for Rails 7. Based on the [step-by-step guide on how to build your own authentication system in Rails from scratch](https://github.com/stevepolitodesign/rails-authentication-from-scratch).
|
4
|
+
|
5
|
+
## 🚀 Installation
|
6
6
|
|
7
|
-
## Installation
|
8
7
|
Add this line to your application's Gemfile:
|
9
8
|
|
10
9
|
```ruby
|
@@ -13,16 +12,39 @@ gem "rails_mvp_authentication"
|
|
13
12
|
|
14
13
|
And then execute:
|
15
14
|
```bash
|
16
|
-
|
15
|
+
bundle
|
17
16
|
```
|
18
17
|
|
19
18
|
Or install it yourself as:
|
20
19
|
```bash
|
21
|
-
|
20
|
+
gem install rails_mvp_authentication
|
21
|
+
```
|
22
|
+
|
23
|
+
Then run the installation command:
|
24
|
+
```bash
|
25
|
+
rails g rails_mvp_authentication:install
|
26
|
+
```
|
27
|
+
|
28
|
+
Once installed make follow these steps:
|
29
|
+
|
30
|
+
1. Run `bundle install` to install [bcrypt](https://rubygems.org/gems/bcrypt/)
|
31
|
+
2. Run `rails db:migrate` to add the `users` and `active_sessions` tables
|
32
|
+
3. Add a root path in `config/routes.rb`
|
33
|
+
4. Ensure you have flash messages in `app/views/layouts/application.html.erb`
|
34
|
+
|
35
|
+
```html+erb
|
36
|
+
<p class="notice"><%= notice %></p>
|
37
|
+
<p class="alert"><%= alert %></p>
|
22
38
|
```
|
23
39
|
|
24
|
-
## Contributing
|
25
|
-
|
40
|
+
## 🙏 Contributing
|
41
|
+
|
42
|
+
If you'd like to open a PR please make sure the following things pass:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
bin/rails test
|
46
|
+
bundle exec standardrb
|
47
|
+
```
|
48
|
+
## 📜 License
|
26
49
|
|
27
|
-
|
28
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
50
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -9,11 +9,15 @@ module RailsMvpAuthentication
|
|
9
9
|
create_users_table
|
10
10
|
modify_users_table
|
11
11
|
create_user_model
|
12
|
+
create_active_sessions_table
|
13
|
+
modify_active_sessions_table
|
14
|
+
create_active_session_model
|
12
15
|
add_bcrypt
|
13
16
|
add_routes
|
14
17
|
create_current_model
|
15
18
|
create_users_controller
|
16
19
|
create_user_views
|
20
|
+
create_active_sessions_controller
|
17
21
|
create_confirmations_controller
|
18
22
|
create_confirmation_views
|
19
23
|
ceate_user_mailer
|
@@ -102,6 +106,18 @@ module RailsMvpAuthentication
|
|
102
106
|
end
|
103
107
|
end
|
104
108
|
|
109
|
+
def create_active_sessions_controller
|
110
|
+
template "active_sessions_controller.rb", "app/controllers/active_sessions_controller.rb"
|
111
|
+
end
|
112
|
+
|
113
|
+
def create_active_session_model
|
114
|
+
template "active_session.rb", "app/models/active_session.rb"
|
115
|
+
end
|
116
|
+
|
117
|
+
def create_active_sessions_table
|
118
|
+
generate "migration", "create_active_sessions user:references user_agent:string ip_address:string remember_token:string:index"
|
119
|
+
end
|
120
|
+
|
105
121
|
def create_authentication_concern
|
106
122
|
template "authentication.rb", "app/controllers/concerns/authentication.rb"
|
107
123
|
end
|
@@ -175,7 +191,7 @@ module RailsMvpAuthentication
|
|
175
191
|
end
|
176
192
|
|
177
193
|
def create_users_table
|
178
|
-
generate "migration", "
|
194
|
+
generate "migration", "create_users email:string:index confirmed_at:datetime password_digest:string unconfirmed_email:string"
|
179
195
|
end
|
180
196
|
|
181
197
|
def create_user_views
|
@@ -195,6 +211,12 @@ module RailsMvpAuthentication
|
|
195
211
|
File.exist?(gemfile)
|
196
212
|
end
|
197
213
|
|
214
|
+
def modify_active_sessions_table
|
215
|
+
migration = Dir.glob(Rails.root.join("db/migrate/*")).max_by { |f| File.mtime(f) }
|
216
|
+
gsub_file migration, /t.string :remember_token/, "t.string :remember_token, null: false"
|
217
|
+
gsub_file migration, /add_index :active_sessions, :remember_token/, "add_index :active_sessions, :remember_token, unique: true"
|
218
|
+
end
|
219
|
+
|
198
220
|
def modify_application_controller
|
199
221
|
inject_into_file "app/controllers/application_controller.rb", "\tinclude Authentication\n", after: "class ApplicationController < ActionController::Base\n"
|
200
222
|
end
|
@@ -232,7 +254,7 @@ module RailsMvpAuthentication
|
|
232
254
|
migration = Dir.glob(Rails.root.join("db/migrate/*")).max_by { |f| File.mtime(f) }
|
233
255
|
gsub_file migration, /t.string :email/, "t.string :email, null: false"
|
234
256
|
gsub_file migration, /t.string :password_digest/, "t.string :password_digest, null: false"
|
235
|
-
gsub_file migration, /add_index :
|
257
|
+
gsub_file migration, /add_index :users, :email/, "add_index :users, :email, unique: true"
|
236
258
|
end
|
237
259
|
|
238
260
|
def path_to(path)
|
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
Next steps 👇
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
1️⃣ Run bundle install
|
6
|
+
2️⃣ Run rails db:migrate
|
7
|
+
3️⃣ Add a root path in config/routes.rb
|
8
|
+
4️⃣ Ensure you have flash messages in app/views/layouts/application.html.erb.
|
9
|
+
|
10
|
+
<p class="notice"><%= notice %></p>
|
11
|
+
<p class="alert"><%= alert %></p>
|
12
|
+
|
13
|
+
=========================================
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class ActiveSessionsController < ApplicationController
|
2
|
+
before_action :authenticate_user!
|
3
|
+
|
4
|
+
def destroy
|
5
|
+
@active_session = current_user.active_sessions.find(params[:id])
|
6
|
+
|
7
|
+
@active_session.destroy
|
8
|
+
|
9
|
+
if current_user
|
10
|
+
redirect_to account_path, notice: "Session deleted."
|
11
|
+
else
|
12
|
+
forget_active_session
|
13
|
+
reset_session
|
14
|
+
redirect_to root_path, notice: "Signed out."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy_all
|
19
|
+
forget_active_session
|
20
|
+
current_user.active_sessions.destroy_all
|
21
|
+
reset_session
|
22
|
+
|
23
|
+
redirect_to root_path, notice: "Signed out."
|
24
|
+
end
|
25
|
+
end
|
data/lib/generators/rails_mvp_authentication/templates/test/integration/user_interface_test.rb.tt
CHANGED
@@ -19,16 +19,12 @@ class UserInterfaceTest < ActionDispatch::IntegrationTest
|
|
19
19
|
login @confirmed_user
|
20
20
|
|
21
21
|
get account_path
|
22
|
-
|
23
|
-
assert_select "
|
24
|
-
assert_select "[value=?]", "Log out of all other sessions"
|
25
|
-
end
|
22
|
+
|
23
|
+
assert_select "button", "Log out of all other sessions"
|
26
24
|
assert_match destroy_all_active_sessions_path, @response.body
|
27
25
|
|
28
26
|
assert_select "table" do
|
29
|
-
assert_select "
|
30
|
-
assert_select "[value=?]", "Sign Out"
|
31
|
-
end
|
27
|
+
assert_select "button", "Sign Out"
|
32
28
|
end
|
33
29
|
assert_match active_session_path(@confirmed_user.active_sessions.last), @response.body
|
34
30
|
end
|
@@ -11,6 +11,8 @@ class LoginsTest < ApplicationSystemTestCase
|
|
11
11
|
fill_in "Email", with: @confirmed_user.email
|
12
12
|
fill_in "Password", with: @confirmed_user.password
|
13
13
|
click_on "Sign In"
|
14
|
+
|
15
|
+
sleep 0.1
|
14
16
|
|
15
17
|
assert_not_nil @confirmed_user.active_sessions.last.user_agent
|
16
18
|
assert_not_nil @confirmed_user.active_sessions.last.ip_address
|
@@ -1,5 +1,11 @@
|
|
1
1
|
<%%= form_with model: @user, url: account_path, method: :put do |form| %>
|
2
|
-
|
2
|
+
<%% if form.object.errors.any? %>
|
3
|
+
<ul>
|
4
|
+
<%% form.object.errors.full_messages.each do |message| %>
|
5
|
+
<li><%%= message %></li>
|
6
|
+
<%% end %>
|
7
|
+
</ul>
|
8
|
+
<%% end %>
|
3
9
|
<div>
|
4
10
|
<%%= form.label :email, "Current Email" %>
|
5
11
|
<%%= form.email_field :email, disabled: true %>
|
@@ -36,7 +42,14 @@
|
|
36
42
|
</tr>
|
37
43
|
</thead>
|
38
44
|
<tbody>
|
39
|
-
|
45
|
+
<%% @active_sessions.each do |active_session| %>
|
46
|
+
<tr>
|
47
|
+
<td><%%= active_session.user_agent %></td>
|
48
|
+
<td><%%= active_session.ip_address %></td>
|
49
|
+
<td><%%= active_session.created_at %></td>
|
50
|
+
<td><%%= button_to "Sign Out", active_session_path(active_session), method: :delete %></td>
|
51
|
+
</tr>
|
52
|
+
<%% end %>
|
40
53
|
</tbody>
|
41
54
|
</table>
|
42
55
|
<%% end %>
|
@@ -1,5 +1,11 @@
|
|
1
1
|
<%%= form_with model: @user, url: sign_up_path do |form| %>
|
2
|
-
|
2
|
+
<%% if form.object.errors.any? %>
|
3
|
+
<ul>
|
4
|
+
<%% form.object.errors.full_messages.each do |message| %>
|
5
|
+
<li><%%= message %></li>
|
6
|
+
<%% end %>
|
7
|
+
</ul>
|
8
|
+
<%% end %>
|
3
9
|
<div>
|
4
10
|
<%%= form.label :email %>
|
5
11
|
<%%= form.email_field :email, required: true %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_mvp_authentication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Polito
|
@@ -24,26 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 7.0.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: sprockets-rails
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.4'
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 3.4.2
|
37
|
-
type: :runtime
|
38
|
-
prerelease: false
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - "~>"
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '3.4'
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 3.4.2
|
47
27
|
description: Rails authentication via a generator.
|
48
28
|
email:
|
49
29
|
- stevepolito@hey.com
|
@@ -66,6 +46,8 @@ files:
|
|
66
46
|
- lib/generators/rails_mvp_authentication/USAGE
|
67
47
|
- lib/generators/rails_mvp_authentication/install_generator.rb
|
68
48
|
- lib/generators/rails_mvp_authentication/templates/README
|
49
|
+
- lib/generators/rails_mvp_authentication/templates/active_session.rb.tt
|
50
|
+
- lib/generators/rails_mvp_authentication/templates/active_sessions_controller.rb.tt
|
69
51
|
- lib/generators/rails_mvp_authentication/templates/authentication.rb.tt
|
70
52
|
- lib/generators/rails_mvp_authentication/templates/confirmations_controller.rb.tt
|
71
53
|
- lib/generators/rails_mvp_authentication/templates/current.rb.tt
|