Alex
Alex

Reputation: 419

Setting up a beta sign up with Devise

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?

Upvotes: 8

Views: 2947

Answers (1)

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

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

Upvotes: 11

Related Questions