warden

Where should warden callbacks be placed in a rails app?

谁说胖子不能爱 提交于 2019-12-05 12:45:34
问题 I'm relatively new to rails. I have Devise set up, and want to run some callback code after users sign in. Looking at the Warden wiki page, I can use the "after_set_user" callback to perform this logic, for example: Warden::Manager.after_set_user do |user, auth, opts| unless user.active? auth.logout throw(:warden, :message => "User not active") end end However, I'm not sure where I should be storing this stuff. My first thought is that I could put it in config/initializers/devise.rb. Is that

Prevent session creation on rails 3.2.2 for RESTful api

时光怂恿深爱的人放手 提交于 2019-12-04 17:31:37
问题 How can i prevent the session store from creating a session on JSON/XML calls ? My problem is that i save sessions in a database and it gets flooded on multiple api calls. I'm using Rails 3.2.2 and Devise for authentication. 回答1: My problem here was with Warden inside Devise. I had to "tell" Warden not to store the user in the session after the user is authenticated. resource = warden.authenticate!(:scope => resource_name, :store => !(request.format.xml? || request.format.json?)) Hope that

Rails 3 - Devise redirects to form after sign_in

南笙酒味 提交于 2019-12-04 16:25:20
In a blog app I want every user to access a form to post a comment. When the user submit the comment form he is redirected to the Devise sign_in form if is not logged in. before_filter :authenticate_user!, :except => [:index, :show, :new] How could I once the user sign_in, redirect him to the comment form and fill all fields ? Thanks in advance If you want to take the user to comment form after every sign in, add in ApplicationController: #after_sign_in_path_for is called by devise def after_sign_in_path_for(resource_or_scope) comment_path... end If you want to take user back to the page they

remember_me with warden

有些话、适合烂在心里 提交于 2019-12-04 07:03:20
For my lastest project I'm using https://github.com/hassox/rails_warden . It suits my needs very well except that I can't find a good way to implement remember_me. I know that it's notoriously difficult to get remember_me right from a security point of view so I'm hoping there's a project out there that will do the job. Anyone seen anything or get a good idea? Devise , which is an authentication solution on top of Warden, has a rememberable implementation. Macario Ok here's how I solved it # User model must have remember_token attribute # in config.ru use Rack::Cookies run MyApp # in lib

Where should warden callbacks be placed in a rails app?

拜拜、爱过 提交于 2019-12-03 22:29:02
I'm relatively new to rails. I have Devise set up, and want to run some callback code after users sign in. Looking at the Warden wiki page , I can use the "after_set_user" callback to perform this logic, for example: Warden::Manager.after_set_user do |user, auth, opts| unless user.active? auth.logout throw(:warden, :message => "User not active") end end However, I'm not sure where I should be storing this stuff. My first thought is that I could put it in config/initializers/devise.rb. Is that correct? It doesn't feel right putting what is essentially controller code in the config directory.

Prevent session creation on rails 3.2.2 for RESTful api

不打扰是莪最后的温柔 提交于 2019-12-03 11:22:17
How can i prevent the session store from creating a session on JSON/XML calls ? My problem is that i save sessions in a database and it gets flooded on multiple api calls. I'm using Rails 3.2.2 and Devise for authentication. My problem here was with Warden inside Devise. I had to "tell" Warden not to store the user in the session after the user is authenticated. resource = warden.authenticate!(:scope => resource_name, :store => !(request.format.xml? || request.format.json?)) Hope that helps whoever sees this thread. Altonymous resource = warden.authenticate!(:scope => resource_name, :store =>

Accessing the new session_id in devise after sign_in

和自甴很熟 提交于 2019-12-02 07:49:10
问题 I am using devise & overriding SessionsController#create to track the login based on a specific condition. The value of session[:session_id] before sign_in(user) is same even after the execution of sign_in(user). I would like to store the new session_id in DB in order to track the user. But unable to access it. How to get it? While looking for it, found that Devise uses set_user method of Warden. But even then, I could not figure out where the session is set in Warden. 回答1: Found the answer

Accessing the new session_id in devise after sign_in

浪子不回头ぞ 提交于 2019-12-02 05:42:50
I am using devise & overriding SessionsController#create to track the login based on a specific condition. The value of session[:session_id] before sign_in(user) is same even after the execution of sign_in(user). I would like to store the new session_id in DB in order to track the user. But unable to access it. How to get it? While looking for it, found that Devise uses set_user method of Warden. But even then, I could not figure out where the session is set in Warden. Shriram Balakrishnan Found the answer in the following question: Rails ActiveRecord store and new session Answer by Benjamin

How to structure authenticated routes when using Devise?

你说的曾经没有我的故事 提交于 2019-12-01 10:52:07
问题 In my question How to have root view when user is not logged in rails? max answered that we can use authenticated to make routes available only when someone is authenticated. I am having a probem that how can I structure this: Rails.application.routes.draw do devise_for :users authenticated :user do # when authenticated allow all action on student resources :subjects do resources :students end end # when not only allow read on student resources :subjects do resources :students, only: [:get]

Stubbing Warden on Controller Tests

倖福魔咒の 提交于 2019-12-01 06:48:42
I'm having an issue with testing my controllers and using Warden. All examples point at stubbing request.env['warden'] . This causes issues in my controllers when I call env['warden'] , which then returns nil . For a crude example, using this: request.env['warden'] = double(Warden, :authenticate => nil, :authenticate! => nil, :authenticated? => false) And a simple before filter like this: before_filter do redirect_to new_user_session_url unless env['warden'].authenticated? end I get a nil . I just managed to get it working using controller.env['warden'] = ... and it works. This makes sense,