codeword 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-version +1 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +97 -0
- data/Rakefile +6 -0
- data/app/controllers/codeword/application_controller.rb +4 -0
- data/app/controllers/codeword/codeword_controller.rb +57 -0
- data/app/helpers/codeword/application_helper.rb +4 -0
- data/app/helpers/codeword/codeword_helper.rb +13 -0
- data/app/views/codeword/codeword/unlock.html.erb +33 -0
- data/app/views/layouts/codeword/_inline_css.html.erb +97 -0
- data/app/views/layouts/codeword/_normalize.html.erb +57 -0
- data/app/views/layouts/codeword/application.html.erb +20 -0
- data/codeword.gemspec +30 -0
- data/config/routes.rb +4 -0
- data/lib/codeword/engine.rb +15 -0
- data/lib/codeword/version.rb +3 -0
- data/lib/codeword.rb +62 -0
- data/script/rails +8 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a2a3032588df8a3dfcb5b5584785cdc9edf5558f2a47216dc70e32a74c083720
|
4
|
+
data.tar.gz: 54dcd07135dd8fe40e1a09091894a7c9baffb9c91d30e0bb4e12f0c18d3686ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 811c21657b493979a64f641e3cb042bae1aec61312d7a3a96e45d7ac17614fcb0fa438f24cb8d7f75c75ef75279082018cb8b9bb97842c0542d2568693994bab
|
7
|
+
data.tar.gz: b3066b27282c5d060c981aa25f983f72fbe51144c31b7aee85921009696c66914976f404c3b6371fc7d1eef39e2e8f081bd87e356c3bf89a6c3bf71c6b35f283
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.3
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in codeword.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use debugger
|
14
|
+
# gem 'debugger'
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Dan Kim
|
4
|
+
Copyright (c) 2013 gb Studio, llc
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# Codeword
|
2
|
+
|
3
|
+
A simple gem to more elegantly place a staging server or other in-progress rails application behind a basic codeword. It’s easy to implement, share with clients/collaborators, and more beautiful than the typical password-protection sheet.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
1. Add this line to your application’s Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'codeword'
|
11
|
+
```
|
12
|
+
|
13
|
+
2. Define a codeword (see Usage below).
|
14
|
+
|
15
|
+
3. Mount the engine in your application’s routes file (usually first, for best results):
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
mount Codeword::Engine, at: '/codeword'
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To set a codeword, define CODEWORD in your environments/your_environment.rb file like so:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
ENV['CODEWORD'] = 'secret'
|
27
|
+
```
|
28
|
+
|
29
|
+
If you think you might need a hint:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
ENV['CODEWORD_HINT'] = 'Something that you do not tell everyone.'
|
33
|
+
```
|
34
|
+
|
35
|
+
If you’re using Rails >= 4.1 or Rails >= 5.2, you can add your Codeword Codeword via Rails Secrets or Rails Credentials functionality in your `secrets.yml` or `credentials.yml.enc` file, respectively:
|
36
|
+
|
37
|
+
```yml
|
38
|
+
codeword: 'love'
|
39
|
+
codeword_hint: 'Pepé Le Pew'
|
40
|
+
```
|
41
|
+
|
42
|
+
Alternately, Rails Credentials in >= 5.2 may be organized under the `codeword` namespace:
|
43
|
+
|
44
|
+
```yml
|
45
|
+
codeword:
|
46
|
+
codeword: 'love'
|
47
|
+
hint: 'Pepé Le Pew'
|
48
|
+
```
|
49
|
+
|
50
|
+
If you’re using [Figaro](https://github.com/laserlemon/figaro), set your Codeword codeword and hint (optional) in your application.yml file:
|
51
|
+
|
52
|
+
```yml
|
53
|
+
codeword: 'love'
|
54
|
+
codeword_hint: 'Pepé Le Pew'
|
55
|
+
```
|
56
|
+
|
57
|
+
**Codewords are not case-sensitive, by design. Keep it simple.**
|
58
|
+
|
59
|
+
## Advanced Usage
|
60
|
+
|
61
|
+
### Use Codeword around a specific controller:
|
62
|
+
|
63
|
+
1. Follow the installation instructions above.
|
64
|
+
|
65
|
+
2. In your application_controller.rb file, add:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
skip_before_action :check_for_codeword, raise: false
|
69
|
+
```
|
70
|
+
|
71
|
+
4. In the controller(s) you would like to restrict:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
before_action :check_for_codeword
|
75
|
+
```
|
76
|
+
|
77
|
+
### Link it with no typing:
|
78
|
+
|
79
|
+
http://somedomain.com/or_path/?codeword=love
|
80
|
+
|
81
|
+
The visitor is redirected and the cookie is set without them ever seeing the Codeword splash page.
|
82
|
+
|
83
|
+
(Codeword 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.)
|
84
|
+
|
85
|
+
### Set a custom lifetime for cookie
|
86
|
+
|
87
|
+
The cookie set by Codeword defaults to 5 years. If you want to set a shorter amount of time, you can specify a number of weeks:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
ENV['COOKIE_LIFETIME_IN_WEEKS'] = 4
|
91
|
+
|
92
|
+
cookie_lifetime_in_weeks: 4
|
93
|
+
```
|
94
|
+
|
95
|
+
### Design Customization
|
96
|
+
|
97
|
+
If you would like to change the content or design of the codeword page, you can create the directories `app/views/layouts/codeword` and `app/views/codeword/codeword` and populate them with the default content from [here](https://github.com/gblakeman/codeword/tree/master/app/views), and then customize as desired.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Codeword
|
2
|
+
class CodewordController < Codeword::ApplicationController
|
3
|
+
CRAWLER_REGEX = /crawl|googlebot|slurp|spider|bingbot|tracker|click|parser|spider/
|
4
|
+
|
5
|
+
if respond_to?(:skip_before_action)
|
6
|
+
skip_before_action :check_for_codeword
|
7
|
+
else
|
8
|
+
skip_before_filter :check_for_codeword
|
9
|
+
end
|
10
|
+
|
11
|
+
def unlock
|
12
|
+
if params[:codeword].present?
|
13
|
+
user_agent = request.env['HTTP_USER_AGENT'].presence
|
14
|
+
if user_agent && user_agent.downcase.match(CRAWLER_REGEX)
|
15
|
+
head :ok
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
@codeword = params[:codeword].to_s.downcase
|
20
|
+
@return_to = params[:return_to]
|
21
|
+
if @codeword == codeword.to_s.downcase
|
22
|
+
set_cookie
|
23
|
+
run_redirect
|
24
|
+
end
|
25
|
+
elsif request.post?
|
26
|
+
if params[:codeword].present? && params[:codeword].respond_to?(:'[]')
|
27
|
+
@codeword = params[:codeword][:codeword].to_s.downcase
|
28
|
+
@return_to = params[:codeword][:return_to]
|
29
|
+
if @codeword == codeword.to_s.downcase
|
30
|
+
set_cookie
|
31
|
+
run_redirect
|
32
|
+
else
|
33
|
+
@wrong = true
|
34
|
+
end
|
35
|
+
else
|
36
|
+
head :ok
|
37
|
+
end
|
38
|
+
else
|
39
|
+
respond_to :html
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def set_cookie
|
46
|
+
cookies[:codeword] = { value: @codeword.to_s.downcase, expires: (Time.now + codeword_cookie_lifetime) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def run_redirect
|
50
|
+
if @return_to.present?
|
51
|
+
redirect_to @return_to.to_s
|
52
|
+
else
|
53
|
+
redirect_to '/'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codeword
|
4
|
+
module CodewordHelper
|
5
|
+
def codeword_hint
|
6
|
+
@codeword_hint ||=
|
7
|
+
ENV['CODEWORD_HINT'] ||
|
8
|
+
ENV['codeword_hint'] ||
|
9
|
+
::Codeword.from_config(:hint, :secrets) ||
|
10
|
+
::Codeword.from_config(:hint)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<div class="container">
|
2
|
+
<h1 style="margin-bottom: .5rem;">One more step</h1>
|
3
|
+
|
4
|
+
<p style="margin-bottom: 1.25rem;">Please enter the code word to continue…</p>
|
5
|
+
|
6
|
+
<% if @wrong %>
|
7
|
+
<div class="alert" style="margin-bottom: 1rem;">
|
8
|
+
<p>Hmm… that doesn't seem right. Try again?</p>
|
9
|
+
</div>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= form_for :codeword, url: { action: 'unlock' } do |form| %>
|
13
|
+
<% if params[:return_to].present? %>
|
14
|
+
<%= form.hidden_field "return_to", value: params[:return_to] %>
|
15
|
+
<% elsif @return_to.present? %>
|
16
|
+
<%= form.hidden_field "return_to", value: @return_to %>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<% unless @wrong == true %>
|
20
|
+
<%= form.password_field :codeword, placeholder: "Code word", autofocus: true, required: true %>
|
21
|
+
<% else %>
|
22
|
+
<%= form.password_field :codeword, value: @codeword, class: 'nope', autofocus: true, required: true %>
|
23
|
+
<% end %>
|
24
|
+
|
25
|
+
<% if codeword_hint %>
|
26
|
+
<small title="<%= codeword_hint %>" class="hint">Hint</small>
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
<p>
|
30
|
+
<%= button_tag 'Go', class: 'button', style: 'margin-top: .75rem;' %>
|
31
|
+
</p>
|
32
|
+
<% end %>
|
33
|
+
</div>
|
@@ -0,0 +1,97 @@
|
|
1
|
+
body {
|
2
|
+
color: #1a202c;
|
3
|
+
background-color: #f7fafc;
|
4
|
+
overflow: hidden;
|
5
|
+
margin: 0;
|
6
|
+
|
7
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
8
|
+
"Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji",
|
9
|
+
"Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
10
|
+
|
11
|
+
min-height: 100vh;
|
12
|
+
display: flex;
|
13
|
+
justify-content: center;
|
14
|
+
}
|
15
|
+
|
16
|
+
p {
|
17
|
+
color: #4a5568;
|
18
|
+
margin: 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
.container {
|
22
|
+
margin: 0 auto;
|
23
|
+
padding-left: 1rem;
|
24
|
+
padding-right: 1rem;
|
25
|
+
width: 100%;
|
26
|
+
}
|
27
|
+
|
28
|
+
.text-center {
|
29
|
+
text-align: center;
|
30
|
+
}
|
31
|
+
|
32
|
+
@media (min-width: 768px) {
|
33
|
+
.container {
|
34
|
+
align-self: center;
|
35
|
+
max-width: 384px;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
form input[type="password"] {
|
40
|
+
color: #4a5568;
|
41
|
+
border: 1px solid #e2e8f0;
|
42
|
+
border-radius: 0.25rem;
|
43
|
+
padding: 0.75rem 0.75rem;
|
44
|
+
line-height: 1.25;
|
45
|
+
-webkit-appearance: none;
|
46
|
+
}
|
47
|
+
|
48
|
+
form input[type="password"]:focus {
|
49
|
+
border-color: #266cec;
|
50
|
+
}
|
51
|
+
|
52
|
+
form input[type="password"].nope {
|
53
|
+
border-color: #d01a45;
|
54
|
+
}
|
55
|
+
|
56
|
+
.button {
|
57
|
+
background-color: #48bb78;
|
58
|
+
color: #fff;
|
59
|
+
cursor: pointer;
|
60
|
+
display: inline-block;
|
61
|
+
padding: 0.875rem 1rem;
|
62
|
+
border-radius: 0.25rem;
|
63
|
+
border: 1px solid transparent;
|
64
|
+
|
65
|
+
font-size: 0.875rem;
|
66
|
+
font-weight: 600;
|
67
|
+
text-align: center;
|
68
|
+
text-transform: uppercase;
|
69
|
+
letter-spacing: 0.1em;
|
70
|
+
|
71
|
+
outline: none;
|
72
|
+
transition: all 0.3s;
|
73
|
+
}
|
74
|
+
|
75
|
+
.button:hover,
|
76
|
+
.button:focus {
|
77
|
+
background-color: #2f855a;
|
78
|
+
}
|
79
|
+
|
80
|
+
.alert {
|
81
|
+
display: block;
|
82
|
+
padding: 0.875rem 1rem;
|
83
|
+
background-color: #fff5f5;
|
84
|
+
border: 1px solid #fc8181;
|
85
|
+
border-radius: 4px;
|
86
|
+
}
|
87
|
+
|
88
|
+
.alert p {
|
89
|
+
color: #c53030;
|
90
|
+
}
|
91
|
+
|
92
|
+
.hint {
|
93
|
+
display: block;
|
94
|
+
cursor: help;
|
95
|
+
color: #718096;
|
96
|
+
margin-top: 0.5rem;
|
97
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
html {
|
2
|
+
font-family: sans-serif;
|
3
|
+
line-height: 1.15;
|
4
|
+
-ms-text-size-adjust: 100%;
|
5
|
+
-webkit-text-size-adjust: 100%;
|
6
|
+
}
|
7
|
+
|
8
|
+
a {
|
9
|
+
-webkit-text-decoration-skip: objects;
|
10
|
+
}
|
11
|
+
|
12
|
+
svg:not(:root) {
|
13
|
+
overflow: hidden;
|
14
|
+
}
|
15
|
+
|
16
|
+
button,
|
17
|
+
input,
|
18
|
+
optgroup,
|
19
|
+
select,
|
20
|
+
textarea {
|
21
|
+
font-family: sans-serif;
|
22
|
+
font-size: 100%;
|
23
|
+
line-height: 1.15;
|
24
|
+
margin: 0;
|
25
|
+
text-transform: none;
|
26
|
+
}
|
27
|
+
|
28
|
+
button,
|
29
|
+
input {
|
30
|
+
overflow: visible;
|
31
|
+
}
|
32
|
+
|
33
|
+
button,
|
34
|
+
html [type="button"],
|
35
|
+
[type="reset"],
|
36
|
+
[type="submit"] {
|
37
|
+
-webkit-appearance: button;
|
38
|
+
}
|
39
|
+
|
40
|
+
button::-moz-focus-inner,
|
41
|
+
[type="button"]::-moz-focus-inner,
|
42
|
+
[type="reset"]::-moz-focus-inner,
|
43
|
+
[type="submit"]::-moz-focus-inner {
|
44
|
+
border-style: none;
|
45
|
+
padding: 0;
|
46
|
+
}
|
47
|
+
|
48
|
+
button:-moz-focusring,
|
49
|
+
[type="button"]:-moz-focusring,
|
50
|
+
[type="reset"]:-moz-focusring,
|
51
|
+
[type="submit"]:-moz-focusring {
|
52
|
+
outline: 1px dotted ButtonText;
|
53
|
+
}
|
54
|
+
|
55
|
+
textarea {
|
56
|
+
overflow: auto;
|
57
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
7
|
+
<meta name="robots" content="noindex, nofollow">
|
8
|
+
|
9
|
+
<title>Please enter the code word to continue…</title>
|
10
|
+
|
11
|
+
<style>
|
12
|
+
<%= render partial: 'layouts/codeword/normalize' %>
|
13
|
+
<%= render partial: 'layouts/codeword/inline_css' %>
|
14
|
+
</style>
|
15
|
+
</head>
|
16
|
+
|
17
|
+
<body>
|
18
|
+
<%= yield %>
|
19
|
+
</body>
|
20
|
+
</html>
|
data/codeword.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'codeword/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'codeword'
|
7
|
+
spec.version = Codeword::VERSION
|
8
|
+
spec.authors = ['Dan Kim', 'gb Studio']
|
9
|
+
spec.email = ['itsdanya@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Lock staging servers from search engines and prying eyespec.'
|
12
|
+
spec.description = 'A simple gem to more elegantly place a staging server or other in-progress application behind a basic codeword. It’s easy to implement, share with clients/collaborators, and more beautiful than the typical password-protection sheet.'
|
13
|
+
spec.homepage = 'https://github.com/dankimio/codeword'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/dankimio/codeword'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/dankimio/codeword/CHANGELOG.md'
|
19
|
+
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.add_dependency 'rails', '>= 6'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'capybara', '~> 2.9'
|
27
|
+
spec.add_development_dependency 'debug'
|
28
|
+
spec.add_development_dependency 'launchy', '~> 2.4'
|
29
|
+
spec.add_development_dependency 'rspec-rails', '~> 4.0'
|
30
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Codeword
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace Codeword
|
4
|
+
|
5
|
+
config.generators do |g|
|
6
|
+
g.test_framework :rspec, fixture: false
|
7
|
+
g.assets false
|
8
|
+
g.helper false
|
9
|
+
end
|
10
|
+
|
11
|
+
initializer 'codeword.app_controller' do |_app|
|
12
|
+
ActiveSupport.on_load(:action_controller) { include Codeword }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/codeword.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'codeword/engine'
|
4
|
+
|
5
|
+
module Codeword
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
if respond_to?(:before_action)
|
10
|
+
before_action :check_for_codeword, except: ['unlock']
|
11
|
+
else
|
12
|
+
before_filter :check_for_codeword, except: ['unlock']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.from_config(setting, secrets_or_credentials = :credentials)
|
17
|
+
return unless Rails.application.respond_to?(secrets_or_credentials)
|
18
|
+
|
19
|
+
store = Rails.application.public_send(secrets_or_credentials)
|
20
|
+
|
21
|
+
store.codeword.respond_to?(:fetch) &&
|
22
|
+
store.codeword.fetch(setting, store.public_send("codeword_#{setting}")) ||
|
23
|
+
store.public_send("codeword_#{setting}") || store.public_send(setting)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def check_for_codeword
|
29
|
+
return unless respond_to?(:codeword) && codeword_code
|
30
|
+
return if cookies[:codeword].present? && cookies[:codeword] == codeword_code.to_s.downcase
|
31
|
+
|
32
|
+
redirect_to codeword.unlock_path(
|
33
|
+
return_to: request.fullpath.split('?codeword')[0],
|
34
|
+
codeword: params[:codeword]
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def cookie_lifetime
|
39
|
+
@cookie_lifetime ||=
|
40
|
+
ENV['COOKIE_LIFETIME_IN_WEEKS'] ||
|
41
|
+
ENV['cookie_lifetime_in_weeks'] ||
|
42
|
+
Codeword.from_config(:cookie_lifetime_in_weeks, :secrets) ||
|
43
|
+
Codeword.from_config(:cookie_lifetime_in_weeks)
|
44
|
+
end
|
45
|
+
|
46
|
+
def codeword_code
|
47
|
+
@codeword ||=
|
48
|
+
ENV['CODEWORD'] ||
|
49
|
+
ENV['codeword'] ||
|
50
|
+
Codeword.from_config(:codeword, :secrets) ||
|
51
|
+
Codeword.from_config(:codeword)
|
52
|
+
end
|
53
|
+
|
54
|
+
def codeword_cookie_lifetime
|
55
|
+
seconds = (cookie_lifetime.to_f * 1.week).to_i
|
56
|
+
if seconds > 0
|
57
|
+
seconds
|
58
|
+
else
|
59
|
+
5.years
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/script/rails
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
5
|
+
ENGINE_PATH = File.expand_path('../lib/codeword/engine', __dir__)
|
6
|
+
|
7
|
+
require 'rails/all'
|
8
|
+
require 'rails/engine/commands'
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codeword
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Kim
|
8
|
+
- gb Studio
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2021-12-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '6'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '6'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: capybara
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '2.9'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '2.9'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: debug
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: launchy
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.4'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.4'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec-rails
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '4.0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '4.0'
|
84
|
+
description: A simple gem to more elegantly place a staging server or other in-progress
|
85
|
+
application behind a basic codeword. It’s easy to implement, share with clients/collaborators,
|
86
|
+
and more beautiful than the typical password-protection sheet.
|
87
|
+
email:
|
88
|
+
- itsdanya@gmail.com
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".gitignore"
|
94
|
+
- ".ruby-version"
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- app/controllers/codeword/application_controller.rb
|
100
|
+
- app/controllers/codeword/codeword_controller.rb
|
101
|
+
- app/helpers/codeword/application_helper.rb
|
102
|
+
- app/helpers/codeword/codeword_helper.rb
|
103
|
+
- app/views/codeword/codeword/unlock.html.erb
|
104
|
+
- app/views/layouts/codeword/_inline_css.html.erb
|
105
|
+
- app/views/layouts/codeword/_normalize.html.erb
|
106
|
+
- app/views/layouts/codeword/application.html.erb
|
107
|
+
- codeword.gemspec
|
108
|
+
- config/routes.rb
|
109
|
+
- lib/codeword.rb
|
110
|
+
- lib/codeword/engine.rb
|
111
|
+
- lib/codeword/version.rb
|
112
|
+
- script/rails
|
113
|
+
homepage: https://github.com/dankimio/codeword
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata:
|
117
|
+
homepage_uri: https://github.com/dankimio/codeword
|
118
|
+
source_code_uri: https://github.com/dankimio/codeword
|
119
|
+
changelog_uri: https://github.com/dankimio/codeword/CHANGELOG.md
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubygems_version: 3.2.32
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Lock staging servers from search engines and prying eyespec.
|
139
|
+
test_files: []
|