Created
July 22, 2016 20:55
-
-
Save mecampbellsoup/58d093e46224a331348e91c64e77e009 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 User < ApplicationRecord | |
| validates :name, :email, presence: true | |
| has_one :current_auth_token, class_name: AuthToken | |
| #has_many :auth_tokens | |
| has_many :sessions | |
| has_many :credentials, through: :sessions | |
| has_many :application_users | |
| has_many :applications, through: :application_users | |
| def included_relationships | |
| rels = [] | |
| rels << 'sessions' if sessions.present? | |
| rels << 'credentials' if credentials.present? | |
| rels | |
| end | |
| def authenticate!(token_string) | |
| authenticate(token_string) || | |
| raise(UsersApi::Exception::InvalidCredentials) | |
| end | |
| private | |
| def authenticate(token_string) | |
| return if auth_token.blank? || auth_token.used_at.present? | |
| ActiveSupport::SecurityUtils. | |
| secure_compare(auth_token.value, token_string) ? self : false | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment