Devise common login page for login and register - ruby-on-rails

I'm trying to have a login and register form on one page with devise. But how can I redirect back to the common page when there is an unsuccessful try to login or register? It i being redirected to the appropriate login or register specific page.
Thanks

Related

Revisiting index page after login

I am new so please be willing to lend me a hand.
I am into a web application that a user needs to enter his credentials in a form set for the login page (index.aspx).
After he signs on, he'll be redirected to a content page (content-page-for-user-x.aspx).
He does open many more subpages and finally enters "index.aspx" in the browser to get back the index page.
What should I do to prevent the index.aspx (login form page) from showing up again? Because he is already in, not new at all. The index page now should be content-page-for-user-x.aspx.
In backend logic of login page index.aspx, you could check if user has already logged in.
If user has already logged in, just redirect user to content-page-for-user-x.aspx should be fine. If user not logged in, display your login page (index.aspx) to prompt user to login.

How to authenticate the user from the email?

I have a rails application which uses devise for authentication. when the application sends any notification to the user, then in order to see the notification or messages i provide a link to my rails application which redirects to a login page.
how can i avoid this login process, means i don't want the user to be asked to login by entering email and password, instead whenever the user clicks on that link, then the user should automatically login.
Devise provides sign_in controller helper which allows you to pass authentication programmatically.
sign_in(user)

Go back to the requested URL in Spring security

In Grails 2.5.1 application i'm using Spring security core plugin 2.0-RC5 , i would like to return back to the requested URL, for instance to access page payOnline you need to be logged in first so i redirect to the login page after the successful login i want to go to payOnline.
How this could be achieved?
To access page payOnline you need to be logged in first so i redirect to the login page after the successful login i want to go to payOnline.
1. Go to Requested page :
By default spring security stores the request url you want to access before you are redirected to the login page. After you logged in successfully you are then redirected to the page you wanted.
E.g.
User trying to access `/payOnline`
If user is not logged in redirect user to `login` page
user successfully logged in redirect to `/payOnline`
What you are asking is the default behavior of spring security core plugin.
If its not working as expected then please check if you have successHandler.alwaysUseDefault config property present in your config.groovy. If yes then remove it.
2 . Got to specific page always :
If you want to go to specific page always after login then you you can specify the controller action to which you want to go in UrlMappings.groovy pretty easily.
Just specify the controller and action to which you want to got after login like below
Lets suppose Provision Controller and payOnline action.
"/"(controller: "provision", action: "payOnline")
This will redirect all the successful login users to payOnline page.
Reference :
http://docs.grails.org/2.5.1/guide/theWebLayer.html#urlmappings

ActionController::InvalidAuthenticityToken when login using two devise model (user and admin)

I create an app using two devise model, user and admin.
I'm following the devise wiki from this link, I'm using the option 1
How To: Add an Admin Role
So I open two page at the same time, the user login page and the admin login page.
When I login in the admin login page it succeed but when I login on the user page it raise an error ActionController::InvalidAuthenticityToken same goes with the other way.
But if I refresh the page first then I login it will succeed.
Are they using the same AuthenticityToken? So when the admin logged in, the AuthenticityToken is changed so when I try to login with the user it raise an InvalidAuthenticityToken?
Thanks.
The behaviour you are seeing is expected.This is because the value of csrf token changes once you sign in,expiring the old value.
There is a workaround to disable CSRF protection for the sign_in action in the ApplicationController. Look here: https://github.com/plataformatec/devise/issues/3102

Rails: redirect back to previous page after sign in / sign up

I am using Rails and devise for user authentication, I don’t know how to redirect the user back to the previous page after successful sign in/sign up.
I know about after_sign_in_path_for, but I don’t know what I should write inside.
You can write custom sessions controller for devise login and use request.referrer to get the URL of the page the user is coming from. Then just redirect back to the previous page after login. Also refer this doc. You could go by one of the methods. Hope it helps.

Resources