Tag: 认证

使用计算/操作的用户名参数设计登录

我正在尝试使用带有我已计算的用户名的设计创建登录。 作为一个例子,我们假设我们想要命名我们的用户名 – 我希望从登录表单接收用户名,并使用namespaced_username进行实际身份validation。 所以在我的User::SessionsController#create ,我可能有: def create params[:user][:namespaced_username] = “namespace/#{params[:user][:mobile_number]}” super end 尽管设计正在侦听namespaced_username(在初始化程序或模型本身中配置了authentication_keys),并且用户设置为namespace/username ,但我仍然会被告知Invalid Namespaced username or password is not valid 我如何获得设计(特别是看守策略)来阅读新的参数?

Omniauth Facebook的before_filter?

对于设计,有一个非常容易使用的Before_filter在控制器中使用。 由于某种原因,我不能让这个为Omniauth_facebook Gem工作。 我在Facebook Omniauth上关注了Railscast before_filter :authenticate def authenticate redirect_to :login unless User.find_by_provider_and_uid(auth[“provider”], auth[“uid”]) end end 但是我收到一个错误: NameError in PostsController#new undefined local variable or method `auth’ for # 有什么想法吗?

Rails Auth,记住我

我正在尝试按照Ryan Bates的教程添加记住我的登录表单function。 但是,当我尝试访问我的页面时,我收到此错误: 找不到具有auth_token =用户 我认为问题来自我的application_controller.rb class ApplicationController < ActionController::Base protect_from_forgery helper_method :current_user private def current_user @current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token] end end 这是我的user.rb中的代码 class User :create before_create { generate_token(:auth_token) } def send_password_reset generate_token(:password_reset_token) self.password_reset_sent_at = Time.zone.now save! UserMailer.password_reset(self).deliver end def generate_token(column) begin self[column] = SecureRandom.urlsafe_base64 end while User.exists?(column => self[column]) end end 这是我的user_controller.rb class […]

Rails 3 / devise似乎忽略了自定义控制器

使用Rails 3应用程序的设计,我已经阅读了如何自定义后注册路由的wiki / docs,我正在使用可确认模块,所以我想我需要覆盖after_inactive_sign_up_path_for 我想我已经做得很好,但它完全忽略了我的自定义控制器,并在注册后仍然路由到root_path。 使我抓狂。 我的注册是使用用户模型,我使用generate任务复制了devise的视图; 如果我将它们移动到视图/注册设计回落到默认视图(在我猜的gem中),所以它似乎不是’注意’我的控制器 我的路线中有这个: devise_for :users, :controllers => { :registrations => “registrations” } match ‘sign_up_done’ => ‘home#sign_up_done’, :as => :after_sign_up 这是我的控制器:(controllers / registrations_controller.rb) class RegistrationsController < Devise::RegistrationsController def after_inactive_sign_up_path_for(resource) after_sign_up_path end def after_sign_up_path_for(resource) after_sign_up_path end end (添加after_sign_up_path_for以防万一,使用确认) 它似乎完全忽略了我的控制器,命名错了吗? 谢谢你的任何输入!

Rails 4带有Clearance密码重置问题

我正在使用身份validationgem’ clearance’构建一个Rails 4应用程序。 我有点困惑于以下问题: 当用户忘记他/她的密码并想要设置新密码时,找不到该用户。 (但存在于DB中),这是服务器日志: Started PUT “/passwords/1?token=[FILTERED]” for 127.0.0.1 at 2013-08-10 21:00:58 +0200 Processing by PasswordsController#update as HTML Parameters: {“utf8″=>”✓”, “authenticity_token”=>”[FILTERED]”, “password_reset”=>”[FILTERED]”, “token”=>”[FILTERED]”, “id”=>”1”} User Load (1.1ms) SELECT “users”.* FROM “users” WHERE “users”.”id” IS NULL AND “users”.”confirmation_token” = ‘bcc6a5b49bc64628eff15bf92761fe1775ef252c’ LIMIT 1 Rendered passwords/new.html.slim within layouts/application (0.9ms) Rendered partials/_favicon_styles.html.slim (0.4ms) User Load (0.9ms) SELECT […]

Rails 3.2 Omniauth Devise – 添加密码 – 跳过当前密码

我正在使用Omniauth允许用户通过Facebook,Twitter和Google登录(并创建帐户)。 但是,如果用户决定不再使用这些服务,但继续使用他们的帐户,他们会想要添加密码。 如何在不输入current password情况下让用户为其帐户添加current password ?* 当我让用户转到edit_user_registration_path(@user) ,他们会看到以下表单: = form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, name: ‘validation’}) do |f| = devise_error_messages! = f.label :email, class: ‘block’ = f.email_field :email, class: ‘large’ %span.infobar Keep this here unless you’d like to change your email = f.label :password, class: ‘block’ = f.password_field :password, class: ‘large’ […]

我应该在rails app中为http基本身份validation添加用户名/密码

我将在rails应用程序中使用http-basic-authentication。 我看了这个railscast来弄清楚这是怎么做到的: http://railscasts.com/episodes/82-http-basic-authentication 在video中,他说不要将用户名和密码直接放在代码中。 我应该把它们放在哪里呢? 我正在使用rails 3.1.0。

Rails – 避免OmniAuth和共享计算机风险的策略

在测试Omniauth并关注流行的Ryan Bates的video时,我认为存在一个重大的安全漏洞。 这是一个例子 我有两个用户:Aurelien和John 约翰在早上登录到Twitter但忘记退出。 然后他继续我的应用程序并通过http://myapplication.com/auth/twitter连接到Twitter服务。 他被自动分配到Twitter身份validation,因为Twitter记得约翰已登录。约翰去上class。 与此同时,他的兄弟Aurelien使用相同的计算机并使用我的应用程序。 他决定发布我的应用程序的推文并继续访问http://myapplication.com/auth/twitter ,通过OmniAuth登录他的Twitter帐户。 多么惊喜! 他不需要登录,但是当重定向到回调URL时,他发现他当前以John身份登录! 现在我想相信大多数用户不共享他们的电脑/桌面/电话,但我确信这是一个经常出现的问题。 您可以遵循什么策略或逻辑来防止这种情况发生? 例如,如何确保当需要与myapplication不同的用户登录Twitter而不是使用之前打开的Twitter会话时? 欢迎举例!

在Rails Devise app中Find_for_database_authentication vs Find_by?

所以,我正在尝试使用设计建立一个React前端和Rails后端,而Rails端应该是一个内部API。 这是我第一次这样做,所以我正在努力进行身份validation。 具体来说,在我的SessionsController中,我有这样的代码: def create resource = User.find_for_database_authentication(email: params[:email]) return invalid_login_attempt unless resource if resource.valid_password?(params[:password]) sign_in :user, resource return render nothing: true end invalid_login_attempt end 这总是返回401 Unauthorized。 我检查调用valid_password的结果? 它总是假的。 但是,如果我用find_for_database_authentication替换find_by ,那么valid_password? 工作没有问题。 为什么是这样? 如果现在用户只能输入他的电子邮件而不是他的密码,这没关系,但这确实让我很困惑。 它也让我觉得这不会使用任何令牌检查(不同的问题)。 另一方面,我也想知道CSRF令牌是否适用于内部API(我应该使用不同的令牌身份validation吗?),以及如果用户使用登录表单我应该如何包含CSRF令牌尚未登录,但我猜这些是另一篇文章的问题。 谢谢你的帮助。

设计现有数据库:401使用有效密码未授权

我正在尝试使用设计用于我的网站的用户身份validation。 它使用现有的User表。 该表具有用户名和密码,但是当我尝试登录时,出现以下错误: 在90ms内完成401 Unauthorized。 日志: Started POST “/users/sign_in” for 127.0.0.1 at 2013-06-06 15:50:01 +0530 Processing by Devise::SessionsController#create as HTML Parameters: {“utf8″=>”✓”, “authenticity_token”=>”+uKE28LrkWW71EHeasDSDCENQogAGODfBc3ZJJLyi9U=”, “user”=>{“email”=>”admin@abc.com”, “password”=>”[FILTERED]”, “remember_me”=>”0”}, “commit”=>”Sign in”} User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = ‘admin@abc.com’ LIMIT 1 Completed 401 Unauthorized in 90ms Processing by Devise::SessionsController#new as HTML Parameters: {“utf8″=>”✓”, “authenticity_token”=>”+uKE28LrkWW71EHeasDSDCENQogAGODfBc3ZJJLyi9U=”, “user”=>{“email”=>”admin@abc.com”, […]