dandelion_s1 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: defb22aa3bc5c08f20627b62117b79956d26fae9
4
- data.tar.gz: f05f2b8d594b2d71d824d69c47e96ed5ef657a96
3
+ metadata.gz: 4a05e6e6bb8ae9266772efd9cb0acb112a9ea080
4
+ data.tar.gz: 96bc27d7c4d69e0c2d264270dd32f7be33ae27a9
5
5
  SHA512:
6
- metadata.gz: c0c8aa85c39e7bdfbcd5a5bbe40dc299de87b50d21021dac0fccaefc4042e72f1fb2940357303f57eea9a054ae655ea780d1cbdbda575322c0aee71f79ad7896
7
- data.tar.gz: 6ea4b45538e936120c85c2db335898b88ade4b3acff7dbad93d242908a8c0a990b053307ab1d917d5e64f3bf4f7de920a24c847a3ac6d73bd1e90da86c19e0d5
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
- #return [status_code=401, {"Content-Type" => 'text/plain'}, [user.inspect]]
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
- s=<<EOF
68
- login
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
- 'you are now logged in as ' + h['username']
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
- private
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dandelion_s1
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file