Class: Frame::Generators::OmniauthGenerator

Inherits:
Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/frame/omniauth/omniauth_generator.rb

Instance Method Summary collapse

Methods inherited from Base

banner, source_root

Instance Method Details

#add_omniauth_secretObject



24
25
26
# File 'lib/generators/frame/omniauth/omniauth_generator.rb', line 24

def add_omniauth_secret
  template('config/initializers/omniauth.rb')
end

#add_routesObject



67
68
69
70
71
72
# File 'lib/generators/frame/omniauth/omniauth_generator.rb', line 67

def add_routes
  add_if_missing('config/routes.rb', "
  match '/auth/failure' => 'authentications#failure'
  match '/auth/:provider/callback' => 'authentications#create'
  ", :after => "get \"authentications/destroy\"\n")
end

#add_sign_in_to_deviseObject



93
94
95
96
97
# File 'lib/generators/frame/omniauth/omniauth_generator.rb', line 93

def 
  template('app/views/devise/sessions/new.html.erb')
  template('app/views/shared/_open_auth.html.erb')
  template('app/views/shared/_login_form.html.erb')
end

#add_username_to_userObject



74
75
76
# File 'lib/generators/frame/omniauth/omniauth_generator.rb', line 74

def add_username_to_user
  generate("migration AddUsernameToUser username:string")
end

#copy_imagesObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/generators/frame/omniauth/omniauth_generator.rb', line 82

def copy_images
  template('app/assets/images/facebook_32.png')
  template('app/assets/images/facebook_64.png')
  template('app/assets/images/github_32.png')
  template('app/assets/images/github_64.png')
  template('app/assets/images/google_32.png')
  template('app/assets/images/google_64.png')
  template('app/assets/images/twitter_32.png')
  template('app/assets/images/twitter_64.png')
end

#direct_devise_to_registrationsObject



28
29
30
# File 'lib/generators/frame/omniauth/omniauth_generator.rb', line 28

def direct_devise_to_registrations
  add_if_missing('config/routes.rb', ", :controllers => {:registrations => 'registrations'}", :after => "devise_for :users")
end

#g_authentication_controllerObject

Leave the routes?



49
50
51
52
53
54
55
56
57
58
# File 'lib/generators/frame/omniauth/omniauth_generator.rb', line 49

def g_authentication_controller
  generate('controller Authentications index create destroy')
  template('app/controllers/authentications_controller.rb')
  remove_file('app/views/authentications/index.html.erb')
  remove_file('app/views/authentications/create.html.erb')
  remove_file('app/views/authentications/destroy.html.erb')
  # Need this index?
  #template('app/views/authentications/index.html.erb')
  #remove_file('app/views/authentications')
end

#g_registration_controllerObject



60
61
62
63
64
65
# File 'lib/generators/frame/omniauth/omniauth_generator.rb', line 60

def g_registration_controller
  generate('controller Registrations edit new')
  template('app/views/registrations/edit.html.erb')
  template('app/views/registrations/new.html.erb')
  template('app/controllers/registrations_controller.rb')
end

#generate_authentication_modelObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/frame/omniauth/omniauth_generator.rb', line 32

def generate_authentication_model
  generate("model authentication user_id:integer provider:string uid:string")
  add_if_missing('app/models/authentication.rb', "
  belongs_to :user

  def provider_name
if provider == 'open_id'
  'OpenID'
elsif provider == 'google_oauth2'
  'Google'
else
  provider.titleize
end
  end\n", :after => "class Authentication < ActiveRecord::Base\n")
end

#install_omniauthObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/frame/omniauth/omniauth_generator.rb', line 11

def install_omniauth

  gem 'omniauth'
  gem 'omniauth-github'
  gem 'omniauth-facebook'
  gem 'omniauth-twitter'
  gem 'omniauth-google-oauth2'

  Bundler.with_clean_env do
    run "bundle"
  end
end

#update_dbObject



99
100
101
102
103
# File 'lib/generators/frame/omniauth/omniauth_generator.rb', line 99

def update_db
  #if yes?("Would you like to migrate the database?")
    rake("db:migrate")
  #end
end

#update_user_modelObject



78
79
80
# File 'lib/generators/frame/omniauth/omniauth_generator.rb', line 78

def update_user_model
  template('app/models/user.rb')
end