Module: Boring::Oauth::BaseGenerator
- Included in:
- Facebook::InstallGenerator, Github::InstallGenerator, Google::InstallGenerator, Twitter::InstallGenerator
- Defined in:
- lib/generators/boring/oauth/base_generator.rb
Instance Method Summary collapse
- #add_omniauth_callback_controller ⇒ Object
- #add_omniauth_callback_routes ⇒ Object
- #add_provider_and_uuid_user_details ⇒ Object
- #configure_and_add_devise_setting_in_user_model ⇒ Object
- #configure_devise_omniauth ⇒ Object
- #show_readme ⇒ Object
Instance Method Details
#add_omniauth_callback_controller ⇒ Object
34 35 36 37 |
# File 'lib/generators/boring/oauth/base_generator.rb', line 34 def add_omniauth_callback_controller say "Copying omniauth_callbacks_controller.rb", :green template("omniauth_callbacks_controller.rb", "app/controllers/users/omniauth_callbacks_controller.rb") end |
#add_omniauth_callback_routes ⇒ Object
29 30 31 32 |
# File 'lib/generators/boring/oauth/base_generator.rb', line 29 def add_omniauth_callback_routes devise_route = '# devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }'.dup route devise_route end |
#add_provider_and_uuid_user_details ⇒ Object
8 9 10 11 12 13 |
# File 'lib/generators/boring/oauth/base_generator.rb', line 8 def add_provider_and_uuid_user_details say "Adding migration to add provider and uuid columns to users", :green Bundler.with_unbundled_env do run "DISABLE_SPRING=1 bundle exec rails generate migration AddOmniauthToUsers provider:string uid:string" end end |
#configure_and_add_devise_setting_in_user_model ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/generators/boring/oauth/base_generator.rb', line 39 def configure_and_add_devise_setting_in_user_model say "Configuring #{@oauth_name.to_s} omniauth for user model", :green insert_into_file "app/models/user.rb", <<~RUBY, after: /class User < ApplicationRecord/ \n\tdevise :omniauthable, omniauth_providers: %i[#{@oauth_name}] \tdef self.from_omniauth(auth) \twhere(provider: auth.provider, uid: auth.uid).first_or_create do |user| \tuser.email = auth.info.email \tuser.password = Devise.friendly_token[0, 20] \t# user.name = auth.info.name # assuming the user model has a name \t# user.image = auth.info.image # assuming the user model has an image \t# If you are using confirmable and the provider(s) you use validate emails, \t# uncomment the line below to skip the confirmation emails. \t# user.skip_confirmation! \tend \tend RUBY end |
#configure_devise_omniauth ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/generators/boring/oauth/base_generator.rb', line 15 def configure_devise_omniauth say "Adding omniauth devise configuration", :green if File.exist?("config/initializers/devise.rb") insert_into_file "config/initializers/devise.rb", <<~RUBY, after: /Devise.setup do \|config\|/ \n \tconfig.omniauth :#{@oauth_name}, "APP_ID", "APP_SECRET" RUBY else raise MissingDeviseConfigurationError, <<~ERROR Looks like the devise installation is incomplete. Could not find devise.rb in config/initializers. ERROR end end |
#show_readme ⇒ Object
58 59 60 |
# File 'lib/generators/boring/oauth/base_generator.rb', line 58 def show_readme readme "README" end |