Skip to content

Commit

Permalink
cookie lifetime - support secrets + update version/readme (#40)
Browse files Browse the repository at this point in the history
* cookie lifetime - support secrets + update version/readme
* bump FIST_BUMP
  • Loading branch information
gblakeman authored Jul 27, 2018
1 parent 0372d51 commit b84285a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions FIST_BUMP.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A note of thanks from Grant ([@gblakeman](http://twitter.com/gblakeman)) and Jak

<img src="http://lockupgem.com/github_host/adventure_time_fist_bump.gif" width="450" height="253" alt="Fist Bump!" />

* Thanks (again) to Dan Rabinowitz (https://github.com/danrabinowitz) for adding support for customizing the length of the cookie.
* Thanks to Nathan Broadbent (https://github.com/ndbroadbent) for some nice refactoring and an additional check.
* Thanks (again) to Dan Rabinowitz (https://github.com/danrabinowitz) for prepping the gem for Rails 5.
* Thanks to Dan Rabinowitz (https://github.com/danrabinowitz) for catching a js error when hints are not used & for providing some additional places for bots to die.
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ The visitor is redirected and the cookie is set without them ever seeing the Loc

(Lockup also makes a rudimentary attempt based on user agent to **block major search engine bots/crawlers** from following this link and indexing the site, just in case it ever gets out into the wild.)

### Set a custom lifetime for cookie

The cookie set by Lockup defaults to 5 years. If you want to set a shorter amount of time, you can specify a number of weeks:

ENV["COOKIE_LIFETIME_IN_WEEKS"] = 4

cookie_lifetime_in_weeks: 4

### Design Customization

If you would like to change the content or design of the lockup page, you can create the directories `app/views/layouts/lockup` and `app/views/lockup/lockup` and populate them with the default content from [here](https://github.com/gblakeman/lockup/tree/master/app/views), and then customize as desired.
Expand Down
12 changes: 11 additions & 1 deletion lib/lockup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ def lockup_codeword
end
end

def cookie_lifetime_variable
if ENV["COOKIE_LIFETIME_IN_WEEKS"].present?
ENV["COOKIE_LIFETIME_IN_WEEKS"]
elsif ENV["cookie_lifetime_in_weeks"].present?
ENV["cookie_lifetime_in_weeks"]
elsif Rails.application.respond_to?(:secrets) && Rails.application.secrets.cookie_lifetime_in_weeks.present?
Rails.application.secrets.cookie_lifetime_in_weeks
end
end

def cookie_lifetime
weeks = ENV['COOKIE_LIFETIME_IN_WEEKS'].to_f
weeks = (cookie_lifetime_variable || 0).to_f
seconds = (weeks * 1.week).to_i
if seconds > 0
seconds
Expand Down
2 changes: 1 addition & 1 deletion lib/lockup/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Lockup
VERSION = "1.4.1"
VERSION = "1.4.2"
end

0 comments on commit b84285a

Please sign in to comment.