Tag: 认证

Devise&CanCan – CanCan 2.0 API的问题

我想为我的用户模型添加其他属性,并且不希望创建单独的配置文件模型。 我正在尝试使用RESTful操作集中的标准«更新»来更新自定义字段: class UsersController < ApplicationController before_filter :authenticate_user! # … def update @user = User.find(params[:id]) authorize! :update, @user respond_to do |format| if @user.update_attributes(params[:user]) format.html { redirect_to @user, notice: 'User was successfully updated.' } format.json { head :ok } else format.html { render action: "edit" } format.json { render json: @user.errors, status: :unprocessable_entity } end end […]

Rails 4 – 设计,访客用户导致filter链停止

我刚刚开始研究Rails 4(4.2.3)应用程序,我使用Devise进行用户身份validation。 我希望用户能够在签署upp之前通过创建测试项目并以guest用户身份登录来使用应用程序。 当用户注册(或进入)时,我想将测试项目分配给新的当前用户。 我一直在关注Platformatec的这个指南: https : //github.com/plataformatec/devise/wiki/How-To : -Create-a-guest-user 创建访客用户是有效的,但在注册或使用活动访客用户会话时,我收到以下错误: Filter chain halted as :require_no_authentication rendered or redirected 如果我清除我的会话它是有效的。 管理我的访客用户的方法如下所示: def current_or_guest_user if current_user if session[:guest_user_id] && session[:guest_user_id] != current_user.id logging_in guest_user(with_retry = false).try(:destroy) session[:guest_user_id] = nil end current_user else guest_user end end 如上所述,创建访客用户似乎工作得很好。 但这种逻辑永远不会发生: # should delete the guest user and clear the […]

Rest-Client获取authenticity_token以创建新记录

我尝试用ruby程序创建一个新人,为此任务我使用rest-client: require ‘rest_client’ require ‘nokogiri’ page = Nokogiri::HTML(RestClient.get(“localhost:3000/people/new”)) token = page.css(“input[name=’authenticity_token’]”) token2 = token[0][“value”] RestClient.post ‘localhost:3000/people’, :authenticity_token => token2, :person => {:name => ‘Joseph’}, :commit => ‘Create Person’ 我试图通过首先向people / new发出get请求来获取authenticity_token,并使用nokogiri从隐藏的输入中读出authenticity_token: 然后我用这个authenticity_token发帖请求,你怎么看上面。 但是有些情况不会起作用,我的rails控制台说它没有令牌真实性: Started POST “/people” for 127.0.0.1 at 2013-09-09 09:33:27 +0200 Processing by PeopleController#create as XML Parameters: {“authenticity_token”=>”WnbZY/060H5IMGdpVMyRKwG/CHKNAEGafOV3i1f8Kj o=”, “person”=>{“name”=>”Joseph”}, “commit”=>”Create Person”} WARNING: Can’t […]

从中间件中触发基本的HTTP身份validation

我已经为rails创建了一个自定义中间件,它将拦截所有请求并确保它来自授权的IP,否则它应该提示基本的http auth用户/名称密码。 这是目前的样子: require ‘net/http’ class AuthorizeEnvironment def initialize(app) @app = app end def call(env) if AppConstants.approved_doximity_ips.include?(env[“REMOTE_ADDR”]) @app.call(env) elsif authorized?(env) @app.call(env) else [403, {“Content-Type” => “text/html”}, [“Not Authorized on this environment.”]] end end def authorized?(env) @auth ||= Rack::Auth::Basic::Request.new(env) @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == [‘username’, ‘password’] end end 这段代码的问题是我似乎找不到在浏览器上触发http auth窗口的方法 。 我对此进行了审核,并没有看到任何明显的迹象表明这是如何完成的。 你能指点我正确的方向吗?

为什么Devise一直问我这个名字不能是空白的?

我是Rails的新手,我正在与Devise合作。 我面临的问题是我的表单在注册时没有更新用户的名称列。 我在数据表中有name属性,但我似乎无法使用设计注册中的表单来更改它。 Sign up resource_name, :url => registration_path(resource_name)) do |f| %> true %> class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_many :posts end Scheme.rb ActiveRecord::Schema.define(version: 20130622203624) do create_table “posts”, force: true do |t| t.integer […]

Rails:RSpec – 用于nil的未定义方法`cookie_jar’:NilClass

Rails新手。 试着按照Michael Hartl的教程。 试图添加辅助方法来模拟RSpec测试中的日志: describe “when the a user has logged in and attempts to visit the page” do let(:user) { FactoryGirl.create :user } before do log_in user end it “should redirect the user to next page” do specify { response.should redirect_to loggedin_path } end end 在我的spec / support / utilities.rb中: def log_in user visit […]

如何将before_filter应用于Rails 3.2.11中每个控制器的每个动作?

我想validation用户是否登录到服务器的每个请求。 就像是: :before_filter verify_logged_in 我应该在哪里放置before_filter,以便它适用于所有控制器操作和所有请求?

设计和rails 3中的http身份validation

我有一个在rails 3上使用devise的应用程序。我想启用http身份validation,以便我可以通过iPhone应用程序对我的Web应用程序进行身份validation。 如何从我的iPhone应用程序进行身份validation? 这是安全的还是我应该以不同方式进行身份validation?

Ruby Webrick HTTP身份validation

如何使用如下子类在此页面中执行相同的身份validation: class Configuration 666) server.mount “/conf”, Configuration trap “INT” do server.shutdown end server.start

具有身份validation的私有Ruby Gem服务器

我想安装一个带有一些身份validation的私有Ruby gem服务器。 我希望能够使用公共Ubuntu服务器托管内部gem。 我读到了http://docs.rubygems.org/read/chapter/18 。 但是没有认证那个 – 我可以看到。 然后我读了一下https://github.com/cwninja/geminabox 。 但是,当我使用基本身份validation(他们在他们的Wiki中)时,它抱怨从我的服务器获取源。 所以。 如何使用身份validation创建私有Ruby gem服务器? 这不可能吗? 谢谢。 编辑: Geminabox问题。 我尝试“捆绑”以安装新的gem……但它给了我这个错误: AGs-MacBook-Pro:super_app AG $捆绑 获取http:// ruby​​gems.org/的源索引 获取http:// localhost:9292 /的源索引 无法访问rubygems存储库http:// ruby​​gems.org/,http:// localhost:9292 / 在任何来源中都找不到aglipsum-0.0.1 而“aglipsum”是我的定制gem。 但是,当我没有基本身份validation时,它可以工作。