Skip to content

Commit 64bbbc2

Browse files
committed
add sudo_rails:config generator to create an initializer
1 parent deb1840 commit 64bbbc2

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ SudoRails.setup do |config|
7373
end
7474
```
7575

76+
Use the provided `sudo_rails:config` generator to create a default config file under your *initializers* folder.
77+
7678
### Sudo sessions
7779

7880
Using the `sudo_session_duration` option you are able to configure the `sudo` session duration (30 minutes by default).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class SudoRails::ConfigGenerator < Rails::Generators::Base
2+
def create_config_file
3+
create_file "config/initializers/sudo_rails.rb", <<~RUBY
4+
SudoRails.setup do |config|
5+
### On/off engine
6+
# config.enabled = true
7+
8+
### Sudo mode sessions duration, default is 30 minutes
9+
# config.sudo_session_duration = 10.minutes
10+
11+
### Confirmation page styling
12+
# config.custom_logo = '/images/logo_medium.png'
13+
# config.primary_color = '#1a7191'
14+
# config.background_color = '#1a1a1a'
15+
# config.layout = 'admin'
16+
17+
### Confirmation strategy implementation
18+
# config.confirm_strategy = -> (context, password) {
19+
# user = context.current_user
20+
# user.valid_password?(password)
21+
# }
22+
23+
### Reset password link
24+
# config.reset_pass_link = '/users/password/new'
25+
end
26+
RUBY
27+
end
28+
end
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class SudoRails::ViewGenerator < Rails::Generators::Base
22
source_root File.expand_path("../../../app/views/sudo_rails/", __dir__)
33

4-
def copy_initializer_file
4+
def copy_view_file
55
copy_file "confirm_form.html.erb", "app/views/sudo_rails/confirm_form.html.erb"
66
end
7-
end
7+
end

0 commit comments

Comments
 (0)