acts_as_tokenable 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ff886775475e5a6aa7a916ebd039015bfd5d06d
4
- data.tar.gz: dd441d8e815f55a4b4e0845b2969c9a108e01e43
3
+ metadata.gz: 2f02687548612702d1f8d208d022e65d206cce53
4
+ data.tar.gz: 11087874d00ba02d0cfb5615ef7ea51ca608fb28
5
5
  SHA512:
6
- metadata.gz: 21b3021fb3d0ac2eabe30498fe25655f72e4bca6a172fe36d8cdafb55ce322d074390083b38627b613088a4e85c85711c88380c65a5d56e4cc449cfdba0b506a
7
- data.tar.gz: 17371a358ade274565b7bee453711107de0331951a92254e9b80febb86fd33d713c4ee225bc5176b38e1df24fac4dd57714ae00f61e035157a547e0ed1ff6442
6
+ metadata.gz: f03ee83b09c7b5b3d6070f75948bddeb4cc8b98a504ffeae4cf12474dadcc0f4b3f8d4475be3f43412aa5c75fbfd7c471d511b49fe1963e61cf960079d77ebfd
7
+ data.tar.gz: 01ec12522e621b7cfde4c68a36178af714c3c352adbaef5205f3a77ecb5b6374677a6a202e31c32231cee647b96fc499cdf34c1b10303002430664baaabf3b09
@@ -3,6 +3,8 @@ require 'bcrypt'
3
3
 
4
4
  module ActsAsTokenable
5
5
  class Token < ActiveRecord::Base
6
+ attr_accessor :token_hash
7
+
6
8
  before_update { false }
7
9
 
8
10
  belongs_to :tokenable, polymorphic: true
@@ -13,19 +15,18 @@ module ActsAsTokenable
13
15
  scope :active, -> { where('expires_at > ?', DateTime.now) }
14
16
 
15
17
  before_validation :generate_token_id
16
- before_validation :generate_token_hash
18
+ before_validation :generate_token
17
19
 
18
20
  private
19
-
20
21
  def generate_token_id
21
22
  begin
22
23
  self.token_id = SecureRandom.hex(16)
23
24
  end while self.class.exists?(token_id: self.token_id)
24
25
  end
25
26
 
26
- def generate_token_hash
27
- secret = SecureRandom.urlsafe_base64(16)
28
- self.token_hash = BCrypt::Password.create(secret, cost: cost)
27
+ def generate_token
28
+ self.token = SecureRandom.urlsafe_base64(32)
29
+ self.token_hash = BCrypt::Password.create(token, cost: cost)
29
30
  end
30
31
 
31
32
  def cost
@@ -3,7 +3,7 @@ class CreateActsAsTokenableTokens < ActiveRecord::Migration
3
3
  create_table :acts_as_tokenable_tokens, :id => false do |t|
4
4
  t.belongs_to :tokenable, polymorphic: true, index: true, index: { name: 'acts_as_tokenable_tokens_polymorphic' }
5
5
  t.string :token_id, unique: true
6
- t.string :token_hash
6
+ t.string :token
7
7
  t.datetime :expires_at
8
8
 
9
9
  t.timestamps null: false
@@ -12,12 +12,12 @@ module ActsAsTokenable
12
12
 
13
13
  class << self
14
14
  def find_by_token(token_id, token_hash)
15
- token = ActsAsTokenable::Token.active.find_by(:token_id => token_id)
15
+ token_record = ActsAsTokenable::Token.active.find_by(:token_id => token_id)
16
16
 
17
- return nil unless token
17
+ return nil unless token_record
18
18
 
19
- if ActiveSupport::SecurityUtils.secure_compare(token.token_hash, token_hash)
20
- token.try(:tokenable)
19
+ if BCrypt::Password.new(token_hash) == token_record.token
20
+ token_record.try(:tokenable)
21
21
  else
22
22
  nil
23
23
  end
@@ -25,7 +25,6 @@ module ActsAsTokenable
25
25
  end
26
26
 
27
27
  private
28
-
29
28
  def default_options
30
29
  {
31
30
  :expires_at => 30.days.from_now
@@ -1,3 +1,3 @@
1
1
  module ActsAsTokenable
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_tokenable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Novikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2015-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails