Class: Trestle::Auth::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/trestle/auth/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#check_trestle_installedObject



9
10
11
12
13
# File 'lib/generators/trestle/auth/install/install_generator.rb', line 9

def check_trestle_installed
  unless ::File.exist?("config/initializers/trestle.rb")
    raise Thor::Error, "The file config/initializers/trestle.rb does not appear to exist. Please run `trestle:install` first."
  end
end

#generate_adminObject



135
136
137
# File 'lib/generators/trestle/auth/install/install_generator.rb', line 135

def generate_admin
  generate "trestle:auth:admin", model
end

#generate_modelObject



131
132
133
# File 'lib/generators/trestle/auth/install/install_generator.rb', line 131

def generate_model
  generate "trestle:auth:model", model
end

#insert_configurationObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/generators/trestle/auth/install/install_generator.rb', line 15

def insert_configuration
  inject_into_file "config/initializers/trestle.rb", before: /^end/ do
    <<-RUBY.strip_heredoc.indent(2)

      # == Authentication Options
      #
      # Specify the user class to be used by trestle-auth.
      #
      config.auth.user_class = -> { #{model} }

      # Specify the scope for valid admin users.
      # Defaults to config.auth.user_class (unscoped).
      #
      # config.auth.user_scope = -> { User.where(admin: true) }

      # Specify the Trestle admin for managing administrator users.
      #
      config.auth.user_admin = -> { :"auth/#{model.underscore.pluralize}" }

      # Specify the parameter (along with a password) to be used to
      # authenticate an administrator. Defaults to :email.
      #
      # config.auth.authenticate_with = :login

      # Customize the method for authenticating a user given login parameters.
      # The block should return an instance of the auth user class, or nil.
      #
      # config.auth.authenticate = ->(params) {
      #   User.authenticate(params[:login], params[:password])
      # }

      # Customize the method for finding a user given an ID from the session.
      # The block should return an instance of the auth user class, or nil.
      #
      # config.auth.find_user = ->(id) {
      #   User.find_by(id: id)
      # }

      # Customize the rendering of user avatars. Can be disabled by setting to false.
      # Defaults to the Gravatar based on the user's email address.
      #
      # config.auth.avatar = ->(user) {
      #   avatar(fallback: user.initials) do
      #     image_tag(user.avatar_url, alt: user.name) if user.avatar_url?
      #   end
      # }

      # Customize the rendering of the current user's name in the main header.
      # Defaults to the user's #first_name and #last_name (last name in bold),
      # with a fallback to `display(user)` if those methods aren't defined.
      #
      # config.auth.format_user_name = ->(user) {
      #   content_tag(:strong, user.full_name)
      # }

      # Customize the method for determining the user's locale.
      # Defaults to user.locale (if the method is defined).
      #
      # config.auth.locale = ->(user) {
      #   user.locale if user.respond_to?(:locale)
      # }

      # Customize the method for determining the user's time zone.
      # Defaults to user.time_zone (if the method is defined).
      #
      # config.auth.time_zone = ->(user) {
      #   user.time_zone if user.respond_to?(:time_zone)
      # }

      # Specify the redirect location after a successful login.
      # Defaults to the main Trestle admin path.
      #
      # config.auth.redirect_on_login = -> {
      #   if admin = Trestle.lookup(Trestle.config.auth.user_admin)
      #     admin.instance_path(current_user)
      #   else
      #     Trestle.config.path
      #   end
      # }

      # Specify the redirect location after logging out.
      # Defaults to the trestle-auth new login path.
      #
      # config.auth.redirect_on_logout = -> { "/" }

      # Enable or disable remember me functionality. Defaults to true.
      #
      # config.auth.remember.enabled = false

      # Specify remember me expiration time. Defaults to 2 weeks.
      #
      # config.auth.remember.for = 30.days

      # Customize the method for authenticating a user given a remember token.
      #
      # config.auth.remember.authenticate = ->(token) {
      #   User.authenticate_with_remember_token(token)
      # }

      # Customize the method for remembering a user.
      #
      # config.auth.remember.remember_me, ->(user) { user.remember_me! }

      # Customize the method for forgetting a user.
      #
      # config.auth.remember.forget_me, ->(user) { user.forget_me! }

      # Customize the method for generating the remember cookie.
      #
      # config.auth.remember.cookie, ->(user) {
      #   { value: user.remember_token, expires: user.remember_token_expires_at }
      # }
    RUBY
  end
end