I have recently integrated the Devise authentication system into a rails test app. The test app simply contains a projects model/controller/view that sits behind the authentication.
I am now adding a beta invite system, so that only users who have received an invite from another user can join the site. I was implementing this system through the following: http://railscasts.com/episodes/124-beta-invitations.
The one problem I am having is that the beta invite requires me to add some logic to the user controller, which you cannot do through Devise. I am trying to create a new registrations controller using Users::RegistrationsController < Devise::RegistrationsController that will basically be the same as the Devise controller but allow me to add in some additional logic for the beta invite system.
I, however, cannot get this new controller to work (and I am also having trouble as to what I should include in this new controller). I have added the following to my routes file:
resources :registrations
resources :invitations
resources :projects
devise_for :users
devise_scope :user do
get 'users/sign_up/:invitation_token' => 'registrations#new'
end
What do I put in this new registrations controller to mimic the functionality of the original devise/registrations controller?
Devise is the cornerstone gem for Ruby on Rails authentication. With Devise, creating a User that can log in and out of your application is so simple because Devise takes care of all the controllers necessary for user creation ( users_controller ) and for user sessions ( users_sessions_controller ).
In your user model, add a validation where you check that the user's email is in a beta invite list.
This SO is very similar: Whitelisting with devise ... I added similar code there, it's relevant here:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable #etc
before_validation :beta_invited?
def beta_invited?
unless BetaInvite.exists?(:email=>email)
errors.add :email, "is not on our beta list"
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With