Class: AuthenticationToken

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/authentication_token.rb

Class Method Summary collapse

Class Method Details

.create_token(user) ⇒ Object



14
15
16
17
# File 'app/models/authentication_token.rb', line 14

def create_token(user)
	authentication_token = AuthenticationToken.create!(user_id: user.id, token: generate_token)
	return authentication_token
end

.generate_tokenObject



5
6
7
8
9
10
11
12
# File 'app/models/authentication_token.rb', line 5

def generate_token
  token = loop do
    random_token = SecureRandom.urlsafe_base64(nil, false)
    break random_token unless AuthenticationToken.exists?(token: random_token)
  end

  return token
end