如果我有omniauth 允许用户使用诸如facebook/twitter 之类的提供程序登录,我如何检查current_user 是否使用omniauth 登录?
我希望仅当 current_user 通过omniauth 登录时才允许代码运行。
这是我的架构的外观
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.timestamp "created_at", :null => false
t.timestamp "updated_at", :null => false
t.string "password_digest"
t.string "remember_token"
end
create_table "authentications", :force => true do |t|
t.integer "user_id"
t.string "provider"
t.string "uid"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "secret"
t.string "token"
end
控制器
class PostsController < ApplicationController
def create
@post = current_user.posts.build(params[:post])
if @post.save
if @post.check
UserMailer.check_email(@user).deliver
else
flash[:success] = "Posted"
Twitter::Client.new.update(@post.content) if logged_using_omniauth? request != nil
end
redirect_to root_path
else
@feed_items = []
render 'static_pages/home'
end
end