authentication_with_registration_generator 0.1.0 → 0.2.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c59c452f38de77479a1aa84069795c21d54bab18dd4926074f9b09c601eeb44d
|
4
|
+
data.tar.gz: 44ec7524e8fe23f274e4b25747e802ac73df0171a10ac541e73417dca0a0b2ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bf07f1603f84c47bf10c8fe33fb3ecf3c7362ecc8a7023372ed0f5e5a3875e0fd6f6db17c7c9a488c86068067b1dffe8f73d83a1050424d88fb32dbfe8b4179
|
7
|
+
data.tar.gz: 26f4c341ed7a476c9250dff0375bbdbebda1c6fe33db33975dc443e8f023977c33169bdd971249f9e55c3c055fa209a518bc2d19b1e5207b78bebbc4e7b880d2
|
data/lib/generators/authentication_with_registration/authentication_with_registration_generator.rb
CHANGED
@@ -16,10 +16,6 @@ module AuthenticationWithRegistration
|
|
16
16
|
template "registration_form.html.erb", "app/views/registrations/new.html.erb"
|
17
17
|
end
|
18
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
19
|
def create_controller
|
24
20
|
template "registrations_controller.rb", "app/controllers/registrations_controller.rb"
|
25
21
|
end
|
@@ -29,6 +25,22 @@ module AuthenticationWithRegistration
|
|
29
25
|
route "get \"sign_in\", to: \"sessions#new\", as: :sign_in"
|
30
26
|
route "delete \"sign_out\", to: \"sessions#destroy\", as: :sign_out"
|
31
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
|
32
44
|
|
33
45
|
def update_authentication_concern
|
34
46
|
inject_into_file "app/controllers/concerns/authentication.rb", before: "private\n" do
|
@@ -36,22 +48,30 @@ module AuthenticationWithRegistration
|
|
36
48
|
|
37
49
|
def link_to_sign_in_or_out
|
38
50
|
if authenticated?
|
39
|
-
|
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
|
40
59
|
else
|
41
|
-
|
60
|
+
"<a href=\"#{sign_in_path}\">Sign In</a>".html_safe
|
42
61
|
end
|
43
|
-
end
|
62
|
+
end
|
44
63
|
|
45
64
|
def show_user_if_signed_in
|
46
65
|
if authenticated?
|
47
66
|
"Signed in as \#{Current.user.email_address}"
|
48
67
|
end
|
49
68
|
end
|
69
|
+
|
50
70
|
RUBY
|
51
71
|
end
|
52
72
|
|
53
|
-
inject_into_file "app/controllers/concerns/authentication.rb", after: "
|
54
|
-
"
|
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"
|
55
75
|
end
|
56
76
|
end
|
57
77
|
|
data/lib/generators/version.rb
CHANGED