teleporter 0.0.28 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acc900e3fc54f6a50f8a5d9a32a979e50ac240d3
4
- data.tar.gz: a20efecce01f81f89257afffbefb5ecb28587cfc
3
+ metadata.gz: e1fcd6f7ab7df7f2f94ebfdc286c6060c62520c6
4
+ data.tar.gz: bb6095a014ef12413520b8a143d43a27981b5060
5
5
  SHA512:
6
- metadata.gz: 8d02bbb3bc290ecca3f93d736307a260d1fc6c78774edde61375e8655ea01e1e6e49072a3445b66796e4a0e01228d99c23f5c8baf4ac759e3f1635504281859d
7
- data.tar.gz: e768668ab8392db4665ec2821fd99529ce2d5308dc91ba7417f7e8e9a54518ebc94b14d5d0bcce1ed2f9f8844b082b79b00d84e1c241807064cc569e5fee1679
6
+ metadata.gz: 97ff0e92f080ef902144eb9c84e1a12010c10553ac9a415338dcb3b99290899fc4e4460b843754fceeb225e7d07d4b7a5fe20712086ff7ad5a119582ae5b757c
7
+ data.tar.gz: 72021a06b331b2d0492ea6a1d690a4d2babd8148a6621450f7555c1acbf8c7c99388085241aabd2a660db64e277f4ca6d9194a7cbc8946f1c315254eedcc95eb
data/README.md CHANGED
@@ -10,6 +10,7 @@ $ rails g initial:start
10
10
  $ rails g initial:capistrano
11
11
  $ rails g initial:bootstrap
12
12
  $ rails g initial:devise
13
+ $ rails g initial:devise_oauth
13
14
 
14
15
  $ rails g admin:start
15
16
  ```
@@ -41,6 +41,9 @@ module Initial
41
41
 
42
42
  model = ask "Type MODEL to bootstrap devise:"
43
43
  generate "devise #{model}"
44
+
45
+ with_oauth = ask 'Add oauth? (y/n)'
46
+ generate 'devise_oauth' if with_oauth =~ /y/
44
47
  end
45
48
  end
46
49
  end
@@ -0,0 +1,102 @@
1
+ module Initial
2
+ class DeviseOauthGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("../templates", __FILE__)
4
+
5
+ def add
6
+ gem 'omniauth-facebook'
7
+ gem 'omniauth-vkontakte'
8
+ gem 'omniauth-odnoklassniki'
9
+
10
+ copy_file 'devise_oauth/devise_oauth.rb',
11
+ 'config/initializers/devise_oauth.rb'
12
+
13
+ insert_into_file 'config/secrets.yml', after: "development:\n" do
14
+ %q{
15
+ fb_app: '267206890544721'
16
+ fb_key: '40aba0555fb761272b07711e30ebe371'
17
+ vk_app: '4470254'
18
+ vk_key: 'J7ANCTdIWb8SAKzA4eUk'
19
+ ok_app: '1096984323'
20
+ ok_key: '792DB3D2757C2A786C2AD5EA'
21
+ ok_pkey: 'CBADHHFCABABABABA'
22
+ }
23
+ end
24
+
25
+ insert_into_file 'config/secrets.yml', after: "production:\n" do
26
+ %q{
27
+ fb_app: <%= ENV["FB_APP"] %>
28
+ fb_key: <%= ENV["FB_KEY"] %>
29
+ vk_app: <%= ENV["VK_APP"] %>
30
+ vk_key: <%= ENV["VK_KEY"] %>
31
+ ok_app: <%= ENV["OK_APP"] %>
32
+ ok_key: <%= ENV["OK_KEY"] %>
33
+ ok_pkey: <%= ENV["OK_PKEY"] %>
34
+ }
35
+ end
36
+
37
+ generate 'migration', 'AddColumnsToUsers provider uid auth_info:text'
38
+ rake 'db:migrate'
39
+ insert_into_file 'app/models/user.rb', before: "end\n" do
40
+ %q{
41
+ serialize :auth_info, JSON
42
+
43
+ devise :omniauthable, omniauth_providers: [:facebook, :vkontakte, :odnoklassniki]
44
+
45
+ def self.from_omniauth(auth_hash)
46
+ auth = auth_hash['auth_hash'].with_indifferent_access
47
+ find_or_create_by(provider: auth[:provider], uid: auth[:uid]) do |user|
48
+ user.email = auth[:info][:email] || "#{auth[:uid]}@example.com"
49
+ user.password = Devise.friendly_token[0,20]
50
+ user.info = auth.try(:to_json)
51
+ end
52
+ end
53
+
54
+ }
55
+ end
56
+
57
+ append_to_file 'app/views/welcome/index.haml' do
58
+ %q{
59
+ %ul.nav
60
+ - if user_signed_in?
61
+ %li= link_to "#{current_user.email} (#{current_user.provider})", '#'
62
+ %li= link_to "Sign out", destroy_user_session_path, :method => :delete
63
+ - else
64
+ %li= link_to "Sign in with Facebook", user_omniauth_authorize_path(:facebook)
65
+ %li= link_to "Sign in with Vkontakte", user_omniauth_authorize_path(:vkontakte)
66
+ %li= link_to "Sign in with Odnoklassniki", user_omniauth_authorize_path(:odnoklassniki)
67
+ }
68
+ end
69
+
70
+ copy_file 'devise_oauth/omniauth_callbacks_controller.rb',
71
+ 'app/controllers/users/omniauth_callbacks_controller.rb'
72
+
73
+
74
+ oauth_without_other_auths = ask 'Use oauth without other authentications? (y/n)'
75
+ content = if oauth_without_other_auths
76
+ %q{
77
+ devise_for :users, controllers: {
78
+ omniauth_callbacks: "users/omniauth_callbacks"
79
+ }
80
+ devise_scope :user do
81
+ get 'sign_in', to: 'devise/sessions#new'#, as: :new_user_session
82
+ get 'sign_out', to: 'devise/sessions#destroy'#, as: :destroy_user_session
83
+ end
84
+ }
85
+ else
86
+ %q{
87
+ devise_scope :user do
88
+ get 'sign_out', to: 'devise/sessions#destroy'#, as: :destroy_user_session
89
+ end
90
+ devise_for :users, controllers: {
91
+ omniauth_callbacks: "users/omniauth_callbacks"
92
+ }
93
+
94
+ }
95
+ end
96
+
97
+ comment_lines 'config/routes.rb', /devise_for/
98
+
99
+ route content
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,6 @@
1
+ Devise.setup do |config|
2
+ secrets = Rails.application.secrets
3
+ config.omniauth :facebook, secrets.fb_app, secrets.fb_key
4
+ config.omniauth :vkontakte, secrets.vk_app, secrets.vk_key
5
+ config.omniauth :odnoklassniki, secrets.ok_app, secrets.ok_key, public_key: secrets.ok_pkey
6
+ end
@@ -0,0 +1,28 @@
1
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
2
+ before_action :enter_with_oauth
3
+
4
+ def vkontakte
5
+ end
6
+
7
+ def facebook
8
+ end
9
+
10
+ def odnoklassniki
11
+ end
12
+
13
+ def enter_with_oauth
14
+ @user= User.from_omniauth(oauth_params)
15
+ if @user.persisted?
16
+ sign_in_and_redirect @user, event: :authentication
17
+ set_flash_message(:notice, :success, kind: action_name) if is_navigational_format?
18
+ else
19
+ session["devise.oauth_data"] = request.env["omniauth.auth"]
20
+ redirect_to new_user_registration_url
21
+ end
22
+ end
23
+
24
+ private
25
+ def oauth_params
26
+ ActionController::Parameters.new(auth_hash: request.env["omniauth.auth"]).permit!
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Teleporter
2
- VERSION = "0.0.28"
2
+ VERSION = "0.0.29"
3
3
  end
data/lib/teleporter.rb CHANGED
@@ -10,6 +10,7 @@ require "generators/initial/welcome"
10
10
  require "generators/initial/capistrano"
11
11
  require "generators/initial/bootstrap"
12
12
  require "generators/initial/devise"
13
+ require "generators/initial/devise_oauth"
13
14
  require "generators/initial/gitignore"
14
15
  require "generators/initial/database"
15
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teleporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ponomarev Nikolay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-16 00:00:00.000000000 Z
11
+ date: 2014-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,6 +70,7 @@ files:
70
70
  - lib/generators/initial/capistrano.rb
71
71
  - lib/generators/initial/database.rb
72
72
  - lib/generators/initial/devise.rb
73
+ - lib/generators/initial/devise_oauth.rb
73
74
  - lib/generators/initial/gemfile.rb
74
75
  - lib/generators/initial/gitignore.rb
75
76
  - lib/generators/initial/rspec.rb
@@ -97,6 +98,8 @@ files:
97
98
  - lib/generators/initial/templates/capistrano/tasks/setup_config.rake
98
99
  - lib/generators/initial/templates/database/database.yml
99
100
  - lib/generators/initial/templates/devise/devise.ru.yml
101
+ - lib/generators/initial/templates/devise_oauth/devise_oauth.rb
102
+ - lib/generators/initial/templates/devise_oauth/omniauth_callbacks_controller.rb
100
103
  - lib/generators/initial/templates/gitignore/gitignore
101
104
  - lib/generators/initial/templates/rspec/configs/capybara.rb
102
105
  - lib/generators/initial/templates/rspec/configs/database_cleaner.rb