Last active
          May 13, 2016 11:12 
        
      - 
      
- 
        Save 1syo/46e5f9365a39a51804f7dcc5bb4bd4e9 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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