mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-10 07:18:14 -05:00
More and more tests to DeviseOauth.
This commit is contained in:
@@ -1 +1,5 @@
|
||||
Home!
|
||||
|
||||
<%- User.oauth_providers.each do |provider| %>
|
||||
<%= link_to "Sign in with #{provider.to_s.titleize}", user_oauth_authorize_url(provider) %><br />
|
||||
<% end =%>
|
||||
@@ -2,6 +2,8 @@ class CreateTables < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :users do |t|
|
||||
t.string :username
|
||||
t.string :facebook_token
|
||||
|
||||
t.database_authenticatable :null => false
|
||||
t.confirmable
|
||||
t.recoverable
|
||||
|
||||
@@ -1,81 +1,47 @@
|
||||
# This file is auto-generated from the current state of the database. Instead of editing this file,
|
||||
# please use the migrations feature of Active Record to incrementally modify your database, and
|
||||
# then regenerate this schema definition.
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
|
||||
# to create the application database on another system, you should be using db:schema:load, not running
|
||||
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20100401102949) do
|
||||
|
||||
create_table "accounts", :force => true do |t|
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :default => "", :null => false
|
||||
t.string "password_salt", :default => "", :null => false
|
||||
t.string "username"
|
||||
t.string "confirmation_token"
|
||||
t.datetime "confirmed_at"
|
||||
t.datetime "confirmation_sent_at"
|
||||
t.string "reset_password_token"
|
||||
t.string "remember_token"
|
||||
t.datetime "remember_created_at"
|
||||
t.integer "sign_in_count", :default => 0
|
||||
t.datetime "current_sign_in_at"
|
||||
t.datetime "last_sign_in_at"
|
||||
t.string "current_sign_in_ip"
|
||||
t.string "last_sign_in_ip"
|
||||
t.integer "failed_attempts", :default => 0
|
||||
t.string "unlock_token"
|
||||
t.datetime "locked_at"
|
||||
t.string "authentication_token"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "admins", :force => true do |t|
|
||||
t.string "email", :default => ""
|
||||
t.string "encrypted_password", :default => ""
|
||||
t.string "password_salt", :default => ""
|
||||
t.string "username"
|
||||
t.string "confirmation_token"
|
||||
t.datetime "confirmed_at"
|
||||
t.datetime "confirmation_sent_at"
|
||||
t.string "email", :default => ""
|
||||
t.string "encrypted_password", :limit => 128, :default => ""
|
||||
t.string "password_salt", :default => ""
|
||||
t.string "reset_password_token"
|
||||
t.string "remember_token"
|
||||
t.datetime "remember_created_at"
|
||||
t.integer "sign_in_count", :default => 0
|
||||
t.datetime "current_sign_in_at"
|
||||
t.datetime "last_sign_in_at"
|
||||
t.string "current_sign_in_ip"
|
||||
t.string "last_sign_in_ip"
|
||||
t.integer "failed_attempts", :default => 0
|
||||
t.integer "failed_attempts", :default => 0
|
||||
t.string "unlock_token"
|
||||
t.datetime "locked_at"
|
||||
t.string "authentication_token"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :default => "", :null => false
|
||||
t.string "password_salt", :default => "", :null => false
|
||||
t.string "username"
|
||||
t.string "facebook_token"
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "password_salt", :default => "", :null => false
|
||||
t.string "confirmation_token"
|
||||
t.datetime "confirmed_at"
|
||||
t.datetime "confirmation_sent_at"
|
||||
t.string "reset_password_token"
|
||||
t.string "remember_token"
|
||||
t.datetime "remember_created_at"
|
||||
t.integer "sign_in_count", :default => 0
|
||||
t.integer "sign_in_count", :default => 0
|
||||
t.datetime "current_sign_in_at"
|
||||
t.datetime "last_sign_in_at"
|
||||
t.string "current_sign_in_ip"
|
||||
t.string "last_sign_in_ip"
|
||||
t.integer "failed_attempts", :default => 0
|
||||
t.integer "failed_attempts", :default => 0
|
||||
t.string "unlock_token"
|
||||
t.datetime "locked_at"
|
||||
t.string "authentication_token"
|
||||
|
||||
@@ -12,7 +12,11 @@ module SharedUser
|
||||
|
||||
module ExtendMethods
|
||||
def find_for_facebook_oauth(access_token, signed_in_resource=nil)
|
||||
User.create { |u| u.update_with_facebook_oauth(access_token) }
|
||||
data = ActiveSupport::JSON.decode(access_token.get('/me'))
|
||||
user = signed_in_resource || User.find_by_email(data["email"]) || User.new
|
||||
user.update_with_facebook_oauth(access_token, data)
|
||||
user.save
|
||||
user
|
||||
end
|
||||
|
||||
def new_with_session(params, session)
|
||||
@@ -25,18 +29,20 @@ module SharedUser
|
||||
end
|
||||
end
|
||||
|
||||
def update_with_facebook_oauth(access_token)
|
||||
data = ActiveSupport::JSON.decode(access_token.get('/me'))
|
||||
def update_with_facebook_oauth(access_token, data=nil)
|
||||
data ||= ActiveSupport::JSON.decode(access_token.get('/me'))
|
||||
|
||||
self.username = data["username"] unless username.present?
|
||||
self.email = data["email"] unless email.present?
|
||||
self.confirmed_at ||= Time.now
|
||||
|
||||
unless password.present?
|
||||
self.confirmed_at ||= Time.now
|
||||
self.facebook_token = access_token.token
|
||||
|
||||
unless encrypted_password.present?
|
||||
self.password = Devise.friendly_token
|
||||
self.password_confirmation = nil
|
||||
end
|
||||
|
||||
yield self if block_given?
|
||||
yield self if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user