module HelperMethods def setup_authentication @model = ask("\n\n What would you like to call your user model? Default: User", :blue) @model = "user" if @model.blank? @model = @model.downcase.singularize @models = @model.pluralize log :bootup_log, "Installing Sorcery" generate "sorcery:install --model #{@model.classify}" log :bootup_log, "Copying models and migrations" case @db when 'mongoid' template "authentication/models/user_mongoid.rb.erb", "app/models/#{@model}.rb" inside Rails.root do run "rm db/migrate/*" end else template "authentication/models/user_others.rb.erb", "app/models/#{@model}.rb" rake("db:migrate") end log :bootup_log, "Copying controllers" template "authentication/controllers/users_controller.rb.erb", "app/controllers/#{@models}_controller.rb" template "authentication/controllers/user_sessions_controller.rb.erb", "app/controllers/#{@model}_sessions_controller.rb" copy_file "authentication/controllers/pages_controller.rb", "app/controllers/pages_controller.rb" copy_file "authentication/controllers/application_controller.rb", "app/controllers/application_controller.rb" log :bootup_log, "Copying views" directory "authentication/views", "app/views" unless @model.blank? inside Rails.root do run "mv app/views/user_sessions app/views/#{@model}_sessions" run "mv app/views/users app/views/#{@models}" end end log :bootup_log, "Copying initializers" template "authentication/sorcery.rb.erb", "config/initializers/sorcery.rb" log :bootup_log, "Copying initializers" template "authentication/routes.rb.erb", "config/routes.rb" inside Rails.root do run "git add ." run "git commit -am 'Authentication with sorcery.'" end say "\n\n An application with basic authentication has been created for you. Start thin server by typing 'rails s' in your command line. Point your browser to localhost:3000 to see the application.\n\n", :green end end