acts_as_tokenable 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f02687548612702d1f8d208d022e65d206cce53
|
4
|
+
data.tar.gz: 11087874d00ba02d0cfb5615ef7ea51ca608fb28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 :
|
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
|
27
|
-
|
28
|
-
self.token_hash = BCrypt::Password.create(
|
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 :
|
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
|
-
|
15
|
+
token_record = ActsAsTokenable::Token.active.find_by(:token_id => token_id)
|
16
16
|
|
17
|
-
return nil unless
|
17
|
+
return nil unless token_record
|
18
18
|
|
19
|
-
if
|
20
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2015-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|