GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Resource-oriented open source Ruby framework for Web apps.
Homepage: http://rubywaves.com/
Clone URL: git://github.com/dyoder/waves.git
HTTP Basic authentication example in blog
automatthew (author)
Sat Oct 04 01:21:40 -0700 2008
commit  db70bc2f4a2beccb2198faceeb72fff65a9d3f38
tree    dfabb431bb8427554be649bd34c10eb4a6c37d72
parent  0bb83d534d4096eb3bc69355973749d06b986eed
...
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
7
8
...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
0
@@ -3,6 +3,24 @@ module Blog
0
     class Entry < Default
0
       include Waves::Resources::Mixin
0
       
0
+ def basic_auth
0
+ raise Waves::Dispatchers::Unauthorized unless auth = @request.http_variable('Authorization')
0
+ scheme, credentials = auth.split(' ', 2)
0
+ raise Waves::Dispatchers::BadRequest unless scheme == "Basic"
0
+ credentials.unpack("m*").first.split(/:/, 2)
0
+ end
0
+
0
+ before do
0
+ return if @request.method == :get
0
+ @user, @pass = basic_auth
0
+ authenticate(*basic_auth)
0
+ end
0
+
0
+ def authenticate(user, password)
0
+ raise Waves::Dispatchers::Unauthorized unless user.reverse == password
0
+ end
0
+
0
+
0
       on :get, :list => [ /entry|entries/ ] do
0
         view.list( plural => controller.all )
0
       end
...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
8
9
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
12
13
14
0
@@ -8,23 +8,6 @@ module Blog
0
       on( :get, [ /entry|entries/ ] ) { to(:entry) }
0
       on( true, [ /entry|entries/, true ] ) { to(:entry) }
0
       
0
-
0
- #
0
- # # default to story if nothing else matches
0
- # on( true ) { to( :story ) }
0
- #
0
- # # special URL just for login and authenticating
0
- # on( [ :get, :post ], [ 'login' ] ) { to( :site ) }
0
- #
0
- # # otherwise assume we are matching against a resource
0
- # on( true, [ :resource ] ) { to( captured.resource ) }
0
- # on( true, [ :resource, { :rest => true } ] ) { to( captured.resource ) }
0
- #
0
- # # before anything else, check the accepts headers and route accordingly
0
- # on( :get, true, :accept => :image ) { to( :image ) }
0
- # on( :get, true, :accept => [ :css, :javascript ] ) { to( :media ) }
0
- # on( :get, true, :accept => :rss ) { to( :blog ) }
0
-
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
7
8
9
10
11
 
12
13
14
...
7
8
9
 
10
11
12
13
14
0
@@ -7,8 +7,8 @@ layout :default, :title => 'Edit Entry' do
0
     input :type => :text, :value => @entry.name, :name => 'entry.name', :size => 50; br
0
     label 'Content'; br
0
     textarea @entry.content, :name => 'entry.content', :rows => 20, :cols => 70; br
0
- a 'Cancel', :href => "/entry/#{@entry.name}"
0
     input :type => :submit, :value => 'Save'
0
+ a 'Cancel', :href => "/entry/#{@entry.name}"
0
   end
0
 end
0
 

Comments

    No one has commented yet.