rsvp 0.1.5 → 0.2.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,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODU3YTY1Y2UwZmVjZTllMjJiNzI2ZWE2ZDQyYzNhZTAyMjE3NjM0OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGRhMjNmNTZmZjRiZWExNjczY2FkODA3NjQwNTBkYzQxNjg3YzgwNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzA5ZTdhZGI3Y2VjZmFmMDJhYTFlYmZhM2Y1OTA0NWYyMGQzZWQwMjJiMWQ4
|
10
|
+
NWViMmE3OTM2MGM4ZmNmNzA0YjUxMjgzYWY5MTMwZDU3MDIxNmUyZGVhNGJj
|
11
|
+
N2RkYjA1NDE3ZDQ4NjMzNThiOGE2MDY2YzFmNjFhYWQ5ZTcwOWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTA0NzlhZmZhZDk1MDE2ZWY1YWIyOWE5MWQzNTMxY2MyZDk1ZDQ2YTZhNTA3
|
14
|
+
ZjUyYjIxYTg0MjBiOWEwM2U1MjdlOTI1MWFhZmE2MDVlNzZkYWY3OTU2ZDg5
|
15
|
+
ZjViZGUxZGU4NmZhMTllMzFiMWY4YjcwZmEwNzA3YmE1Mzg5Nzk=
|
@@ -34,12 +34,11 @@ module Rsvp
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def get_access_attempt
|
37
|
-
@access_attempt ||= AccessAttempt.
|
37
|
+
@access_attempt ||= AccessAttempt.find_or_create_by(remote_ip: request.remote_ip)
|
38
38
|
end
|
39
39
|
|
40
40
|
def record_failed_access_attempt
|
41
41
|
@access_attempt.record_attempt
|
42
|
-
@access_attempt.save
|
43
42
|
end
|
44
43
|
|
45
44
|
def redirect_locked
|
@@ -1,50 +1,39 @@
|
|
1
1
|
module Rsvp
|
2
2
|
class AccessAttempt < ActiveRecord::Base
|
3
|
-
attr_accessible :
|
3
|
+
attr_accessible :remote_ip
|
4
4
|
|
5
|
-
ALLOWED_ATTEMPTS =
|
5
|
+
ALLOWED_ATTEMPTS = 7
|
6
6
|
LOCK_DURATION = 15
|
7
7
|
|
8
|
-
def allowed_attempts
|
9
|
-
ALLOWED_ATTEMPTS
|
10
|
-
end
|
11
|
-
|
12
|
-
def lock_duration
|
13
|
-
LOCK_DURATION
|
14
|
-
end
|
15
|
-
|
16
|
-
def multiplier
|
17
|
-
locks_incurred + 1
|
18
|
-
end
|
19
|
-
|
20
|
-
def multiplied_allowed_attempts
|
21
|
-
allowed_attempts * multiplier
|
22
|
-
end
|
23
|
-
|
24
|
-
def multiplied_lock_duration
|
25
|
-
(lock_duration * multiplier).minutes
|
26
|
-
end
|
27
|
-
|
28
8
|
def record_attempt
|
29
|
-
|
30
|
-
if failed_attempts >=
|
31
|
-
self.
|
32
|
-
|
9
|
+
self.failed_attempts += 1
|
10
|
+
if failed_attempts >= allowed_attempts
|
11
|
+
self.locked_until = Time.now + lock_duration
|
12
|
+
self.locks_incurred += 1
|
33
13
|
end
|
14
|
+
self.save
|
34
15
|
end
|
35
16
|
|
36
17
|
def locked?
|
37
|
-
unless
|
38
|
-
return
|
18
|
+
unless locked_until.nil?
|
19
|
+
return locked_until >= Time.now
|
39
20
|
else
|
40
21
|
return false
|
41
22
|
end
|
42
23
|
end
|
43
24
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
25
|
+
def allowed_attempts
|
26
|
+
ALLOWED_ATTEMPTS * multiplier
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def multiplier
|
32
|
+
locks_incurred + 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def lock_duration
|
36
|
+
(LOCK_DURATION * (multiplier**3)).minutes
|
48
37
|
end
|
49
38
|
end
|
50
39
|
end
|
@@ -3,7 +3,7 @@ class CreateRsvpAccessAttempts < ActiveRecord::Migration
|
|
3
3
|
create_table :rsvp_access_attempts do |t|
|
4
4
|
t.string :remote_ip
|
5
5
|
t.integer :failed_attempts, default: 0
|
6
|
-
t.datetime :
|
6
|
+
t.datetime :locked_until
|
7
7
|
t.integer :locks_incurred, default: 0
|
8
8
|
t.timestamps
|
9
9
|
end
|
data/lib/rsvp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsvp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Ricard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|