Last time, on “Dr Nic loves OpenID”…
Dr Nic decided that each User might like to link multiple OpenIDs to their application account.
Of course, if a user wanted multiple accounts then they could use their different OpenIDs to do that too.
All Dr Nic had to do now, was write some code…
In the mean-whilst…
It’s a many-to-one relationship (each user can have multiple OpenIDs attached to their account,
but a given OpenID can only be claimed by a single user)
“Champion!” Exclaims Dr Nic in the seclusion of his
underground lair 300m isolated tower kitchen.
This article also lays out an implementation plan. It is in excruciating detail, including table schemas, stylesheet snippets and form suggestions.
Dr Nic rubbed his hands together and gets busy…
[/end of 3rd person]
As a developer, the only reason you wouldn’t want to support “multiple OpenIDs per User” is because it is a PITA to implement, in that its an administrative bonus feature for your app. Its not really adding any real uber value.
Now you can add multiple OpenIDs per user and be lazy at the same time.
NOTE: The code is built for Rails Edge, but the two bundles do not include rails edge, so you need to
rake rails:freeze:edge after unpacking it (all this and more in the README). If you want to work with Rails 1.2.3 gems, then.. um, I didn’t write a list of changes, but it might still work, I haven’t tested it. Ben’s original app was built for 1.2.3, so at its very heart it should still work. Perhaps.
Deviations from the Joesph’s tutorial
I want my users to be able to throw their OpenID around on any old page where they see an OpenID field.
That is, allow users to login or register with OpenID from either the “login” form or the “registration/signup” form. Within Rails, these are traditionally two separate controllers (
So, I extracted out this functionality in to a module (helper
user_openids_helper) and its used by the two controllers.
How’s it work?
Same way that Ben’s sample app worked, more or less, so read his article a couple times, then read through the source code for the multi-OpenID sample app.
I guess a couple tourist highlights might be:
app/helpers/user_openids_helper.rb– the extract fancy code
config/routes.rb– we need more routes to support alternate callbacks from OpenID providers
users_controller.rb– they are emptier and cleaner now
test\functionals\sessions_controller.rb– at the bottom are some test cases for the login/registration features of
So, grab your Code Camera…
- Instant new Rails applications with the App Scrolls When I start a new project I want to start...
- Using CoffeeScript in Rails and even on Heroku I’m pretty excited about CoffeeScript as a clean-syntax replacement for...
- First look at rails 3.0.pre This article is out of date in some aspects....
- Rails themes can remember things I was getting annoyed at having to remember all the...
- Install any HTML theme/template into your Rails app Have you ever even bothered to Google for “rails...