ruby on rails - Devise confirmation token invalid -


my problem unrelated transition devise 3.1+, use @token variable in email view.

the problem is, confirmation token sent via email not one. if try on console

u = user.last.send_confirmation_instructions the_token_from_the_email = xxx #a copy paste email token_digest = devise.token_generator.digest(user, :confirmation_token, the_token_from_the_email) u.confirmation_token == token_digest # false 

it fails... idea might cause this?

the token in email looks 3d7vdawayshxkmm6ys-mhb token in db/after digest looks 6e8d045e084910d0cfb67b73679da12981221f52eeb984776f969f3c2d475937

edit :

here's what's happening

  1. user clicks on sign_up, enter login
  2. we check login against distant ldap, if find him, entry on distant ldap duplicated our ldap if doesn't exist (no db query), , send him email new password
  3. then, account user created on rails database if doesn't exist already, following commands issued (note user has_many :clients , check client models in confirmation_required?

    moped: 127.0.0.1:27017 query        database=intranet_rails_development collection=users selector={"confirmation_token"=>"iocin4pmf4ipddffdx3p2q=="} flags=[] limit=-1 skip=0 batch_size=nil fields={:_id=>1} runtime: 0.5599ms moped: 127.0.0.1:27017 query        database=intranet_rails_development collection=users selector={"confirmation_token"=>"iocin4pmf4ipddffdx3p2q=="} flags=[] limit=-1 skip=0 batch_size=nil fields={:_id=>1} runtime: 0.3061ms moped: 127.0.0.1:27017 command      database=intranet_rails_development command={:count=>"clients", :query=>{"user_id"=>bson::objectid('55744fd46a65004c95000000')}} runtime: 0.3512ms moped: 127.0.0.1:27017 query        database=intranet_rails_development collection=users selector={"$query"=>{"confirmation_token"=>"b3606f731762a75314f52467993c09fdcd99124ca6357fca6b52a694f159cd9b"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.4727ms moped: 127.0.0.1:27017 insert       database=intranet_rails_development collection=users documents=[{"_id"=>bson::objectid('55744fd46a65004c95000000'), "confirmation_token"=>"b3606f731762a75314f52467993c09fdcd99124ca6357fca6b52a694f159cd9b", "ldap_groups_cache"=>["intervenants"], "last_ldap_groups_check"=>2015-06-07 14:06:12 utc, "gender_cd"=>0, "login"=>"tarasiuk", "from_tpt_ldap"=>false, "tpt"=>false, "superadmin"=>false, "first_name"=>"orest", "last_name"=>"somename", "email"=>"blblabla@domain.fr", "updated_at"=>2015-06-07 14:06:12 utc, "created_at"=>2015-06-07 14:06:12 utc, "confirmation_sent_at"=>2015-06-07 14:06:13 utc}] flags=[]                      command      database=intranet_rails_development command={:getlasterror=>1, :w=>1} runtime: 0.5337ms moped: 127.0.0.1:27017 command      database=intranet_rails_development command={:count=>"clients", :query=>{"user_id"=>bson::objectid('55744fd46a65004c95000000')}} runtime: 0.3471ms rendered devise/mailer/confirmation_instructions.html.erb (1.3ms) 
  4. then confiration email sent token confirmation_token=3dhjtj34o1xkel-efn8b4j"

  5. then final query

    moped: 127.0.0.1:27017 query        database=intranet_rails_development collection=clients selector={"user_id"=>bson::objectid('55744fd46a65004c95000000')} flags=[] limit=0 skip=0 batch_size=nil fields=nil runtime: 0.6091ms redirected [address] completed 302 found in 2522ms 
  6. then confirmation token

    started "/users/confirmation?confirmation_token=3dhjtj34o1xkel-efn8b4j" 46.193.138.19 @ 2015-06-07 16:22:53 +0200 processing confirmationscontroller#show html   parameters: {"confirmation_token"=>"3dhjtj34o1xkel-efn8b4j"}   moped: 127.0.0.1:27017 command      database=admin command={:ismaster=>1} runtime: 0.5095ms   moped: 127.0.0.1:27017 query        database=intranet_rails_development collection=users selector={"$query"=>{"confirmation_token"=>"31cd2ab688b1fd94e6327856603b68873eff7031acc69137cc7d4a527360856b"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.4650ms 

ok, turns out had default value confirmation token screwed up

field :confirmation_token, default: securerandom.base64

then after couple errors (including bug introduced in devise 3.5.1), able make work correctly


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -