travis-api/lib/travis/model/token.rb
Aakriti Gupta 65f1a29d86 Move travis-core files from /vendor to /lib.
- Re-factor
- Remove code for notifications
- Remove addons
- Remove travis-core gem.
- Ignore logs directory only
- Move core tests to spec/lib
2016-07-20 11:22:25 +02:00

26 lines
688 B
Ruby

require 'securerandom'
require 'travis/model'
# Tokens used for authenticating requests from Github.
#
# Users can have one or many tokens (even though the current UI only allows for
# one) that they need use on their service hooks. This gives us some security
# that people cannot throw random repositories at Travis CI.
class Token < Travis::Model
belongs_to :user
validate :token, :presence => true
before_validation :generate_token, on: :create
attr_accessible # nothing is changable
serialize :token, Travis::Model::EncryptedColumn.new(disable: true)
protected
def generate_token
self.token = SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz')
end
end