所以我正在制作一个rails应用程序,它也利用node.js来实现实时功能.在节点应用程序上对用户进行身份验证的最佳方法是什么?我一直在考虑在数据库中保存会话ID,然后用它进行验证,或者在页面中显示用户ID,然后在连接时将其发送到节点应用程序.或者也许其他东西完全是最好的.我正在使用猫鼬为我的节点orm和mongoid用于红宝石.
我构建了一个应用程序,允许用户使用omniauth-ldap对Active Directory进行身份验证.如果这是新用户,则成功的身份验证将根据从AD返回的信息为其创建用户.如果用户已存在,则只会将其登录.用户不会注册该应用程序,只需使用AD凭据登录即可.我从不希望用户使用数据库凭据登录.
我无法弄清楚如何摆脱或改变一些路线.例如,如果用户访问/ sign_in,他们将获得数据库身份验证.如果用户访问sign_up,他们将被带到页面注册该站点.我希望访问/ sign_in的用户进入LDAP登录,即/ users/auth/ldap.我想我需要制作一个自定义路线,但我不确定我需要哪个控制器来引导用户.我想让sign_up页面完全消失.
现在我有一个允许用户使用ldap登录的链接,其路径是user_omniauth_authorize_path(:ldap).我只是不确定如何将其转换为我的config/routes.rb文件理解的内容.这就是我现在在路线上所拥有的.
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
get 'sign_in', :to => 'devise/sessions#new', :as => :new_user_session
get 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session
end
Run Code Online (Sandbox Code Playgroud)
当我运行rake路由时,我没有看到user_omniauth_authorize_path的任何路由,我认为是因为该路由是由设计生成的.所以我认为我需要让我的路线指向一个设计控制器,但我似乎无法找到正确的路径.
我在Rails应用程序中使用Devise并希望通过API公开一些模型数据,但应该像应用程序一样限制对API的访问.
$ curl http://myapp.com/api/v1/sales/7.json
{"error":"You need to sign in or sign up before continuing."}
Run Code Online (Sandbox Code Playgroud)
明显.
在这种情况下访问API是否有最佳实践?我更愿意一步验证+获取数据,但这只是为了让客户的工作更轻松.他们将使用JQuery吸引数据客户端.
感谢您的任何信息!
模型:
devise :database_authenticatable, :registerable,:timeoutable, :recoverable, :rememberable, :trackable, :validatable,:timeout_in => 10.seconds
Run Code Online (Sandbox Code Playgroud)
development.rb:
config.timeout_in = 10.seconds
Run Code Online (Sandbox Code Playgroud)
devise.rb:
config.timeout_in = 10.seconds
Run Code Online (Sandbox Code Playgroud) 我正在尝试建立授权/身份验证系统,我感到困惑,所以我有几个问题:
我已经尽力阅读所有涉及的文档,我从本教程开始
http://railsapps.github.com/tutorial-rails-bootstrap-devise-cancan.html
虽然我也阅读了 http://starqle.com/articles/rails-3-authentication-and-authorization-with-devise-and-cancan-part-1/和tonyamoyal.com/2010/09/29/rails -authentication与-色器件和-康康舞部分-2-宁静资源换管理员/
我真的不能按照我想要的方式工作.我该怎么做呢?
我正在使用Omniauth和Devise使用google_oauth2
策略.它运作良好,但现在我想用我选择的方式更改授权路径.
实际上,http://localhost:3000/users/auth/google_oauth2
我想要更简单,http://localhost:3000/login
因为它很容易记住.
它不会引起任何错误,因为我已禁用Devise数据库可验证(登录的唯一方法是通过谷歌帐户).
我能怎么做?
谢谢.
我正在使用rails with devise进行注册.我还添加了一个邀请码,所以不是每个人都可以注册.
邀请代码通过查询字符串传输,如"/ users/sign_up?invite_code = wajdpapojapsd",并通过"f.hidden_field:invite_code,:value => params [:invite_code]添加到注册表单的隐藏字段中".
这非常有效.唯一的问题是,如果注册没有得到验证和拒绝,则设计重定向到"/ users"并丢失其中包含invite_code的查询字符串.
由于在尝试失败后电子邮件保留在注册表单中,我相信这也适用于邀请代码.作为最糟糕的解决方案重定向:在注册失败并丢失电子邮件后返回,但保留邀请代码,将比现在的工作方式更好.
编辑:到目前为止我已经为设计设置了一个注册控制器,但是不知道如何获得所需的行为.
有关如何保留查询字符串或仅提供邀请代码的任何帮助都很棒.
我正在尝试允许用户更改其设计用作其唯一用户名的电子邮件地址.即使更新没有出现错误,也不会对数据库中用户的电子邮件地址进行任何更改.
以下是代码的相关部分:
形成:
<%= f.fields_for :user_account, @user.user_account do |user_account| %>
<p>Edit email address for account: <%= @user.user_account.email %></p>
<div class="field">
<%= user_account.label :new_email %><br />
<%= user_account.text_field :email, autocomplete: "off", value: nil %>
</div>
<div class="field">
<%= user_account.label :password %> <i>(please confirm the password associated with this account)</i><br />
<%= user_account.password_field :current_password, autocomplete: "off" %>
</div>
<%= hidden_field_tag 'form', 'email' %>
<div class="actions">
<%= user_account.submit "Edit" %>
</div>
Run Code Online (Sandbox Code Playgroud)
控制器:
def update
respond_to do |format|
if params[:form] == 'email'
if @user.user_account.valid_password?(params[:user][:user_account_attributes][:current_password]) …
Run Code Online (Sandbox Code Playgroud) 我想用devise gem创建一个rails API进行身份验证.我正在使用Chrome Postman来检查API输出.
我的环境:
我做了什么:
跑
rails new my_api
cd my_api
Run Code Online (Sandbox Code Playgroud)添加了设计宝石 Gemfile
bundle install
添加
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
Run Code Online (Sandbox Code Playgroud)
至 environment/development.rb
rails console
之后我尝试从邮递员登录.我给email
和password
成邮差的头.
POST http://localhost:3000/users/sign_in
Run Code Online (Sandbox Code Playgroud)
头
电子邮件 abcd @ gamilcom
密码abcd1234
但它不是在验证.我需要做什么?
我有一个非常古老的Rails 2.3.18,ruby 1.9.3,rspec 1.x应用程序我们正在升级它并且它有restful-authentication.所以我用Devise 1.0.11取而代之.
我可以登录到该应用程序,但我的测试不会运行;
这是有问题的测试
require 'spec_helper'
describe CategoriesController do
context "As a logged in user" do
before do
login_user
current_firm = mock_model(Firm, :id => 1)
controller.stub!(:current_firm).and_return(current_firm)
end
describe "#index" do
it "should render index" do
get :index
response.should render_template('index')
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误;
NoMethodError in 'CategoriesController As a logged in user#index should render index'
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while …
Run Code Online (Sandbox Code Playgroud)