Skip to content

Commit f564e96

Browse files
committed
Switched to using has_secure_token for user authenication tokens
1 parent 77653ae commit f564e96

File tree

4 files changed

+7
-17
lines changed

4 files changed

+7
-17
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ gem 'devise'
1919
gem 'simple_token_authentication', '~> 1.0'
2020
gem 'cancancan'
2121
gem 'stripe', '1.20.1'
22+
gem 'has_secure_token'
2223

2324
group :development, :test do
2425
gem 'pry-rails'

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ GEM
7272
railties (>= 3.0.0)
7373
globalid (0.3.5)
7474
activesupport (>= 4.1.0)
75+
has_secure_token (1.0.0)
76+
activerecord (>= 3.0)
7577
hashie (3.4.1)
7678
http-cookie (1.0.2)
7779
domain_name (~> 0.5)
@@ -199,6 +201,7 @@ DEPENDENCIES
199201
devise
200202
dotenv-rails
201203
factory_girl_rails
204+
has_secure_token
202205
hashie
203206
pg
204207
pry

app/models/team.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ class Team < ActiveRecord::Base
1313
delegate :name, to: :plan, prefix: true
1414
delegate :slug, to: :plan, prefix: true
1515

16-
end
16+
end

app/models/user.rb

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
class User < ActiveRecord::Base
2+
has_secure_token :authentication_token
23
acts_as_token_authenticatable
3-
4+
45
# Include default devise modules. Others available are:
56
# :confirmable, :lockable, :timeoutable and :omniauthable
67
devise :database_authenticatable, :registerable,
78
:recoverable, :trackable, :validatable
89

9-
before_save :ensure_authentication_token
10-
1110
has_many :team_memberships
1211
has_many :teams, through: :team_memberships
13-
14-
def ensure_authentication_token
15-
if authentication_token.blank?
16-
self.authentication_token = generate_authentication_token
17-
end
18-
end
19-
20-
private
21-
22-
def generate_authentication_token
23-
Devise.friendly_token
24-
end
25-
2612
end

0 commit comments

Comments
 (0)