Thursday, 15 July 2010

ruby on rails - Confirmation token is invalid -



ruby on rails - Confirmation token is invalid -

i using devise 3.2.2. , turned on confirmable.

with sql, shows successful token created in users table.

and token in email link that's generated. clicking on it, gives confirmation token invalid error. having working code allow login using username or email, hope not conflicting.

erb:

<p>welcome <%= @email %>!</p> <p>you can confirm business relationship email through link below:</p> <p><%= link_to 'confirm account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>

user model:

class user < activerecord::base # include default devise modules. others available are: # :confirmable, :lockable, :timeoutable , :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable # virtual attribute authenticating either username or email # in add-on real persisted field 'username' attr_accessor :login # setup accessible (or protected) attributes 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 allow login 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 allow login 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

first, read through lot of other similar questions on so, , 1 helped @ to the lowest degree understand flow, since user in similar bind. devise confirmation resend "login can't blank" error & confirmation link email has "confirmation token invalid" error

but got solution work next things.

step 1.

confirmation_instructions.html.erb created when using pre devise 3.1.x version, link_to code had changed. there many articles in on this.

essentially, replacing :confirmation_token => @resource.confirmation_token :confirmation_token => @token.

step 2.

this tricky part. had created custom mailer before working fine, , there had re-create on devise actions custom mailer. again, maybe because using older version of devise @ time, there no mention of @token in these actions, added @token = token, in confirmation_instructions action/method, since token passed action/method parameter.

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

by doing so, , looking @ rails console submitted resend of confirmation instructions request, see other articles talking regarding typical devise 3.1 , higher behavior, is, confirmation_token created , stored in database, not same value sent confirmation instructions email, seems encrypted version. when click on email link, went login page , said confirmation successful.

ruby-on-rails

No comments:

Post a Comment