Devise access params in Devise sessions view - ruby-on-rails

I'm on Rails 3.0.9, Ruby 1.9.2, Devise 1.3.4
URL to an authenticated Devise resource for my app, e.g.,
http://myblog.com/article/5?type=blah
This will cause Devise to redirect to a login page. I have a need on Devise login page, sessions#new.html.erb, to conditionally display a drop down depending on type and I have no idea how to access it from sessions#new.html.erb. I tried params and that didn't work, ideas?

I found a workaround, Devise stores that info in a session variable
session[:user_return_to]
Hope this helps someone else out of a jam if they need to do the same thing

Related

Devise - LogIn parameters invalid email and password

I am new to RoR and I used devise gem for authentication.
I have a login form which is created by command "rails g devise:views"
If I change the form_for(:session,.......) it shows invalid email and password and if I change to form_for(:user,......) it is working.
Questions:
1)Why only user resource not any other resource or controller because the first parameter is for only use for params i.e, params[:session][email].
2)Where is it documented in Devise gem docs?
Can anyone please help me with this issue ?
Thanks in advance !!!!Sorry for silly doubt!

LDAP Authentication with Refinery CMS

I'm attempting to use devise_ldap_authenticatable with Refinery CMS. I've overriden Refinery's user model and changed its call to devise, and added in a devise initializer to configure it.
The path to my LDAP config is correct in the initizlier, but I don't think it's being utilized. I get a Sorry, your login or password was incorrect. error whether the config is there or not.
I'm not sure what else do at this point. I have a simple devise app with devise_ldap_authenticatable that I'm able to authenticate with. I just can't seem to get it work with the Refinery app.

Ruby on Rails User Login Event

I'm using devise for user authentication. I would like to create a component to be able to respond to a user logging in. Does devise have user events or something similar?
You can check out the pages here: Devise Wiki Pages. You can do things like redirect to certain pages. Additionally, when someone is logged in, so you can always check the current_user method provided by devise and see if it returns nil or a user.
Specifically look at redirecting on signin/signout. You can redirect to a controller action that does what you want.

Devise with user logged in using multiple scopes logs all but one out when using token_authenticateable

I'm using Devise with multiple scopes (in this case, a user scope and an admin scope) and admins are able to 'become' a user using the approach on the Devise wiki. This works well, except that I have one particular page that requires the use of an auth token that causes a problem with a session logged in under both a user and admin scope. The page generates a POST to a controller that requires a user to be logged in using the user auth token. The POST succeeds, but afterwards, the admin scope has been signed out. (Meaning that admin_signed_in? returns false.) Other pages that execute POSTs to the same controller without requiring the auth token work as expected without logging out the admin scope.
I suspect that something is going on with token_authenticatable where the authentication of any scopes other than the one associated with that specific token are logged out. I've searched for references in the devise gem source to both the devise sign_out and warden logout methods that could be invoked as part of the token_authenticatable functionality and wasn't able to find anything.
This is happening with Devise 1.3.4. Any help is appreciated.
In case anyone else is looking for a solution to this, I found that the before_filter/after_filter approach I described in the comment to my question seems to work fine. I think that a better, more general solution to this would be to make a change to the devise gem and underlying calls to warden, but didn't have time to make those changes for this particular problem yet.

How to make Rails devise post to the return_to path, not redirect to it?

I'm using devise on rails 2.3 and need to have a form that is available both public and private - for logged in users and those who are not logged in. Both users should see it, but only logged in users can post the form.
I would like to achieve that when an anonymous user has filled it and posts the form, then devise shows him the login page, he logs in and the contents of the form are posted.
Right now when I make the create action (to which the form posts itself) private, then devise would show him the login screen and remember where he came from - save the url to
session[:return_to] and it redirects him back to the form.
Is there some other way than monkeypatching devise to do that?
I believe that Devise you will not be able to get Devise to post to a location on a successful login without some hacking of Devise.
However, since you are saving the url in the session, you could easily also save the post data in the session as well, then just check for it when you are redirected back. Also make sure that you delete it from the session once it has been used.

Resources