Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 300
Alex Avatar asked Mar 19 '11 00:03

Alex


People also ask

What is gem Devise?

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 ).


1 Answers

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
like image 185
Jesse Wolgamott Avatar answered Oct 18 '22 23:10

Jesse Wolgamott