Class: StrongMindRailsIdentity::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- StrongMindRailsIdentity::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/strong_mind_rails_identity/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_devise_routes ⇒ Object
- #copy_auto_login ⇒ Object
- #copy_initializer ⇒ Object
- #copy_omniauth_callbacks_controller ⇒ Object
- #run_devise_user ⇒ Object
- #uid_migration ⇒ Object
Class Method Details
.next_migration_number(path) ⇒ Object
69 70 71 72 |
# File 'lib/generators/strong_mind_rails_identity/install_generator.rb', line 69 def self.next_migration_number(path) # Add 1 to make sure this happens after the devise migration (Time.now.utc.strftime("%Y%m%d%H%M%S").to_i + 1).to_s end |
Instance Method Details
#add_devise_routes ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/generators/strong_mind_rails_identity/install_generator.rb', line 47 def add_devise_routes devise_route = " devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' } devise_scope :user do post 'users/sign_out', to: 'devise/sessions#destroy' unauthenticated do root 'strong_mind_auto_login#index', as: :unauthenticated_root end authenticated do root 'strong_mind_auto_login#signed_in' end end ".dup route devise_route end |
#copy_auto_login ⇒ Object
18 19 20 21 22 |
# File 'lib/generators/strong_mind_rails_identity/install_generator.rb', line 18 def copy_auto_login copy_file "strong_mind_auto_login_controller.rb", "app/controllers/strong_mind_auto_login_controller.rb" copy_file "strong_mind_auto_login.html.erb", "app/views/strong_mind_auto_login/index.html.erb" copy_file "strong_mind_auto_login.signed_in.html.erb", "app/views/strong_mind_auto_login/signed_in.html.erb" end |
#copy_initializer ⇒ Object
10 11 12 |
# File 'lib/generators/strong_mind_rails_identity/install_generator.rb', line 10 def copy_initializer template "devise.rb", "config/initializers/devise.rb" end |
#copy_omniauth_callbacks_controller ⇒ Object
14 15 16 |
# File 'lib/generators/strong_mind_rails_identity/install_generator.rb', line 14 def copy_omniauth_callbacks_controller copy_file "omniauth_callbacks_controller.rb", "app/controllers/users/omniauth_callbacks_controller.rb" end |
#run_devise_user ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/strong_mind_rails_identity/install_generator.rb', line 24 def run_devise_user generate "active_record:devise User" inject_into_file "app/models/user.rb", after: ":recoverable, :rememberable, :validatable\n" do " devise :omniauthable, :omniauth_providers => %i[strongmind] def self.from_omniauth(auth) Rails.cache.write(auth.uid, auth) email = auth.extra.raw_info['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress'] user = User.where(uid: auth.uid).first if user.nil? user ||= User.create!(uid: auth.uid, email: email) end user end def auth Rails.cache.read(uid) end" end end |
#uid_migration ⇒ Object
65 66 67 |
# File 'lib/generators/strong_mind_rails_identity/install_generator.rb', line 65 def uid_migration migration_template "add_uid_to_user.rb", "db/migrate/add_uid_to_user.rb" end |