2014-06-24 4 views
0

Devise 3.2.2를 사용 중입니다. 그리고 확인을 켰어.확인 토큰이 잘못되었습니다.

SQL을 사용하면 사용자 테이블에 성공적인 토큰이 만들어 졌음을 알 수 있습니다.

토큰이 생성 된 이메일 링크에 있습니다. 그러나 그것을 클릭하면 Confirmation token is invalid error가 발생합니다. 이미 사용자 이름이나 전자 메일을 사용하여 로그인 할 수 있도록 작업 코드가 있지만 충돌하지 않기를 바랍니다.

ERB :

<p>Welcome <%= @email %>!</p> 

<p>You can confirm your account email through the link below:</p> 

<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p> 

사용자 모델 :

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :confirmable, :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
    :recoverable, :rememberable, :trackable, :validatable, :confirmable 

    # Virtual attribute for authenticating by either username or email 
    # This is in addition to a real persisted field like 'username' 
    attr_accessor :login 

    # Setup accessible (or protected) attributes for your model 
    attr_accessible :email, :password, :password_confirmation, :remember_me, :approved, :role, :username, :userfriendlyname, :persona, :public, :login, :active, :confirmation_token, :confirmed_at, :confirmation_sent_at 
    # attr_accessible :title, :body 



    # MTM 06/21/2014 to allow for login with username or email 
    def self.find_for_database_authentication(warden_conditions) 
    conditions = warden_conditions.dup 
    if login = conditions.delete(:login) 
     where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first 
    else 
     where(conditions).first 
    end 
    end 

    # MTM 06/23/2014 to allow for login with username or email 
    def self.find_first_by_auth_conditions(warden_conditions) 
    conditions = warden_conditions.dup 
    if login = conditions.delete(:login) 
    where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first 
    else 
     where(conditions).first 
    end 
    end 

end 

답변

0

첫째, 그래서 다른 비슷한 질문을 많이 읽어,이 중 하나는 사용자 이후 흐름을 이해 적어도 도움 비슷한 구속을 받았다. Devise Confirmation Resend "Login can't be blank" error & Confirmation link from email has "Confirmation token is invalid" error

하지만 다음 해결 방법이 있습니다. LINK_TO 코드를 변경했다, 그래서 나는 미리 고안의 3.1.X 버전을 사용 할 때

1 단계

confirmation_instructions.html.erb는 원래 만들었습니다. 이것에 많은 기사가 있습니다.

기본적으로 다음과 같이 바꿉니다 : confirmation_token => @ resource.confirmation_token : confirmation_token => @token.

2 단계

이것은 까다로운 부분이었습니다. 이전에 제대로 작동하는 맞춤 메일러를 만들었으므로 Devise 작업을 맞춤 메일러로 복사해야했습니다. 다시 한 번, 이전 버전의 Devise를 사용했기 때문에 @token에 대한 언급이 없었으므로 confirm_instructions 액션/메소드에 @token = 토큰을 추가했습니다. 토큰이이 액션/메서드를 매개 변수로 사용합니다. 그렇게함으로써

def confirmation_instructions(record, token, opts={}) 
    @token = token  
    devise_mail(record, :confirmation_instructions) 
    end 

, 내가 확인 지침 요청의 재전송을 제출로 레일 콘솔을보고, 나는 다른 SO 기사는 전형적인 고안 3.1 이상 행동에 관한 얘기를하고 있었는지 알 수 있었다 confirmation_token이 생성되어 데이터베이스에 저장되지만 암호화 된 버전 인 것처럼 확인 지침 전자 메일과 함께 전송 된 값과 다릅니다. 전자 메일 링크를 클릭하면 로그인 페이지로 이동하여 확인에 성공했다고 말합니다.

-2

이 코드를 코드로 변경하고 확인하십시오.

% 포인트 = LINK_TO '내 계정 확인', confirmation_url (@Resource : confirmation_token => @Resource)

관련 문제