dandelion_s1 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/dandelion_s1.rb +30 -21
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a05e6e6bb8ae9266772efd9cb0acb112a9ea080
|
4
|
+
data.tar.gz: 96bc27d7c4d69e0c2d264270dd32f7be33ae27a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26d04e12c6e4c99b20112703fd461176499e73868b75ba86f208acd204cf69e044e33b8e18b4abf9db527dbae6477b5a904581ba5ebc0887d30e86d01947144d
|
7
|
+
data.tar.gz: 41ac1772805b24e868b916d36b5a54e9c2cfb5ed8931afc357098f17d7796677c1c2a2173627cc3b2c06a2192c406845f279429c3462e27dca565f8140cdf6e4
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/dandelion_s1.rb
CHANGED
@@ -11,8 +11,9 @@ class DandelionS1 < RackRscript
|
|
11
11
|
|
12
12
|
def initialize(opts={})
|
13
13
|
|
14
|
-
h = {root: 'www', static: []}.merge(opts)
|
14
|
+
h = {root: 'www', static: [], passwords: {'user' => 'us3r'}}.merge(opts)
|
15
15
|
|
16
|
+
@passwords = h[:passwords]
|
16
17
|
access_list = h[:access]
|
17
18
|
@app_root = Dir.pwd
|
18
19
|
|
@@ -44,7 +45,7 @@ class DandelionS1 < RackRscript
|
|
44
45
|
|
45
46
|
req = Rack::Request.new(e)
|
46
47
|
user = req.session[:username]
|
47
|
-
|
48
|
+
|
48
49
|
return jumpto '/login' unless user
|
49
50
|
|
50
51
|
if private_user.nil? then
|
@@ -64,23 +65,24 @@ class DandelionS1 < RackRscript
|
|
64
65
|
|
65
66
|
get '/login' do
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
username: [ ]
|
70
|
-
password: [ ]
|
71
|
-
|
72
|
-
[login]('/login')
|
73
|
-
EOF
|
74
|
-
|
75
|
-
Martile.new(s).to_html
|
68
|
+
login_form()
|
69
|
+
|
76
70
|
end
|
77
71
|
|
78
72
|
post '/login' do
|
79
73
|
|
80
74
|
h = @req.params
|
81
|
-
@req.session[:username] = h['username']
|
82
75
|
|
83
|
-
|
76
|
+
if @passwords[h['username']] == h['password'] then
|
77
|
+
|
78
|
+
@req.session[:username] = h['username']
|
79
|
+
'you are now logged in as ' + h['username']
|
80
|
+
|
81
|
+
else
|
82
|
+
|
83
|
+
login_form('Invalid username or password, try again.',401)
|
84
|
+
|
85
|
+
end
|
84
86
|
|
85
87
|
end
|
86
88
|
|
@@ -110,21 +112,28 @@ EOF
|
|
110
112
|
end
|
111
113
|
|
112
114
|
get '/unauthorised' do
|
113
|
-
'unauthorised user'
|
115
|
+
['unauthorised user', 'text/plain', 403]
|
114
116
|
end
|
115
117
|
|
116
118
|
super(env, params)
|
117
119
|
|
118
120
|
end
|
119
121
|
|
120
|
-
|
121
|
-
|
122
|
-
def jumpto(request)
|
123
|
-
|
124
|
-
content, content_type, status_code = run_route(request)
|
125
|
-
content_type ||= 'text/html'
|
126
|
-
[status_code=401, {"Content-Type" => content_type}, [content]]
|
122
|
+
def login_form(msg='Log in to this site.', http_code=200)
|
127
123
|
|
124
|
+
s=<<EOF
|
125
|
+
p #{msg}
|
126
|
+
|
127
|
+
login
|
128
|
+
username: [ ]
|
129
|
+
password: [ ]
|
130
|
+
|
131
|
+
[login]('/login')
|
132
|
+
EOF
|
133
|
+
|
134
|
+
[Martile.new(s).to_s, 'text/slim', http_code]
|
135
|
+
|
128
136
|
end
|
129
137
|
|
138
|
+
|
130
139
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|