views:

123

answers:

7

I'm building my first website with rails,it consists of a blog, a few static pages and a photo gallery. The admin section has namespaced controllers. I also want to create a mailing list, collecting contact info, (maybe a spree store in the future too.)

Should I just use basic http authentication and check if the user is admin? Or is a plugin like authlogic better, then define user roles even though there would only be two; admin and user?

A: 

You can to do that. Authlogic or Devise made that for you.

shingara
A: 

Really it is just a matter of opinion and you'll have to do what is right for you.

Basically you just need to determine what your authentication(user logins etc.) needs are and your authorization(What a user can do) needs are.

I personally am a big fan of authlogic for authentication and Ryan from railscasts cancan authorization library:

http://github.com/ryanb/cancan

But again, it is really up to you, and if you use git, you can branch your app and try both. :D

Cheers!

Dustin M.
would using cancan mean that I wouldn't have to use a namespaced admin section? but make the views a mess...
juststarting
Well, It does add code to your views if you want admin/only features to show up. The actually follows the DRY conventions by not duplicating your view content for an admin only section..But to answer your question, yes, using cancan would allow you to not have an admin only secton, and yes it will add code to your views.Again it goes back to personal preference, if your views are basically the same, but with added features for admins, this works well. If not, then perhaps creating a whole different namespace for admins is better. Cheers!
Dustin M.
A: 

Remember that you'd have to use HTTPS for the username/password to be encrypted when traveling over the wire.

Probably not a concern but something to be aware of.

frou
well you don't _have_ to use https if you want that, but it's best if you do. You could also use javascript if you really want.
Cam
@incrediman I meant if using the basic type of auth that pops up the browser specific username/password modal dialog. That's the case, right?
frou
Ah. Yes, that's correct of course :)
Cam
A: 

Use rpxnow.com. Integrate with them once, and it will let users from Google, Yahoo, Microsoft, Facebook, etc log into your site.

The process is fairly simple:

  1. Stick their javascript code on your login page.
  2. Write a controller which RPXnow calls with a token for the authentication callback. This routine parses out the token, and makes a secure web call to rpxnow.com to get data about the user. Grab the email address, which is then authentic.
  3. Since you now have an authentic email address, the user can be granted access to the inner part of your site.

If you use RPX for authentication, you don't have to write a "forgot my password" feature, or a "signup" feature with email confirmation. The identity provider does this.

Stackoverflow.com uses a similar scheme for authentication.

(This is based on the assumption that 99% of internet users have one of Google, Yahoo, Hotmail/Live, or Facebook).

Jay Godse
A: 

To answer your comment to dustmoo: If adding authorization rules to your application "makes the views a mess" then you are not using authorization the right way. Which is, being declarative.

declarative_authorization will allow you to "separate" authorization concerns from your application.

There's also cancan, which is a little easier to set up, but has less functionality (you loose Model.with_permissions_to).

egarcia
A: 

I also vote for authlogic + cancan.

The tutorial from Ryan are simple enough to follow which takes a few hours to set up the whole thing (even for newbies).

If you try to build your own authentication model (and I assume you do not have a lot of experience), the time spent in (re-)doing the whole thing (again and again) well justify the time spent to learn from the pros.

my 0.02

ohho
A: 

Definitely a subjective question and many correct answers. I wrote a blog post that should get you up and running with Devise for auth and CanCan for roles in about 30 minutes. Hope this helps: http://www.tonyamoyal.com/2010/07/28/rails-authentication-with-devise-and-cancan-customizing-devise-controllers/

Tony