Skip to content

Instantly share code, notes, and snippets.

@juandefelix
Last active January 24, 2016 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juandefelix/1667da9b2c9fb53ca1a4 to your computer and use it in GitHub Desktop.
Save juandefelix/1667da9b2c9fb53ca1a4 to your computer and use it in GitHub Desktop.
Devise email confirmation token generation

Mecanismo usado por Devise identificar un usuario por medio de un token para confirmar el email: Siguiendo este issue, vemos cómo podemos generar un token para la transacción. El código

Devise.token_generator.generate(class, column)

genera un token encriptado único para una instancia de la clase class y devuelve el token encriptado y sin encriptar. El token sin encriptar se envía en el link del email. Al acceder a este link, Devise comprobará qué instancia de Order contiene un token encriptado correspondiente al token del link así:

  def generate_confirmation_token
    raw, enc = Devise.token_generator.generate(self.class, :confirmation_token)
    @raw_confirmation_token   = raw
    self.confirmation_token   = enc
    self.confirmation_sent_at = Time.now.utc
  end

Más información en el modulo en Devise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment