authentication_with_registration_generator 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4681439bb93e7104bd2fb5e81beb6d3bdebe2fa7b3f41ab40bf1667d1ec95560
4
+ data.tar.gz: 528b29f802154e3d896ba1a9c8a96cf3d7e2d8b7f406a774040050e5503ee962
5
+ SHA512:
6
+ metadata.gz: 8e1b97b25be5535e159020308bc0592d97e574b23074f77f7b750f973966e58303f114ac1e43f77dfc419f224017ac9b99072c0d9965ab2aa02d037919f1d565
7
+ data.tar.gz: 3684fb7b2a2dd034464294b7c6edb0884a01e0d4d55ac60f06ed9f2a929eb49e6d7a9c8cbc2a2582d62159d514de2ba8037834e895625fa3a311073a90992cae
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Authentication With Registration Generator
2
+
3
+ A Rails Generator that adds registration pages to the Authentication Generator as well as some useful routes and helper methods.
4
+
5
+ * Runs the Authentication generator
6
+ * Adds a registration page which will create a new user with an email address and password.
7
+ * Adds a link to the registration page on the sign_in page
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
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
+ * Adds a `show_user_if_signed_in` method that displays a "signed in as username" message if the user is signed in
12
+
13
+ ## Installation
14
+
15
+ Install the gem and add to the application's Gemfile by executing:
16
+
17
+ $ bundle add registration_generator
18
+
19
+ If bundler is not being used to manage dependencies, install the gem by executing:
20
+
21
+ $ gem install registration_generator
22
+
23
+ ## Usage
24
+
25
+ ```bash
26
+ rails generate registration
27
+ ```
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/daz4126/registration_generator.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,12 @@
1
+ Description:
2
+ Creates registration pages for the authentication generator
3
+
4
+ Example:
5
+ bin/rails generate registration
6
+
7
+ This will create:
8
+ regisistration routes
9
+ new registration view
10
+ registrations controller
11
+ link_to_sign_in_or_out helper method
12
+ show_user_if_signed_in helper method
@@ -0,0 +1,59 @@
1
+ # lib/generators/registration/registration_generator.rb
2
+ require "rails/generators"
3
+
4
+ module AuthenticationWithRegistration
5
+ class AuthenticationWithRegistration < Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ def run_auth_generator
9
+ unless File.exist?(Rails.root.join("app/controllers/concerns/authentication.rb"))
10
+ invoke "rails:authentication"
11
+ end
12
+ end
13
+
14
+
15
+ def create_view
16
+ template "registration_form.html.erb", "app/views/registrations/new.html.erb"
17
+ end
18
+
19
+ def create_sign_in
20
+ template "sign_in_form.html.erb", "app/views/sessions/new.html.erb", force: true
21
+ end
22
+
23
+ def create_controller
24
+ template "registrations_controller.rb", "app/controllers/registrations_controller.rb"
25
+ end
26
+
27
+ def add_routes
28
+ route "resource :registration, only: [:new, :create]"
29
+ route "get \"sign_in\", to: \"sessions#new\", as: :sign_in"
30
+ route "delete \"sign_out\", to: \"sessions#destroy\", as: :sign_out"
31
+ end
32
+
33
+ def update_authentication_concern
34
+ inject_into_file "app/controllers/concerns/authentication.rb", before: "private\n" do
35
+ <<~RUBY
36
+
37
+ def link_to_sign_in_or_out
38
+ if authenticated?
39
+ button_to "Sign Out", sign_out_path, method: :delete
40
+ else
41
+ link_to "Sign In", sign_in_path
42
+ end
43
+ end
44
+
45
+ def show_user_if_signed_in
46
+ if authenticated?
47
+ "Signed in as \#{Current.user.email_address}"
48
+ end
49
+ end
50
+ RUBY
51
+ end
52
+
53
+ inject_into_file "app/controllers/concerns/authentication.rb", after: "helper_method :authenticated?\n" do
54
+ " helper_method :link_to_sign_in_or_out, :show_user_if_signed_in\n"
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,21 @@
1
+ <h1>Registration</h1>
2
+
3
+ <%%= form_with model: @user, url: registration_path do |f| %>
4
+ <%% if @user.errors.any? %>
5
+ <div>
6
+ <%%= @user.errors.full_messages.to_sentence %>
7
+ </div>
8
+ <%% end %>
9
+
10
+ <div>
11
+ <%%= f.label :email_address %>
12
+ <%%= f.email_field :email_address %>
13
+ </div>
14
+
15
+ <div>
16
+ <%%= f.label :password %>
17
+ <%%= f.password_field :password %>
18
+ </div>
19
+
20
+ <%%= f.submit "Register" %>
21
+ <%% end %>
@@ -0,0 +1,24 @@
1
+ class RegistrationsController < ApplicationController
2
+ allow_unauthenticated_access
3
+
4
+ def new
5
+ @user = User.new
6
+ end
7
+
8
+ def create
9
+ @user = User.new(user_params)
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
18
+
19
+ private
20
+
21
+ def user_params
22
+ params.require(:user).permit(:email_address, :password)
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
2
+ <%%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
3
+
4
+ <%%= form_with url: session_path do |form| %>
5
+ <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address] %><br>
6
+ <%%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72 %><br>
7
+ <%%= form.submit "Sign in" %>
8
+ <%% end %>
9
+ <p>
10
+ <%%= link_to "Forgot password?", new_password_path %> |
11
+ <%%= link_to "No Account? Register here", new_registration_path %>
12
+ </p>
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "registration_generator/version"
4
+
5
+ module AuthenticationWithRegistrationGenerator
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AuthenticationWithRegistrationGenerator
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: authentication_with_registration_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - DAZ
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-02-24 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '8.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '8.0'
26
+ description: This gem provides a Rails generator to create a registration form and
27
+ related files.
28
+ email:
29
+ - darren.jones@hey.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - lib/generators/authentication_with_registration/USAGE
36
+ - lib/generators/authentication_with_registration/authentication_with_registration_generator.rb
37
+ - lib/generators/authentication_with_registration/templates/registration_form.html.erb
38
+ - lib/generators/authentication_with_registration/templates/registrations_controller.rb
39
+ - lib/generators/authentication_with_registration/templates/sign_in_form.html.erb
40
+ - lib/generators/authentication_with_registration_generator.rb
41
+ - lib/generators/version.rb
42
+ homepage: https://github.com/your_username/registration_generator
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.6.3
61
+ specification_version: 4
62
+ summary: A Rails generator for user authenticatin with extra registration pages, routes
63
+ and helpers
64
+ test_files: []