Redirect to different pages after login
The problem
Here's a common use case for which I can't find an elegant solution :
On each page of my application, there is a small login form. Once the person is logged in, I want to redirect him to the page he logged from.
Existing solution
I have found two solutions :
- Having a view that registers the page to which the user is to be redirected (redirect_to) into the session, depending on the referer. This view then redirect to the velruse view.
- Having a view that registers redirect_to into the sessions, then call directly the code of velruse's views (something like
return request.registry.velruse_providers['github'].login(request)).
Both solutions fell ugly because I have add another view to my application. In the first case /mylogin/{provider} redirects to /login/{provider}. In the second case, /login/{provider} is just plain ignored.
Proposed solution
One solution that seems clean would be to give the possibility to add callbacks or hooks to be called at the beginning of the login views. This would enable one to do any required work and information storage before the login process.
Those hooks would have the ability provide extra data that would be stored in the session during the authentication, then returned as part of AuthenticationComplete, or in the store in the case of the standalone application.
A hook providing simple referer storage would be provided.
Please tell me if you think that solution is ok. If you agree, or if you think code will explain much better than this unclear wall of text, I'll code this.