Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise, requiring user to accept terms of service?

I want to mandate that all users accept terms of service, much like is described here:

Ruby on Rails / Devise - Bypassing custom validation option in model when resetting password

However there are 2 requirements that make the above approach not fit.

1) Users are not self registered, rather they are created by a system administrator. The administrator obviously can't accept terms and conditions on the users behalf. The user should be prompted to accept terms and conditions on their first login.

2) If the terms and conditions change after the fact. Users need to re-accept the new terms on subsequent logins.

These seem like pretty standard workflows. Does devise provide any way to accomplish this?

If not, I am thinking this check will need to be implemented in a before_filter on my application controller. (Feels dirty mixing authentication with the application logic...)

Will I have to resort to this or can anyone suggest a better way?

Thanks

like image 736
Chris Avatar asked May 08 '12 13:05

Chris


People also ask

What is Rails devise?

Devise is an excellent authentication system made for Rails that allows us to easily drop-in User functionality into our project. Devise only includes an email and password for registration, let's also add our own username to our User model. We also want to have a unique index on our username.


1 Answers

this is not something devise would handle and devise should not handle this because a TOS does not pertain to authentication.

What you could do is something like implement a state machine but that may be more complex than what you need.

The simple way would be to add a accepted_tos boolean field to your user model and tie that into a before_filter then you would set the accepted_tos to false everytime the TOS is updated.

like image 154
Mike Avatar answered Nov 05 '22 05:11

Mike