auto-facebook 0.1.rails4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in taiwan_city_dists_helper.gemspec
4
+ gemspec
5
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 xdite
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # AutoFacebook
2
+
3
+ Easy to mount omniauth-facebook to Rails
4
+
5
+ ## Installation
6
+
7
+ Add these lines to your application's Gemfile:
8
+
9
+ gem "omniauth"
10
+ gem "omniauth-facebook"
11
+ gem "auto-facebook"
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Install
18
+
19
+ 1. rails g auto_facebook:user
20
+ 2. rake db:migrate
21
+ 3. rails g auto_facebook:install
22
+ 4. touch tmp/restart.txt
23
+
24
+ ## Config
25
+
26
+ Edit `config/config.yml` # If you use [SettingsLogic](https://github.com/binarylogic/settingslogic)
27
+
28
+ add:
29
+
30
+ facebook_app_id: 'APP_ID'
31
+ facebook_secret: 'APP_SECRET'
32
+
33
+
34
+ ## Other
35
+
36
+ ``` rhtml
37
+
38
+ <%= link_to("Facebook Login", Setting.domain + user_omniauth_authorize_path(:facebook), :class => "btn btn-facebook") %>
39
+
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,36 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
3
+ def self.provides_callback_for(*providers)
4
+ providers.each do |provider|
5
+ class_eval %Q{
6
+ def #{provider}
7
+ if !current_user.blank?
8
+ current_user.bind_service(env["omniauth.auth"])#Add an auth to existing
9
+ redirect_to setting_path, :notice => "Bind #{provider} account successfully."
10
+ else
11
+ @user = User.find_or_create_for_#{provider}(env["omniauth.auth"])
12
+
13
+ if @user.persisted?
14
+ # flash[:notice] = "Signed in with #{provider.to_s.titleize} successfully."
15
+
16
+
17
+ sign_in_and_redirect @user, :event => :authentication, :notice => "Signed in successfully."
18
+ else
19
+ redirect_to new_user_registration_url
20
+ end
21
+ end
22
+ end
23
+ }
24
+ end
25
+ end
26
+
27
+ provides_callback_for :facebook
28
+
29
+ # This is solution for existing accout want bind Google login but current_user is always nil
30
+ # https://github.com/intridea/omniauth/issues/185
31
+ def handle_unverified_request
32
+ true
33
+ end
34
+
35
+
36
+ end
@@ -0,0 +1,49 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class User
3
+ module OmniauthCallbacks
4
+
5
+ ["facebook"].each do |provider|
6
+ define_method "find_or_create_for_#{provider}" do |response|
7
+ uid = response["uid"]
8
+ data = response["info"]
9
+
10
+ credentials= response['credentials']
11
+
12
+ if user = User.where( :fb_id => uid).first
13
+ return user
14
+ elsif user = User.find_by_email(data["email"])
15
+ user.update_attribute(:fb_id ,uid )
16
+ return user
17
+ else
18
+ user = User.new_from_provider_data(provider,uid,data, credentials)
19
+ if user.save(:validate => false)
20
+ user.fb_id = uid
21
+ user.save
22
+ return user
23
+ else
24
+ Rails.logger.warn("User.create_from_hash 失败,#{user.errors.inspect}")
25
+ return nil
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+
32
+
33
+ def new_from_provider_data(provider, uid, data,credentials)
34
+ user = User.new
35
+ user.email = data["email"]
36
+ user.token = credentials['token']
37
+ user.name = data["nickname"] ? data ["nickname"] : data["name"]
38
+
39
+ user.name.gsub!(/[^\w]/, "_")
40
+ if User.where(:name => user.name).count > 0 || user.name.blank?
41
+ user.name = "u#{Time.now.to_i}"
42
+ end
43
+
44
+ user.password = Devise.friendly_token[0,20]
45
+
46
+ return user
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'auto/facebook/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "auto-facebook"
8
+ gem.version = AutoFacebook::VERSION
9
+ gem.authors = ["xdite"]
10
+ gem.email = ["xdite@rocodev.com"]
11
+ gem.description = %q{Auto Mount Facebook Login}
12
+ gem.summary = %q{Auto Mount Facebook Login}
13
+ gem.homepage = "http://github.com/xdite/auto-facebook"
14
+
15
+ gem.add_dependency 'omniauth'
16
+ gem.add_dependency 'omniauth-facebook'
17
+ gem.add_dependency 'rails', '4.0.0.rc1'
18
+ gem.files = `git ls-files`.split($/)
19
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.require_paths = ["lib"]
22
+ end
@@ -0,0 +1 @@
1
+ require "auto/facebook/engine"
@@ -0,0 +1,7 @@
1
+ module AutoFacebook
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ # TODO
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ module AutoFacebook
2
+
3
+ VERSION = "0.1.rails4"
4
+ end
@@ -0,0 +1,28 @@
1
+ module AutoFacebook
2
+
3
+ module Generators
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+
6
+ self.source_paths << File.join(File.dirname(__FILE__), 'templates')
7
+
8
+ def inject_to_user_model
9
+ inject_into_file 'app/models/user.rb', "\n extend OmniauthCallbacks\n\n ", :before => /devise :/
10
+ inject_into_file 'app/models/user.rb', ", :omniauthable", :after => /:validatable/
11
+ end
12
+
13
+ def inject_to_routing
14
+ gsub_file 'config/routes.rb', /devise_for :users/, 'devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }'
15
+ end
16
+
17
+ def inject_to_devise_setting
18
+ inject_into_file 'config/initializers/devise.rb', "\n config.omniauth :facebook, Setting.facebook_app_id, Setting.facebook_secret, :scope => 'email'\n", :after => /# ==> OmniAuth/
19
+ end
20
+
21
+ def copy_initializer_of_omniauth
22
+ template 'omniauth.rb', 'config/initializers/omniauth.rb'
23
+ end
24
+
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,2 @@
1
+ # -*- encoding : utf-8 -*-
2
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
@@ -0,0 +1,7 @@
1
+ class AddFbIdToUser < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :fb_id, :string, :limit => 20
4
+ add_column :users, :token, :string
5
+ add_column :users, :name, :string
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ require 'rails/generators/active_record'
4
+
5
+ module AutoFacebook
6
+
7
+ module Generators
8
+ class UserGenerator < ::Rails::Generators::Base
9
+ include ::Rails::Generators::Migration
10
+
11
+ self.source_paths << File.join(File.dirname(__FILE__), 'templates')
12
+
13
+ def create_migration_file
14
+ migration_template "migration.rb", "db/migrate/add_fb_id_to_user.rb"
15
+ end
16
+
17
+ def self.next_migration_number(path)
18
+ @migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i.to_s
19
+ end
20
+
21
+ def self.next_migration_number(dirname)
22
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
23
+ end
24
+ end
25
+ end
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auto-facebook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.rails4
5
+ prerelease: 4
6
+ platform: ruby
7
+ authors:
8
+ - xdite
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: omniauth-facebook
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 4.0.0.rc1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 4.0.0.rc1
62
+ description: Auto Mount Facebook Login
63
+ email:
64
+ - xdite@rocodev.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - app/controllers/users/omniauth_callbacks_controller.rb
75
+ - app/models/user/omniauth_callbacks.rb
76
+ - auto-facebook.gemspec
77
+ - lib/auto-facebook.rb
78
+ - lib/auto/facebook/engine.rb
79
+ - lib/auto/facebook/version.rb
80
+ - lib/generators/auto_facebook/install/install_generator.rb
81
+ - lib/generators/auto_facebook/install/templates/omniauth.rb
82
+ - lib/generators/auto_facebook/user/templates/migration.rb
83
+ - lib/generators/auto_facebook/user/user_generator.rb
84
+ homepage: http://github.com/xdite/auto-facebook
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: 4063996162541562257
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>'
103
+ - !ruby/object:Gem::Version
104
+ version: 1.3.1
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.25
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Auto Mount Facebook Login
111
+ test_files: []