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 D开发者_高级运维evise. 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?
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
精彩评论