OmniAuth before_filter用于要求登录 [英] OmniAuth before_filter for requiring login

查看:69
本文介绍了OmniAuth before_filter用于要求登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用OmniAuth在某些操作之前要求登录?

is it possible using OmniAuth to require login before certain actions?

我从铁路广播中记得Devise有一个before_filter,但是OmniAuth吗?

I remember from a railscast that Devise has a before_filter, but does OmniAuth?

推荐答案

您可以添加before_filter:

class ApplicationController < ActionController::Base

  before_filter :authenticate

  def authenticate
    redirect_to :login unless User.find_by_provider_and_uid(auth["provider"], auth["uid"])
  end
...
end

假设: 1.您已经定义了一个登录页面,其链接如下:<%= link_to "Sign in with Facebook", "/auth/facebook" %>

Presuming: 1. You have defined a login page with link(s) like : <%= link_to "Sign in with Facebook", "/auth/facebook" %>

另请参见带有身份验证标签的RailsCast

这篇关于OmniAuth before_filter用于要求登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆