Tag: 令牌

rails教程:cookie与记忆令牌不匹配

我正在做Michael Hartl的Rails教程第8章。当我尝试通过存储在浏览器cookie中的remember_token找到用户时,它无法正常工作。 find_by方法返回NIL。 我一直在尝试通过查看存储在浏览器上的记忆令牌cookie并将其与存储在用户数据库中的记忆令牌进行比较来进行调试。 他们不匹配,我不知道为什么。 这是Session Helper的代码。 module SessionsHelper def sign_in(user) remember_token = User.new_remember_token cookies.permanent[:remember_token] = remember_token user.update_attribute(:remember_token, User.encrypt(remember_token)) self.current_user = user end def signed_in? !current_user.nil? end def current_user=(user) @current_user = user end def current_user #remember_token = User.encrypt(cookies[:remember_token]) remember_token = “71e45660fbaa69bad9fb55b912f80122a584f6af” #@current_user ||= User.find_by(remember_token: remember_token) @current_user ||= User.find_by_remember_token(remember_token) end end 我一直在调整它以试图弄清楚发生了什么。 为了调试,我注释掉了正常的行并使用我在数据库中看到的值显式设置了记忆标记 – 然后应用程序正常工作。 当我将存储在浏览器中的cookie的值与存储在数据库中的记忆令牌的值进行比较时,它们不匹配。 […]

在页面上的多个输入上使用tokeninput jquery插件

我正在使用来自loopj.com的jquery tokeninput插件。这是我的JS文件: $(document).ready(function() { // Token input plugin: $(“#issuer”).tokenInput(“/issuers.json”,{ crossDomain: false, theme: “facebook”, prePopulate: $(“#issuer”).data(“pre”), preventDuplicates: true }); $(“#shareholder”).tokenInput(“/shareholders.json”,{ crossDomain: false, theme: “facebook”, prePopulate: $(“#shareholder”).data(“pre”), preventDuplicates: true }); }); 这是我的标记: \ Issuer Shareholder 我的tokenize插件适用于#issuer但不适#shareholder ,如果我使用顶部的#shareholder选择器移动jQuery代码,令牌输入代码适用于#shareholder但停止为另一个工作。 我怎么能让它们都适用于它们? 此外,如果我在编辑模式下具有相同标记的相同表单 – 这意味着data-pre具有有效的JSON而不是[null] ,则令牌输入适用于这两个字段。

Rails简单forms给出了InvalidAuthenticityToken错误

我有一个这样的简单forms: 和这种方法的控制器: def busca puts params[:searchText] end 当我单击表单中的图像按钮时,我得到一个ActionController :: InvalidAuthenticityToken。 这是完整的StackTrace: /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/request_forgery_protection.rb:86:in verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in / verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in / verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in / verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in / verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in / verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in / verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in / verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in发送’/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in evaluate_method’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:166:in verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in / verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in / verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in / verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in / verify_authenticity_token’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in evaluate_method’ /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:166:in调用’/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:225:in call’ /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:629:in […]

使用来自请求标头的auth_token而不是使用Rails 3 / devise的POST / PUT参数

我需要在Rails 3.1 API中结合最新版本的设备使用基于令牌的身份validation。 到目前为止没问题。 现在我不想将我的:auth_token附加到客户端的POST / PUT参数,而是将此令牌作为请求标头发送,如HTTP_X_MYAPP_AUTH_TOKEN“。 我可以说服设计使用它而不是参数中的令牌吗? 是否可以实现这两者,以便我的API用户可以通过请求头或POST / PUT参数发送令牌? 问候。 费利克斯

Devise Token Auth错误:未设置Devise.secret_key

我目前正在使用Devise Token Auth( https://github.com/lynndylanhurley/devise_token_auth )gem并使其在开发中运行良好。 但是,在我的生产环境中,当我运行rake db:migrate ,我收到以下错误: rake aborted! Devise.secret_key was not set. Please add the following to your Devise initializer: config.secret_key = ‘my secret key’ Please ensure you restarted your application after installing Devise or setting the key. /Users/karimbutt/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/rails/routes.rb:480:in `raise_no_secret_key’ /Users/karimbutt/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/rails/routes.rb:209:in `devise_for’ /Users/karimbutt/.rvm/gems/ruby-2.1.2/gems/devise_token_auth-0.1.31/lib/devise_token_auth/rails/routes.rb:25:in `mount_devise_token_auth_for’ /Users/karimbutt/Development/projects/haubby/backend/config/routes.rb:3:in `block in ‘ /Users/karimbutt/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:423:in `instance_exec’ /Users/karimbutt/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:423:in `eval_block’ /Users/karimbutt/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:401:in […]