vanilla 1.9.12 → 1.9.13
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.
- data/Rakefile +1 -1
- data/config.ru +1 -1
- data/lib/vanilla/authentication/warden.rb +18 -2
- data/lib/vanilla/dynasnips/logout.rb +8 -0
- data/lib/vanilla/dynasnips/new.rb +0 -2
- data/lib/vanilla/snips/system.rb +14 -0
- metadata +2 -2
- data/lib/vanilla/dynasnips/login.rb +0 -40
data/Rakefile
CHANGED
data/config.ru
CHANGED
@@ -12,7 +12,7 @@ require 'vanilla/authentication/warden'
|
|
12
12
|
app.authenticator = Vanilla::Authentication::Warden.new(app)
|
13
13
|
use Warden::Manager do |manager|
|
14
14
|
manager.default_strategies :vanilla
|
15
|
-
manager.failure_app =
|
15
|
+
manager.failure_app = Vanilla::Authentication::Warden::FailApp.new
|
16
16
|
end
|
17
17
|
|
18
18
|
use Rack::Static, :urls => ["/public"], :root => File.join(File.dirname(__FILE__))
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'warden'
|
2
|
+
require 'md5'
|
2
3
|
|
3
4
|
module Vanilla
|
4
5
|
module Authentication
|
@@ -31,12 +32,27 @@ module Vanilla
|
|
31
32
|
|
32
33
|
def authenticate!
|
33
34
|
if env['vanilla.app'].config[:credentials][params["name"]] == MD5.md5(params["password"]).to_s
|
35
|
+
# clear these so they don't interfere with the request
|
36
|
+
env['vanilla.app'].request.params.delete(:name)
|
37
|
+
env['vanilla.app'].request.params.delete(:password)
|
34
38
|
success!(params["name"])
|
35
39
|
else
|
36
|
-
|
40
|
+
fail! "Sorry, you couldn't be logged in with those details"
|
37
41
|
end
|
38
42
|
end
|
39
43
|
end
|
44
|
+
|
45
|
+
class FailApp
|
46
|
+
def call(env)
|
47
|
+
[401, {"Content-Type" => "text/html"}, [login_form(env)]]
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def login_form(env)
|
53
|
+
env['vanilla.app'].soup["system"].login_template.gsub("MESSAGE", env['warden'].message)
|
54
|
+
end
|
55
|
+
end
|
40
56
|
end
|
41
57
|
end
|
42
|
-
end
|
58
|
+
end
|
data/lib/vanilla/snips/system.rb
CHANGED
@@ -27,6 +27,20 @@ system.main_template = <<-HTML
|
|
27
27
|
</html>
|
28
28
|
HTML
|
29
29
|
|
30
|
+
system.login_template = <<-HTML
|
31
|
+
<html>
|
32
|
+
<head><link rel="stylesheet" type="text/css" media="screen" href="/system/css.css" /></head>
|
33
|
+
<body id="login">
|
34
|
+
<form action='' method='post'>
|
35
|
+
<h1>Login</h1><p class="message">MESSAGE</p>
|
36
|
+
<label>Name: <input type="text" name="name"></input></label>
|
37
|
+
<label>Password: <input type="password" name="password"></input></label>
|
38
|
+
<button>login</button>
|
39
|
+
</form>
|
40
|
+
</body>
|
41
|
+
</html>
|
42
|
+
HTML
|
43
|
+
|
30
44
|
system.css = <<-CSS
|
31
45
|
body {
|
32
46
|
font-family: Helvetica;
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vanilla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Adam
|
@@ -136,7 +136,7 @@ files:
|
|
136
136
|
- lib/vanilla/dynasnips/kind.rb
|
137
137
|
- lib/vanilla/dynasnips/link_to.rb
|
138
138
|
- lib/vanilla/dynasnips/link_to_current_snip.rb
|
139
|
-
- lib/vanilla/dynasnips/
|
139
|
+
- lib/vanilla/dynasnips/logout.rb
|
140
140
|
- lib/vanilla/dynasnips/new.rb
|
141
141
|
- lib/vanilla/dynasnips/notes.rb
|
142
142
|
- lib/vanilla/dynasnips/pre.rb
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'vanilla/dynasnip'
|
2
|
-
require 'yaml'
|
3
|
-
require 'md5'
|
4
|
-
|
5
|
-
class Login < Dynasnip
|
6
|
-
def get(*args)
|
7
|
-
if app.request.authenticated?
|
8
|
-
login_controls
|
9
|
-
else
|
10
|
-
render(self, 'template')
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def post(*args)
|
15
|
-
if app.request.authenticate!
|
16
|
-
login_controls
|
17
|
-
else
|
18
|
-
"login fail!"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def delete(*args)
|
23
|
-
app.request.logout
|
24
|
-
"Logged out"
|
25
|
-
end
|
26
|
-
|
27
|
-
attribute :template, <<-EHTML
|
28
|
-
<form action='/login' method='post'>
|
29
|
-
<label>Name: <input type="text" name="name"></input></label>
|
30
|
-
<label>Password: <input type="password" name="password"></input></label>
|
31
|
-
<button>login</button>
|
32
|
-
</form>
|
33
|
-
EHTML
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def login_controls
|
38
|
-
"logged in as #{link_to app.request.user}; <a href='/login?_method=delete'>logout</a>"
|
39
|
-
end
|
40
|
-
end
|