diaspora/app/models/user/authentication_token.rb
Benjamin Neff d421e42ddb
Remove ability to authenticate with auth_token on the frontend
Remove devise-token_authenticatable gem and only generate a token to be
used by the chat.
2016-10-28 00:36:14 +02:00

26 lines
772 B
Ruby

class User
module AuthenticationToken
extend ActiveSupport::Concern
# Generate new authentication token and save the record.
def reset_authentication_token!
self.authentication_token = self.class.authentication_token
save(validate: false)
end
# Generate authentication token unless already exists and save the record.
def ensure_authentication_token!
reset_authentication_token! if authentication_token.blank?
end
module ClassMethods
# Generate a token checking if one does not already exist in the database.
def authentication_token
loop do
token = Devise.friendly_token(30)
break token unless User.exists?(authentication_token: token)
end
end
end
end
end