Skip to content

Commit a02eafd

Browse files
committed
update config generator
1 parent 74440a9 commit a02eafd

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

README.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,15 @@ SudoRails.setup do |config|
7171
# Reset password link
7272
config.reset_pass_link = '/users/password/new'
7373

74-
# Callbacks to subscribe to different events
74+
# Subscribe to different events
7575
config.callbacks = {
76-
new_sudo_session: -> (context) {
77-
user = context.current_user
78-
Rails.logger.warn("[SUDO_RAILS] new sudo session created: #{user.email}")
79-
},
8076
invalid_sudo_session: -> (context) {
8177
user = context.current_user
8278
AuthService.send_code(user)
8379
},
8480
invalid_verification: -> (context) {
8581
user = context.current_user
86-
Rails.logger.warn("[SUDO_RAILS] invalid password: #{user.email}")
82+
Rails.logger.warn("[SUDO_RAILS] invalid password for #{user.email}")
8783
}
8884
end
8985
```
@@ -138,7 +134,9 @@ config.confirm_strategy = -> (context, password) {
138134

139135
### Callbacks
140136

141-
You can subscribe to different events via the `callbacks` option. Each callback must be a `lambda`, which will receive 1 argument: the controller instance (`context`). You can subscribe to the following events:
137+
You can subscribe to different lifecycle events via the `callbacks` option. Each callback must be a `lambda`, which will receive 1 argument, the controller instance (`context`).
138+
139+
You can subscribe to the following events:
142140

143141
- `:invalid_sudo_session`: fired when the confirmation page is rendered, because there is no valid sudo session. Be careful! If the page is re-submitted or the password is invalid, the confirmation page will be rendered again and this event will be fired again too.
144142
- `:new_sudo_session`: fired when a new sudo session is started.

lib/generators/sudo_rails/config_generator.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ def create_config_file
2323
### Reset password link
2424
# config.reset_pass_link = '/users/password/new'
2525
26-
### TODO: add callback
26+
### Subscribe to different events
27+
# config.callbacks = {
28+
# new_sudo_session: -> (context) { Rails.logger.warn("new sudo session created") },
29+
# invalid_sudo_session: -> (context) { Rails.logger.warn("invalid sudo session") },
30+
# invalid_verification: -> (context) { Rails.logger.warn("invalid password in sudo session") }
31+
# }
32+
end
2733
RUBY
2834
end
2935
end

0 commit comments

Comments
 (0)