authentication_with_registration_generator 0.1.0 → 0.3.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/lib/generators/authentication/authentication.rb +79 -0
- data/lib/generators/authentication_with_registration_generator.rb +1 -1
- data/lib/generators/version.rb +2 -2
- metadata +6 -6
- data/lib/generators/authentication_with_registration/authentication_with_registration_generator.rb +0 -59
- /data/lib/generators/{authentication_with_registration → authentication}/USAGE +0 -0
- /data/lib/generators/{authentication_with_registration → authentication}/templates/registration_form.html.erb +0 -0
- /data/lib/generators/{authentication_with_registration → authentication}/templates/registrations_controller.rb +0 -0
- /data/lib/generators/{authentication_with_registration → authentication}/templates/sign_in_form.html.erb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65882eaf7831babf0a4db3d53875aa731ae768d0e4272e8b494876df94c539f2
|
4
|
+
data.tar.gz: 8860951102bdf138dadadf76fc952dec8dc1a550ca15781f4890b27a9e205f74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ced190d7da5c1e7bd07a173774174e8ead4012ed8cc66f00790687e5baab0182a653b199b2ad3c89c2722349288e9789a1d4a766b75097b2a9e96d2f6790c8d6
|
7
|
+
data.tar.gz: 607b2b8516eec0a6d4eac02b03f8b0a8cb58f16691b5aaf3d81a25548ea78fea87c29337f3301194d4e67e0bf0adf5614a9a97f9d2666eb81f5bacb4c856450a
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# lib/generators/registration/registration_generator.rb
|
2
|
+
require "rails/generators"
|
3
|
+
|
4
|
+
module Authentication
|
5
|
+
class Authentication < 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_controller
|
20
|
+
template "registrations_controller.rb", "app/controllers/registrations_controller.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_routes
|
24
|
+
route "resource :registration, only: [:new, :create]"
|
25
|
+
route "get \"sign_in\", to: \"sessions#new\", as: :sign_in"
|
26
|
+
route "delete \"sign_out\", to: \"sessions#destroy\", as: :sign_out"
|
27
|
+
end
|
28
|
+
|
29
|
+
def modify_session_view
|
30
|
+
# Path to the generated sessions/new.html.erb
|
31
|
+
session_view_path = "app/views/sessions/new.html.erb"
|
32
|
+
|
33
|
+
# Check if the file exists before modifying it
|
34
|
+
if File.exists?(session_view_path)
|
35
|
+
# Replace the "Forgot password?" link with the new links
|
36
|
+
gsub_file session_view_path, /<br>\s*<%= link_to "Forgot password\?", new_password_path %>/ do |match|
|
37
|
+
"<p>\n <%= link_to 'Forgot password?', new_password_path %> | \n <%= link_to 'No Account? Register here', new_registration_path %>\n</p>"
|
38
|
+
end
|
39
|
+
else
|
40
|
+
# If the file doesn't exist, handle it accordingly (e.g., raise an error or create the file)
|
41
|
+
raise "Session view file not found"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def update_authentication_concern
|
46
|
+
inject_into_file "app/controllers/concerns/authentication.rb", before: "private\n" do
|
47
|
+
<<~RUBY
|
48
|
+
|
49
|
+
def link_to_sign_in_or_out
|
50
|
+
if authenticated?
|
51
|
+
authenticity_token = form_authenticity_token
|
52
|
+
action_url = sign_out_path
|
53
|
+
# Return the form as a string
|
54
|
+
"<form class=\"button_to\" action=\"#{action_url}\" accept-charset=\"UTF-8\" method=\"post\">
|
55
|
+
<input type=\"hidden\" name=\"_method\" value=\"delete\" autocomplete=\"off\" />
|
56
|
+
<button type=\"submit\">Sign Out</button>
|
57
|
+
<input type=\"hidden\" name=\"authenticity_token\" value=\"#{authenticity_token}\" autocomplete=\"off\" />
|
58
|
+
</form>".html_safe
|
59
|
+
else
|
60
|
+
"<a href=\"#{sign_in_path}\">Sign In</a>".html_safe
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def show_user_if_signed_in
|
65
|
+
if authenticated?
|
66
|
+
"Signed in as \#{Current.user.email_address}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
RUBY
|
71
|
+
end
|
72
|
+
|
73
|
+
inject_into_file "app/controllers/concerns/authentication.rb", after: ":authenticated?" do
|
74
|
+
", helper_method :link_to_sign_in_or_out, :show_user_if_signed_in"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
data/lib/generators/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authentication_with_registration_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DAZ
|
@@ -32,11 +32,11 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- README.md
|
35
|
-
- lib/generators/
|
36
|
-
- lib/generators/
|
37
|
-
- lib/generators/
|
38
|
-
- lib/generators/
|
39
|
-
- lib/generators/
|
35
|
+
- lib/generators/authentication/USAGE
|
36
|
+
- lib/generators/authentication/authentication.rb
|
37
|
+
- lib/generators/authentication/templates/registration_form.html.erb
|
38
|
+
- lib/generators/authentication/templates/registrations_controller.rb
|
39
|
+
- lib/generators/authentication/templates/sign_in_form.html.erb
|
40
40
|
- lib/generators/authentication_with_registration_generator.rb
|
41
41
|
- lib/generators/version.rb
|
42
42
|
homepage: https://github.com/your_username/registration_generator
|
data/lib/generators/authentication_with_registration/authentication_with_registration_generator.rb
DELETED
@@ -1,59 +0,0 @@
|
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|