authentication_with_registration_generator 0.4.0 → 0.4.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: f0b23f75ebcd6eb2f59c6de139f976c9fef290c3c815d0dff6ae7a94d1ee6551
4
- data.tar.gz: 37fd9f913c6a36515c64a4490fdd43869d13de837db2b6f840b9c26bb3af5189
3
+ metadata.gz: 8a53cbc855638d51ce2a5de1068d3298c363a9ae7373ed73e5e9b0d68795b0f0
4
+ data.tar.gz: 87663c9181fbfe8e3294206f177fef0fa2300e0ee6196095c5b9e92eda70ca53
5
5
  SHA512:
6
- metadata.gz: d1ff85084c2c42ab83cd6d5858d55cacb5d83bf7617b415b9d067c97109f5ef45102dd01eec8e6e420571c68d8cdaca34f29763a85506e8a934ad0ef630251cf
7
- data.tar.gz: 2084a38f791e245e7e6eb6a30dff29344a770b8597ee3863246d4a6c285ffcbbabe048688b61c1a086753794b7352ef42ac4fa91091ad53cec3b1b7f5d2473b9
6
+ metadata.gz: 02a39377051fb6b42a593a4b42de98539d6b381d15ac677623e0e09cc32c0587783719e6228fe0517af05f47c8e754aea0b9b5fbb3818e202c5d7a68acbf490e
7
+ data.tar.gz: 7ba07bad578487103e57292b9fcf91297c78efec4cffa28cd3ade750e5ec5f4e3d18ec781b6550b321b052c4b2290efe08fd0db45d0f9864c988e592f7e45413
data/README.md CHANGED
@@ -6,24 +6,26 @@ A Rails Generator that adds registration pages to the Authentication Generator a
6
6
  * Adds a registration page which will create a new user with an email address and password.
7
7
  * Adds a link to the registration page on the sign_in page
8
8
  * Adds `new_registration_path` and `registration_path` routes
9
- * Adds '/sign_in' and '/sign_out' routes as alias to '/session/new' and 'session', these can be accessed using the `sign_in_path` and `sign_out_path, method: :delete` helpers
9
+ * Adds '/sign_in' and '/sign_out' routes as alias to '/session/new' and 'session', these can be accessed using the `sign_in_path` and `sign_out_path` helpers
10
10
  * Adds a `link_to_sign_in_or_out` helper that will display a sign out or sign in link depending on if a user is authenticated or not
11
11
  * Adds a `show_user_if_signed_in` method that displays a "signed in as username" message if the user is signed in
12
12
 
13
+ Much of this was based on [this excellent tutorial](https://www.rubanonrails.com/courses/rails-cookie-authentication/lessons/introduction) by @alexandreruban (https://github.com/alexandreruban) that will help you understand how the Authentication Generator works.
14
+
13
15
  ## Installation
14
16
 
15
17
  Install the gem and add to the application's Gemfile by executing:
16
18
 
17
- $ bundle add registration_generator
19
+ $ bundle add authentication_with_registration_generator
18
20
 
19
21
  If bundler is not being used to manage dependencies, install the gem by executing:
20
22
 
21
- $ gem install registration_generator
23
+ $ gem install authentication_with_registration_generator
22
24
 
23
25
  ## Usage
24
26
 
25
27
  ```bash
26
- rails generate registration
28
+ rails generate authentication
27
29
  ```
28
30
 
29
31
  ## Development
@@ -15,8 +15,10 @@ module Authentication
15
15
  user_model_path = "app/models/user.rb"
16
16
 
17
17
  # Check if the validation already exists to prevent duplication
18
- if File.readlines(user_model_path).grep(/validates_uniqueness_of :email_address/).empty?
19
- inject_into_class user_model_path, User, " validates :email_address, uniqueness: true\n"
18
+ if File.exist?(user_model_path)
19
+ if File.readlines(user_model_path).grep(/validates.*:email_address.*uniqueness/).empty?
20
+ inject_into_class user_model_path, "User", " validates :email_address, uniqueness: true\n"
21
+ end
20
22
  end
21
23
  end
22
24
 
@@ -42,7 +44,7 @@ module Authentication
42
44
  if File.exist?(session_view_path)
43
45
  # Replace the "Forgot password?" link with the new links
44
46
  gsub_file session_view_path, /<br>\s*<%= link_to "Forgot password\?", new_password_path %>/ do |match|
45
- "<p>\n <%%= link_to 'Forgot password?', new_password_path %> | \n <%= link_to 'No Account? Register here', new_registration_path %>\n</p>"
47
+ "<p>\n <%= link_to 'Forgot password?', new_password_path %> | \n <%= link_to 'No Account? Register here', new_registration_path %>\n</p>"
46
48
  end
47
49
  else
48
50
  # If the file doesn't exist, handle it accordingly (e.g., raise an error or create the file)
@@ -57,13 +59,13 @@ module Authentication
57
59
  def link_to_sign_in_or_out
58
60
  if authenticated?
59
61
  # Return the form as a string
60
- "<form class=\"button_to\" action=\"\#{sign_out_path}\" accept-charset=\"UTF-8\" method=\"post\">
61
- <input type=\"hidden\" name=\"_method\" value=\"delete\" autocomplete=\"off\" />
62
- <button type=\"submit\">Sign Out</button>
63
- <input type=\"hidden\" name=\"authenticity_token\" value=\"\#{form_authenticity_token}\" autocomplete=\"off\" />
62
+ "<form class=\\"button_to\\" action=\\"\#{sign_out_path}\\" accept-charset=\\"UTF-8\\" method=\\"post\\">
63
+ <input type=\\"hidden\\" name=\\"_method\\" value=\\"delete\\" autocomplete=\\"off\\" />
64
+ <button type=\\"submit\\">Sign Out</button>
65
+ <input type=\\"hidden\\" name=\\"authenticity_token\\" value=\\"\#{form_authenticity_token}\\" autocomplete=\\"off\\" />
64
66
  </form>".html_safe
65
67
  else
66
- "<a href=\"\#{sign_in_path}\">Sign In</a>".html_safe
68
+ "<a href=\\"\#{sign_in_path}\\">Sign In</a>".html_safe
67
69
  end
68
70
  end
69
71
 
@@ -1,24 +1,24 @@
1
1
  class RegistrationsController < ApplicationController
2
2
  allow_unauthenticated_access
3
3
 
4
- def new
5
- @user = User.new
6
- end
4
+ def new
5
+ @user = User.new
6
+ end
7
7
 
8
- def create
9
- @user = User.new(user_params)
8
+ def create
9
+ @user = User.new(user_params)
10
10
 
11
- if @user.save
12
- start_new_session_for @user
13
- redirect_to after_authentication_url, notice: "You have successfully registered!"
14
- else
15
- render :new, status: :unprocessable_entity
16
- end
17
- end
11
+ if @user.save
12
+ start_new_session_for @user
13
+ redirect_to after_authentication_url, notice: "You have successfully registered!"
14
+ else
15
+ render :new, status: :unprocessable_entity
16
+ end
17
+ end
18
18
 
19
- private
19
+ private
20
20
 
21
- def user_params
22
- params.require(:user).permit(:email_address, :password)
23
- end
21
+ def user_params
22
+ params.expect(user: [ :email_address, :password ])
23
+ end
24
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AuthenticationGenerator
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authentication_with_registration_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DAZ
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-02-28 00:00:00.000000000 Z
10
+ date: 2025-04-10 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
@@ -39,11 +38,10 @@ files:
39
38
  - lib/generators/authentication/templates/registrations_controller.rb
40
39
  - lib/generators/authentication_generator.rb
41
40
  - lib/generators/version.rb
42
- homepage: https://github.com/your_username/registration_generator
41
+ homepage: https://github.com/daz4126/authentication_with_registration_generator
43
42
  licenses:
44
43
  - MIT
45
44
  metadata: {}
46
- post_install_message:
47
45
  rdoc_options: []
48
46
  require_paths:
49
47
  - lib
@@ -58,8 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
56
  - !ruby/object:Gem::Version
59
57
  version: '0'
60
58
  requirements: []
61
- rubygems_version: 3.5.11
62
- signing_key:
59
+ rubygems_version: 3.6.3
63
60
  specification_version: 4
64
61
  summary: A Rails generator for user authenticatin with extra registration pages, routes
65
62
  and helpers