Skip to content

Instantly share code, notes, and snippets.

@1syo
Last active May 13, 2016 11:12
Show Gist options
  • Save 1syo/46e5f9365a39a51804f7dcc5bb4bd4e9 to your computer and use it in GitHub Desktop.
Save 1syo/46e5f9365a39a51804f7dcc5bb4bd4e9 to your computer and use it in GitHub Desktop.
class Token
include ActiveModel::Model
attr_accessor :email
validate :ensure_effective_token
def initialize(token, email, expire_at)
@token, @email, @expire_at = token, email, expire_at
end
def self.create(token)
verifier = Rails.application.message_verifier(:password_reset).verify(token)
new(token, *verifier)
end
def to_s
@token
end
private
def ensure_effective_token
errors.add :base, 'This token is expired.' unless Time.zone.now < @expire_at
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment