Best practices for letting users sign up AFTER using the site for a bit

79 views
Skip to first unread message

Erik Pukinskis

unread,
Apr 1, 2010, 3:03:51 AM4/1/10
to Authlogic
Hi there,

I've been wrestling with this a big, and I haven't found the solution
that feels *right* yet. This must be a common need, so I figured I'd
write the list.

On my site I let users start using the site, and creating personalized
stuff before actually formally "signing up". Which means I'm
attaching user data to a User model, before I've even gotten their
username and password. Then, if they choose to, they can sign up.

The trouble this causes is that Authlogic seems to expect that you
decide on your username/password validations at the class level, but I
really want to decide at the instance level. Basically I want to be
able to do this:

u = User.new
u.should be_valid

u.activate
u.should_not be_valid

u.update_attributes(:login => "erik", :password => "lalala")
u.should be_valid

Unfortunately, there doesn't seem to be a way to do this in Authlogic,
because it requires changing the configuration at the instance level,
rather than the class level.

I'm considering using single table inheritance, and having a
ProspectiveUser class with a different set of validations, but I tried
it before and it was a bit of a mess. Anyone have any suggestions?

-Erik

Mopac Media

unread,
Apr 1, 2010, 9:52:04 AM4/1/10
to auth...@googlegroups.com
Hi Erik,

Search the google group for the keywords "gradual engagement" -- I have this same requirement for my site and came up with "a" solution. I'm sure there are other solutions but maybe that one will work for you or provide a starting point.

Kevin

> --
> You received this message because you are subscribed to the Google Groups "Authlogic" group.
> To post to this group, send email to auth...@googlegroups.com.
> To unsubscribe from this group, send email to authlogic+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/authlogic?hl=en.
>

Erik Pukinskis

unread,
Apr 2, 2010, 4:07:41 PM4/2/10
to Authlogic
Kevin,

Ah, "gradual engagement" is the magic incantation. :)

Thanks for the tip. But I tried using the conditionals
(c.validate_login_field = {:if => :active?}) and it still didn't
work. Here's a barebones test case that fails:

http://gist.github.com/353636

(running spec -c gradual_engagement_spec.rb should work without any
dependencies.)

Any ideas what I'm doing wrong?

Best,
Erik

Erik Pukinskis

unread,
Apr 2, 2010, 4:48:13 PM4/2/10
to Authlogic
Well that spec I posted is a little messed up. I've already spent way
to much time on this, so I just decided to not use the authlogic
validations, since they weren't cooperating. I'm just disabling them
and using the standard activerecord ones:

class User < ActiveRecord::Base
validates_uniqueness_of :login, :if => :active?
validates_format_of :login, :with => Authlogic::Regex.login, :if
=> :active?
validates_uniqueness_of :email, :if => :active?
validates_format_of :email, :with => Authlogic::Regex.email, :if
=> :active?
validates_presence_of :password, :if => :active?
validates_length_of :password, :minimum => 3, :if => :active?

acts_as_authentic do |c|
c.validate_login_field = false
c.validate_password_field = false
c.validate_email_field = false
end
end

Oh well.

Erik

Mopac Media

unread,
Apr 2, 2010, 4:53:43 PM4/2/10
to auth...@googlegroups.com
Hi Erik,

Heh, yeah, gradual engagement is the magic incarnation, ha.

If you come across this again, here's the gist I created. It shows how to use the conditionals:


I use :unless instead of :if because authlogic uses :if in places and the merge would overwrite the authlogic conditional :if tests.

Kevin

Erik Pukinskis

unread,
Apr 5, 2010, 2:31:34 PM4/5/10
to Authlogic
Ah, the :unless instead of :if got it working. Great, thank you!
Reply all
Reply to author
Forward
0 new messages