class BootswatchRails::Generators::SorceryGenerator
Public Instance Methods
add_controllers()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 67 def add_controllers template "users_controller.rb", "app/controllers/#{table_name}_controller.rb" end
add_gravatar()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 56 def add_gravatar return unless options.gravatar? template "gravatar_helper.rb", "app/helpers/gravatar_helper.rb" end
add_initializer()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 115 def add_initializer template "initializer.rb", "config/initializers/sorcery.rb" end
add_locales()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 119 def add_locales %w[en de].each do |locale| template "sorcery.#{locale}.yml", "config/locales/sorcery.#{locale}.yml" end end
add_mailer()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 61 def add_mailer return unless options.reset_password? template "user_mailer.rb", "app/mailers/#{mailer_name}.rb" template "reset_password_email.html.erb", "app/views/#{mailer_name}/reset_password_email.html.erb" end
add_migrations()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 43 def add_migrations migration_template "user_migration.rb", "db/migrate/create_#{table_name}.rb" end
add_models()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 47 def add_models template "user_model.rb", "app/models/#{name}.rb" end
add_routes()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 79 def add_routes lines = [ "resources :#{table_name} do", " collection do", " get 'log_in'", " post 'access'", " get 'log_out'" ] lines << [ " get 'password'", " post 'reset'" ] if options.reset_password? lines << [ " end" ] lines << [ " member do", " get 'change'", " patch 'refresh'", " put 'refresh'", " end" ] if options.reset_password? lines << [ " end" ] lines << [ " root '#{table_name}#log_in'" ] if options.root_route_login? lines << [ " get '/login' => '#{table_name}#log_in', as: :login, format: false", " get '/logout' => '#{table_name}#log_out', as: :logout, format: false", "" ] route lines.join("\n") end
add_uploader()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 51 def add_uploader return unless options.picture? template "picture_uploader.rb", "app/uploaders/picture_uploader.rb" end
add_views()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 71 def add_views views = %w[edit _form index log_in new show] views += %w[password change] if options.reset_password? views.each do |view| template "#{view}.html.erb", "app/views/#{table_name}/#{view}.html.erb" end end
update_application_controller()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 125 def update_application_controller file = "app/controllers/application_controller.rb" inject_into_class file, "ApplicationController", " before_action :require_login\n\n" inject_into_file file, "\n\n private", after: /protect_from_forgery.*$/ lines = [ "", " def not_authenticated", " redirect_to login_path, alert: t('sorcery.required')", " end", "", " def current_sysadm?", " logged_in? and current_#{name}.sysadm", " end", " helper_method :current_sysadm?", "" ] inject_into_file file, lines.join("\n"), before: /^end$/ end
Protected Instance Methods
added_fields()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 146 def added_fields list = options.add_attr || [] array = [] list.each do |entry| name, type, index = entry.split(':') type, index = ["string", type] if %w(index uniq).include? type array << [name, type || "string", index] end array end
controller_name()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 178 def controller_name "#{table_name}_controller" end
mailer_name()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 174 def mailer_name "#{name}_mailer" end
migration_name()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 170 def migration_name "create_#{table_name}" end
submodules()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 157 def submodules modules = [] modules << ":user_activation" if options.user_activation? modules << ":reset_password" if options.reset_password? modules << ":remember_me" if options.remember_me? modules << ":session_timeout" if options.session_timeout? modules << ":brute_force_protection" if options.brute_force_protection? modules << ":http_basic_auth" if options.http_basic_auth? modules << ":activity_logging" if options.activity_logging? modules << ":external" if options.external? modules.join(', ') end
whitelist()
click to toggle source
# File lib/generators/bootswatch_rails/sorcery/sorcery_generator.rb, line 182 def whitelist text = ":email, :name, :phone, :comment, :theme, " + ":active, :sysadm, :password, :password_confirmation" text += ", :language_id" if options.language? text += ", :picture, :picture_cache" if options.picture? added_fields.each do |field| text += ", :#{field[0]}" end text end