2011-03-02 2 views
7

devils를 사용하여 레일 앱에서 사용자 인증을 관리하고 있습니다. Devise는 정말 좋습니다.devit 허용 목록

그러나 신청할 때 특별한 요구 사항이 있습니다. 사용자가 사용자로 등록하려면 먼저 허용 목록에 있어야합니다.

허용 된 이메일 목록을 만드는 관리자가 있습니다. 사용자는 전자 메일을 등록하고 전자 메일이 화이트리스트 테이블에 있으면 등록됩니다. 그러나 메일이 허용 목록에 없으면 "아직 초대되지 않았습니다."와 같은 메시지로 등록을 중단해야합니다.

어떻게 해결할 수 있을지 알고 있습니까?

미리 감사드립니다.

답변

6

당신이 당신의 자신의 등록 컨트롤러를 만들고 같은 장치를 하나씩 확장되어 수행 할 수 있습니다

class MyRegistrationController < Devise::RegistrationsController 
    def create 
    # do your checks 
    super 
    end 
end 

참조 : https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb 그리고 : https://github.com/plataformatec/devise/wiki/How-to:-Customize-routes-to-user-registration-pages

행운을 빕니다!

15

모델 유효성 검사 만 사용합니다. 내가 app/users/registrations_controller.rb에 배치

class Users::RegistrationsController < Devise::RegistrationsController 
    def create 
     email = params[:user][:email] 
     if Admin::Whitelist.find_by_email(email) != nil 
      super 
     else 
      build_resource 

      set_flash_message :error, "You are not permitted to sign up yet. If you have already payed your registration fee, try again later." 
      render_with_scope :new 
     end 
    end 
end 

: 나는 당신의 사용자 클래스를 가정하고있어 제안 난 내 자신의 컨트롤러를 생성했던 유증 방법

class User < ActiveRecord::Base 
    devise :database_authenticatable, :registerable #etc 

    before_validation :whitelisted 

    def whitelisted 
    unless celebrityemail.include? email 
     errors.add :email, "#{email} is not on our invitation list" 
    end 
    end 

end 
+0

오류의 MSG의 실제 이메일을 표시하려면, 당신은 어떻게이 코드를 변경할 것인가? – Magne

+0

@Magne'errors.add : email, "은 우리의 초대 목록에 없습니다 : # {email}"' –

2

에게 있습니다. 그런 다음 기본보기가 사용되지 않았기 때문에 장치 등록보기를 app/views/users/registrations으로 복사해야했습니다.

그것은 지금 노력하고 있습니다

, 덕분에 당신의 도움을

관련 문제