rsvp 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/controllers/rsvp/session_controller.rb +19 -0
- data/app/models/rsvp/access_attempt.rb +50 -0
- data/app/models/rsvp/person.rb +12 -0
- data/app/models/rsvp/rsvp.rb +7 -0
- data/app/models/rsvp/salutation/husband_and_wife_with_own_names.rb +13 -0
- data/app/models/rsvp/salutation/husband_wife_and_children.rb +19 -0
- data/app/models/rsvp/salutation/single_female_and_guest.rb +1 -1
- data/app/models/rsvp/salutation/single_male_and_guest.rb +1 -1
- data/app/models/rsvp/salutation.rb +5 -1
- data/db/migrate/20140304015111_create_rsvp_access_attempts.rb +11 -0
- data/lib/rsvp/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Yzc3MTQzNzQ1OWU0MjY1Njc5ZTAyOWI3YWY3Mjc1ZDVlOTE5ZTA4Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjdlMmZkY2JjNWYwNGQ5NjQwNTZjN2QzZDE3MGYyYzZjM2UwYWM2Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmYyNWVmZWY0MmM4Mzk2OWE1Mjc4NDVlZjRhZmNlZjk5MDMzYjA0MmI2YzI3
|
10
|
+
MjQ1OGQ3OGViMjE2YjM1MTMwYTBiY2MxMmZjMzBjZjEyMjc2NDM1YTNjNTdh
|
11
|
+
MjVhMjQxODc5YTVjYWM5ODQ3M2MyYWRhZTIyNDRkNWM3MzhkZGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWY1ODhjNTkzNGFkMDExYTU3NDVmZDNiOTNiYjJhOThiODI4NjA1OGM0NDJl
|
14
|
+
MmI2NzVjMTEzZDhiYzA2NzAxOGI3NWY1MzBkZGQ1YWQ5YjcyNmM1YmI4YzZl
|
15
|
+
ODc3NDE2Nzc5MmJlZjk0NjliOGU5ZDlmNGNlZTk4NjhkM2E0ZDk=
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Rsvp
|
2
2
|
class SessionController < ApplicationController
|
3
3
|
skip_before_filter :require_session, :only => [:index, :create]
|
4
|
+
before_filter :get_access_attempt
|
5
|
+
before_filter :redirect_locked, :only => [:create]
|
4
6
|
|
5
7
|
# GET /session
|
6
8
|
def index; end
|
@@ -12,6 +14,7 @@ module Rsvp
|
|
12
14
|
session[:invitation_id] = invitation.id
|
13
15
|
redirect_to (invitation.responses.any? ? show_response_index_path : response_index_path)
|
14
16
|
else
|
17
|
+
record_failed_access_attempt
|
15
18
|
flash.alert = "Oops!! The code you entered is not valid. Please try again."
|
16
19
|
redirect_to root_path
|
17
20
|
end
|
@@ -29,5 +32,21 @@ module Rsvp
|
|
29
32
|
def redirect_after_destroy
|
30
33
|
redirect_to root_path, notice: "Thank you for your response!"
|
31
34
|
end
|
35
|
+
|
36
|
+
def get_access_attempt
|
37
|
+
@access_attempt ||= AccessAttempt.find_or_create_by_remote_ip(request.remote_ip)
|
38
|
+
end
|
39
|
+
|
40
|
+
def record_failed_access_attempt
|
41
|
+
@access_attempt.record_attempt
|
42
|
+
@access_attempt.save
|
43
|
+
end
|
44
|
+
|
45
|
+
def redirect_locked
|
46
|
+
if @access_attempt.locked?
|
47
|
+
flash[:alert] = "You surpassed the attempt threshold. You may try again on #{@access_attempt.locked_until.strftime('%B %d at %I:%M %p')}."
|
48
|
+
redirect_to root_path
|
49
|
+
end
|
50
|
+
end
|
32
51
|
end
|
33
52
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Rsvp
|
2
|
+
class AccessAttempt < ActiveRecord::Base
|
3
|
+
attr_accessible :locked_at, :locks_incurred
|
4
|
+
|
5
|
+
ALLOWED_ATTEMPTS = 5
|
6
|
+
LOCK_DURATION = 15
|
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
|
+
def record_attempt
|
29
|
+
increment(:failed_attempts)
|
30
|
+
if failed_attempts >= multiplied_allowed_attempts
|
31
|
+
self.locked_at = Time.now
|
32
|
+
increment(:locks_incurred)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def locked?
|
37
|
+
unless locked_at.nil?
|
38
|
+
return (locked_at + multiplied_lock_duration) >= Time.now
|
39
|
+
else
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def locked_until
|
45
|
+
if locked?
|
46
|
+
return locked_at + multiplied_lock_duration
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/app/models/rsvp/person.rb
CHANGED
@@ -17,6 +17,18 @@ module Rsvp
|
|
17
17
|
where("gender_type = ?", Gender::AdultFemale.to_s)
|
18
18
|
end
|
19
19
|
|
20
|
+
def self.young_females
|
21
|
+
where("gender_type = ?", Gender::YoungFemale.to_s)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.young_males
|
25
|
+
where("gender_type = ?", Gender::YoungMale.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.children
|
29
|
+
young_females + young_males
|
30
|
+
end
|
31
|
+
|
20
32
|
def gender_type=(klass)
|
21
33
|
write_attribute(:gender_type, klass.to_s)
|
22
34
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Rsvp
|
2
|
+
class Salutation::HusbandAndWifeWithOwnNames < Salutation
|
3
|
+
def male
|
4
|
+
family.people.adult_males.first
|
5
|
+
end
|
6
|
+
def female
|
7
|
+
family.people.adult_females.first
|
8
|
+
end
|
9
|
+
def template
|
10
|
+
"Mr. [[male__first_name]] [[male__last_name]] and Mrs. [[female__first_name]] [[female__last_name]]"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rsvp
|
2
|
+
class Salutation::HusbandWifeAndChildren < Salutation
|
3
|
+
def male
|
4
|
+
family.people.adult_males.first
|
5
|
+
end
|
6
|
+
def children
|
7
|
+
names = ""
|
8
|
+
children = family.people.children
|
9
|
+
children.each_with_index do |child, index|
|
10
|
+
names << " and" if children.size > 1 && (index + 1) == children.size
|
11
|
+
names << " #{child.first_name}"
|
12
|
+
end
|
13
|
+
names.strip
|
14
|
+
end
|
15
|
+
def template
|
16
|
+
"Mr. and Mrs. [[male__first_name]] [[male__last_name]], [[children]]"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -21,7 +21,11 @@ module Rsvp
|
|
21
21
|
salutation = template
|
22
22
|
template.scan(/\[\[\w*\]\]/).each do |expression|
|
23
23
|
salutation_method, person_method = expression.tr("][", "").split(/__/)
|
24
|
-
|
24
|
+
merge_data = send(salutation_method)
|
25
|
+
unless merge_data.class == String
|
26
|
+
merge_data = merge_data.send(person_method)
|
27
|
+
end
|
28
|
+
salutation.gsub!(expression, merge_data)
|
25
29
|
end
|
26
30
|
salutation
|
27
31
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreateRsvpAccessAttempts < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :rsvp_access_attempts do |t|
|
4
|
+
t.string :remote_ip
|
5
|
+
t.integer :failed_attempts, default: 0
|
6
|
+
t.datetime :locked_at
|
7
|
+
t.integer :locks_incurred, default: 0
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
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.1.
|
4
|
+
version: 0.1.5
|
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-
|
11
|
+
date: 2014-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- app/controllers/rsvp/response_controller.rb
|
162
162
|
- app/controllers/rsvp/session_controller.rb
|
163
163
|
- app/helpers/rsvp/application_helper.rb
|
164
|
+
- app/models/rsvp/access_attempt.rb
|
164
165
|
- app/models/rsvp/family.rb
|
165
166
|
- app/models/rsvp/gender.rb
|
166
167
|
- app/models/rsvp/gender/adult_female.rb
|
@@ -171,9 +172,12 @@ files:
|
|
171
172
|
- app/models/rsvp/member.rb
|
172
173
|
- app/models/rsvp/person.rb
|
173
174
|
- app/models/rsvp/response.rb
|
175
|
+
- app/models/rsvp/rsvp.rb
|
174
176
|
- app/models/rsvp/salutation.rb
|
175
177
|
- app/models/rsvp/salutation/boyfriend_and_girlfriend.rb
|
176
178
|
- app/models/rsvp/salutation/husband_and_wife.rb
|
179
|
+
- app/models/rsvp/salutation/husband_and_wife_with_own_names.rb
|
180
|
+
- app/models/rsvp/salutation/husband_wife_and_children.rb
|
177
181
|
- app/models/rsvp/salutation/husband_wife_and_family.rb
|
178
182
|
- app/models/rsvp/salutation/lieutenant_colonel_and_wife.rb
|
179
183
|
- app/models/rsvp/salutation/male_doctor_and_wife.rb
|
@@ -199,6 +203,7 @@ files:
|
|
199
203
|
- db/migrate/20140106042748_create_rsvp_members.rb
|
200
204
|
- db/migrate/20140106042845_create_rsvp_invitations.rb
|
201
205
|
- db/migrate/20140106043014_create_rsvp_responses.rb
|
206
|
+
- db/migrate/20140304015111_create_rsvp_access_attempts.rb
|
202
207
|
- lib/generators/rsvp/USAGE
|
203
208
|
- lib/generators/rsvp/views_generator.rb
|
204
209
|
- lib/rsvp.rb
|