Tag: 认证

Rails为某些用户类型设计了禁用密码恢复function

在我的Rails项目中,我有不同类型的用户,其中一个用户具有user_status :admin ,与其他用户不同,它具有编辑内容的完全权限。 出于显而易见的原因,我想为这些类型的用户添加额外的安全性,特别是完全禁用密码恢复。 覆盖标准Devise密码恢复( :recoverable Devise模块)方法的正确方法是什么,以便当用户尝试为管理员用户( user_status == “admin” )的用户获取重置密码链接时,系统会返回“标准电子邮件未找到”消息? 这有点像未回答的问题:将设计密码恢复限制为仅限某些用户 先感谢您。

Rails,Sidekiq – Redis NOAUTH

我在rails上使用sidekiq发送电子邮件。 我已经为redis服务器添加了密码,但似乎无法正确使用,因为我收到了错误 D, [2015-12-10T16:49:52.714279 #10497] DEBUG — : (0.5ms) COMMIT I, [2015-12-10T16:49:52.720380 #10497] INFO — : [ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 5bce215c-7649-4774-8c6e-d29e743cf25e) to Sidekiq(mailers) with arguments: “MessageMailer”, “new_message”, “deliver_now”, gid://customer-app/Message/18 I, [2015-12-10T16:49:52.723400 #10497] INFO — : Completed 500 Internal Server Error in 25ms (ActiveRecord: 1.6ms) F, [2015-12-10T16:49:52.726204 #10497] FATAL — : Redis::CommandError (NOAUTH Authentication required.): […]

Rails重定向到登录前想要查看的页面用户

我正在尝试将用户重定向回他们在登录之前尝试访问的页面(该页面仅供用户查看)。 我将从一个针对我的旅行新动作的前filter开始: before_filter :authenticate, :only => [:new, :create, :edit, :update, :destroy] def authenticate deny_access unless signed_in? end def deny_access store_location redirect_to login_path, :notice => “Please log in to access this page.” end def store_location session[:return_to] = request.fullpath end 这是我的sessions_controller.rb中的new和create操作 def new @title = “Log in” end def create user = User.authenticate(params[:session][:email].downcase, params[:session][:password]) if user.nil? flash.now[:error] […]

Warden身份validation召回401 Unauthorized

我尝试使用全新的rails应用程序设置设计,我已使用gemfile和bundle install正确安装 以下使用rails生成设计devise:install 使用rails generate devise用户创建了一个新模型 rake db:migrate来创建用户表 添加了devise_for :users do get ‘users/sign_out’, :to => ‘devise/sessions#destroy’ end用于我的浏览器注销 运行rails服务器 转到localhost:3000 / users / sign_up以创建新用户 转到localhost:3000 / users / sign_out将他注销 转到localhost:3000 / users / sign_in并尝试再次登录并失败并返回以下内容并将我发送回登录屏幕而不登录 Started POST “/users/sign_in” for 127.0.0.1 at 2012-07-13 16:55:28 +0800 Processing by Devise::SessionsController#create as HTML Parameters: {“utf8″=>”✓”, “authenticity_token”=>”cbFEP0FJ/e2XYHfub3ZeI7nEX0nCheXzCDs2ner3Zw8=”, “newuser”=>{“email”=>”henghong.lee@gmail.com”, “password”=>”[FILTERED]”, “remember_me”=>”0”}, “commit”=>”Sign in”} […]

如何在过滤之前添加身份validation到rails 3应用程序,并设计用户注册并登录?

鉴于我使用的是Rails 3.1,Ruby 1.9.2,其标准设置用于通过名称和密码登录用户(例如类似于https://github.com/RailsApps/rails3-devise-rspec-cucumber ): 在创建新用户(注册) 或用户登录之前 ,我需要添加一个层来对外部服务validation发布的用户名和密码。 (FWIW,我计划使用https://github.com/chicks/devise_aes_encryptable strategy / gem来加密敏感密码,并在使用本地密码登录时,解密远程服务的密码,进行validation,然后继续登录,即有两个密码,一个加密单向,另一个可逆…不要问为什么,反正) 在lib / util / authenticate.rb中,我有一个认证类,它返回一个针对该服务的布尔值,例如 Util::Authenticate.authenticate(username,password) 但是,我无法弄清楚如何在身份validation继续之前添加filter以对其进行身份validation(用于注册或登录)。 我尝试过的: 我有一个用户模型,我想放一个 before_filter :authenticate_against_my_service, :only => [:create, :new] 在UserController但但没有用 所以,我尝试打开Devise Sessions控制器,它没有工作,也没有对它进行子类化(例如在自述文件中), class User::SessionsController { :sessions => “users/sessions” } 也没有对Devise Registrations控制器进行子类化(例如http://www.tonyamoyal.com/2010/07/28/rails-authentication-with-devise-and-cancan-customizing-devise-controllers/ )并添加before_filter(与以上)。 # in app/controllers/users/registrations_controller.rb class Users::RegistrationsController [:new, :create, :cancel] skip_before_filter :require_no_authentication def check_permissions authorize! :create, resource end […]

Rails和Authlogic:每个用户只允许一个会话?

有没有办法限制Ruby on Rails应用程序中的会话数量(我使用Authlogic进行身份validation)? 我想每个用户帐户只允许1个会话。 当同一用户登录另一台计算机时,上一个会话应该过期/无效。 我正在考虑将会话数据存储在数据库中,然后在创建新会话实例时将其删除但可能有更简单的方法吗? (配置选项)

Active_shipping Fedex API身份validation错误

我正在我的应用中实现aсtive_shipping插件function。 我有来自fedex的测试帐户并试图获得一些运费,如插件的自述文件中所示: fedex = FedEx.new(:login => ‘***’, :password => ‘***’, :key => ‘***’, :account => ‘510087569’, :meter => ‘100054531’) response = fedex.find_rates(origin, destination, packages) 此请求导致错误: ActiveMerchant::Shipping::ResponseError (ERROR – 1000: Authentication Failed) 此外,我对所有API密钥(DHL,UPS等)感到困惑。 我是否可以为每个运营商在不同的应用程序中使用相同的帐户密钥,还是应该为每个应用程

heroku上的Google Vision API身份validation

什么是在heroku上validationVision API的最佳,简单方法? 在开发中我只使用: @vision = Google::Cloud::Vision.new( project: “instacult”, keyfile: “path/to/keyfile.json” ) 其中keyfile是google在创建服务帐户后生成的json( https://cloud.google.com/vision/docs/common/auth )。 但显然我不能只将密钥文件上传到github。 我尝试将整个json保存到Heroku的配置变量并运行: Rails.env.production? ? ENV[“GOOGLE_CREDENTIALS”] : path 但是我在heroku的日志中得到“不是一个有效的文件”。 由于我没有传递文件而是传递对象,因此似乎是合乎逻辑的。 但是如何克服它呢? 干杯,凯

rails authenticate_or_request_with_http_basic

在我的RoR应用程序中,我需要使用基本身份validation来保护页面,并且我希望每次用户链接到该页面时都会询问凭据。 所以我在操作之前添加了一个filter,如下所示: before_filter :request_confirm, :only => [:delete_device] 过滤方法是: def request_confirm user = User.find_by_id(session[:user_id]) authenticate_or_request_with_http_basic do |nick, pass| nick == user.nickname and pass == user.password end end 没关系,但只是第一次因为rails保存插入的数据,所以以下时间filter将被执行但凭证不会询问。 我不知道保存凭据的位置。 。

使用rspec测试设计视图

我已经生成了运行rails g devise:views Devise的视图,现在想测试它们。 这就是我想出的: require ‘spec_helper’ describe “devise/sessions/new” do before do render end it “renders the form to log in” do rendered.should have_selector(“form”, action: user_session_path, method: :post) do |form| end end end 对于render语句,它给了我undefined local variable or method ‘resource’ 。 谷歌搜索后我发现我应该添加 @user.should_receive(:resource).and_return(User.new) 在render语句之前 – 但它仍然给我相同的错误,我不确定如何使用它。 我究竟做错了什么? 谢谢你的帮助。