sinatra-authentication-dmeiz 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +4 -0
  2. data/History.txt +4 -0
  3. data/Manifest +26 -0
  4. data/Rakefile +38 -0
  5. data/TODO +53 -0
  6. data/example/dm_extend_app.rb +26 -0
  7. data/example/dm_sinbook.rb +56 -0
  8. data/example/extend_views/edit.haml +42 -0
  9. data/example/extend_views/index.haml +31 -0
  10. data/example/extend_views/login.haml +21 -0
  11. data/example/extend_views/show.haml +9 -0
  12. data/example/extend_views/signup.haml +30 -0
  13. data/example/mm_app.rb +22 -0
  14. data/example/tc_app.rb +16 -0
  15. data/example/tc_sinbook.rb +62 -0
  16. data/lib/models/abstract_user.rb +54 -0
  17. data/lib/models/datamapper_user.rb +42 -0
  18. data/lib/models/dm_adapter.rb +50 -0
  19. data/lib/models/mm_adapter.rb +53 -0
  20. data/lib/models/mongomapper_user.rb +42 -0
  21. data/lib/models/rufus_tokyo_user.rb +177 -0
  22. data/lib/models/tc_adapter.rb +83 -0
  23. data/lib/sinatra-authentication.rb +290 -0
  24. data/lib/views/edit.haml +43 -0
  25. data/lib/views/index.haml +29 -0
  26. data/lib/views/login.haml +22 -0
  27. data/lib/views/show.haml +9 -0
  28. data/lib/views/signup.haml +26 -0
  29. data/readme.markdown +238 -0
  30. data/sinatra-authentication.gemspec +119 -0
  31. data/test/datamapper_test.rb +5 -0
  32. data/test/lib/dm_app.rb +20 -0
  33. data/test/lib/dm_extend_app.rb +27 -0
  34. data/test/lib/dm_sinbook.rb +55 -0
  35. data/test/lib/extend_views/edit.haml +42 -0
  36. data/test/lib/extend_views/index.haml +31 -0
  37. data/test/lib/extend_views/login.haml +21 -0
  38. data/test/lib/extend_views/show.haml +9 -0
  39. data/test/lib/extend_views/signup.haml +29 -0
  40. data/test/lib/helper.rb +9 -0
  41. data/test/lib/mm_app.rb +24 -0
  42. data/test/lib/tc_app.rb +16 -0
  43. data/test/lib/tc_sinbook.rb +62 -0
  44. data/test/mongomapper_test.rb +39 -0
  45. data/test/route_tests.rb +29 -0
  46. data/test/rufus_tokyo_test.rb +5 -0
  47. metadata +212 -0
@@ -0,0 +1,119 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sinatra-authentication}
8
+ s.version = "0.3.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Max Justus Spransy"]
12
+ s.date = %q{2010-06-14}
13
+ s.description = %q{Simple authentication plugin for sinatra.}
14
+ s.email = %q{maxjustus@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "TODO"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "History.txt",
21
+ "Manifest",
22
+ "Rakefile",
23
+ "TODO",
24
+ "example/dm_extend_app.rb",
25
+ "example/dm_sinbook.rb",
26
+ "example/extend_views/edit.haml",
27
+ "example/extend_views/index.haml",
28
+ "example/extend_views/login.haml",
29
+ "example/extend_views/show.haml",
30
+ "example/extend_views/signup.haml",
31
+ "example/mm_app.rb",
32
+ "example/tc_app.rb",
33
+ "example/tc_sinbook.rb",
34
+ "lib/models/abstract_user.rb",
35
+ "lib/models/datamapper_user.rb",
36
+ "lib/models/dm_adapter.rb",
37
+ "lib/models/mm_adapter.rb",
38
+ "lib/models/mongomapper_user.rb",
39
+ "lib/models/rufus_tokyo_user.rb",
40
+ "lib/models/tc_adapter.rb",
41
+ "lib/sinatra-authentication.rb",
42
+ "lib/views/edit.haml",
43
+ "lib/views/index.haml",
44
+ "lib/views/login.haml",
45
+ "lib/views/show.haml",
46
+ "lib/views/signup.haml",
47
+ "readme.markdown",
48
+ "sinatra-authentication.gemspec",
49
+ "test/datamapper_test.rb",
50
+ "test/lib/dm_app.rb",
51
+ "test/lib/dm_extend_app.rb",
52
+ "test/lib/dm_sinbook.rb",
53
+ "test/lib/extend_views/edit.haml",
54
+ "test/lib/extend_views/index.haml",
55
+ "test/lib/extend_views/login.haml",
56
+ "test/lib/extend_views/show.haml",
57
+ "test/lib/extend_views/signup.haml",
58
+ "test/lib/helper.rb",
59
+ "test/lib/mm_app.rb",
60
+ "test/lib/tc_app.rb",
61
+ "test/lib/tc_sinbook.rb",
62
+ "test/mongomapper_test.rb",
63
+ "test/route_tests.rb",
64
+ "test/rufus_tokyo_test.rb"
65
+ ]
66
+ s.homepage = %q{http://github.com/maxjustus/sinatra-authentication}
67
+ s.rdoc_options = ["--charset=UTF-8"]
68
+ s.require_paths = ["lib"]
69
+ s.rubygems_version = %q{1.3.7}
70
+ s.summary = %q{Simple authentication plugin for sinatra.}
71
+ s.test_files = [
72
+ "test/lib/dm_sinbook.rb",
73
+ "test/lib/tc_app.rb",
74
+ "test/lib/mm_app.rb",
75
+ "test/lib/tc_sinbook.rb",
76
+ "test/lib/helper.rb",
77
+ "test/lib/dm_extend_app.rb",
78
+ "test/lib/dm_app.rb",
79
+ "test/datamapper_test.rb",
80
+ "test/mongomapper_test.rb",
81
+ "test/rufus_tokyo_test.rb",
82
+ "test/route_tests.rb"
83
+ ]
84
+
85
+ if s.respond_to? :specification_version then
86
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
87
+ s.specification_version = 3
88
+
89
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
90
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
91
+ s.add_runtime_dependency(%q<dm-core>, [">= 0"])
92
+ s.add_runtime_dependency(%q<dm-migrations>, [">= 0"])
93
+ s.add_runtime_dependency(%q<dm-validations>, [">= 0"])
94
+ s.add_runtime_dependency(%q<dm-timestamps>, [">= 0"])
95
+ s.add_runtime_dependency(%q<rufus-tokyo>, [">= 0"])
96
+ s.add_runtime_dependency(%q<sinbook>, [">= 0"])
97
+ s.add_runtime_dependency(%q<rack-flash>, [">= 0"])
98
+ else
99
+ s.add_dependency(%q<sinatra>, [">= 0"])
100
+ s.add_dependency(%q<dm-core>, [">= 0"])
101
+ s.add_dependency(%q<dm-migrations>, [">= 0"])
102
+ s.add_dependency(%q<dm-validations>, [">= 0"])
103
+ s.add_dependency(%q<dm-timestamps>, [">= 0"])
104
+ s.add_dependency(%q<rufus-tokyo>, [">= 0"])
105
+ s.add_dependency(%q<sinbook>, [">= 0"])
106
+ s.add_dependency(%q<rack-flash>, [">= 0"])
107
+ end
108
+ else
109
+ s.add_dependency(%q<sinatra>, [">= 0"])
110
+ s.add_dependency(%q<dm-core>, [">= 0"])
111
+ s.add_dependency(%q<dm-migrations>, [">= 0"])
112
+ s.add_dependency(%q<dm-validations>, [">= 0"])
113
+ s.add_dependency(%q<dm-timestamps>, [">= 0"])
114
+ s.add_dependency(%q<rufus-tokyo>, [">= 0"])
115
+ s.add_dependency(%q<sinbook>, [">= 0"])
116
+ s.add_dependency(%q<rack-flash>, [">= 0"])
117
+ end
118
+ end
119
+
@@ -0,0 +1,5 @@
1
+ require 'lib/dm_app'
2
+ require 'lib/helper'
3
+ require 'test/unit'
4
+ require 'rack/test'
5
+ require 'route_tests'
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'haml'
4
+ require 'dm-core'
5
+ require 'rack-flash'
6
+ require File.join(File.dirname(__FILE__), '../../lib/sinatra-authentication')
7
+
8
+ DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/test.db")
9
+ DataMapper.auto_migrate!
10
+
11
+ use Rack::Session::Cookie, :secret => "heyhihello"
12
+ use Rack::Flash
13
+
14
+ set :environment, 'development'
15
+ set :public, 'public'
16
+ set :views, 'views'
17
+
18
+ get '/' do
19
+ haml "= render_login_logout", :layout => :layout
20
+ end
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'haml'
4
+ require 'dm-core'
5
+ require 'rack-flash'
6
+ require File.join(File.dirname(__FILE__), '../../lib/sinatra-authentication')
7
+
8
+
9
+ class DmUser
10
+ property :name, String
11
+ end
12
+
13
+ DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/test.db")
14
+ DataMapper.auto_migrate!
15
+
16
+ set :sinatra_authentication_view_path, Pathname(__FILE__).dirname.expand_path + "extend_views/"
17
+ use Rack::Session::Cookie, :secret => "heyhihello"
18
+ use Rack::Flash
19
+
20
+ set :environment, 'development'
21
+ set :public, 'public'
22
+ set :views, 'views'
23
+
24
+ get '/' do
25
+ puts User.all(:name => 'max')
26
+ haml "= render_login_logout", :layout => :layout
27
+ end
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'haml'
4
+ require 'sinbook'
5
+ require 'dm-core'
6
+ require File.join(File.dirname(__FILE__), '../../lib/sinatra-authentication')
7
+
8
+ facebook do
9
+ api_key 'aa2db1b96cb7b57f0c5b1d4d3d8f0a22'
10
+ secret '21d94ee63969ae3b3f833689838ca00f'
11
+ app_id 48652736613
12
+ url 'peoplewithjetpacks.com:4568/'
13
+ callback 'peoplewithjetpacks.com:4568/'
14
+ end
15
+
16
+ set :port, 4568
17
+
18
+ DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/test.db")
19
+ DataMapper.auto_migrate!
20
+
21
+ use Rack::Session::Cookie, :secret => "heyhihello"
22
+
23
+ set :environment, 'development'
24
+ set :public, 'public'
25
+ set :views, 'views'
26
+
27
+ get '/' do
28
+ haml :main
29
+ end
30
+
31
+ get '/test' do
32
+ login_required
33
+ 'hihihi'
34
+ end
35
+
36
+ __END__
37
+
38
+ @@ layout
39
+ %html{:xmlns=>"http://www.w3.org/1999/xhtml", :'xmlns:fb'=>"http://www.facebook.com/2008/fbml"}
40
+ %head
41
+ %title Welcome to my Facebook Connect website!
42
+ %script{:type => 'text/javascript', :src => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US'}
43
+ %body
44
+ = render_login_logout
45
+ = yield
46
+ :javascript
47
+ FB.init("#{fb.api_key}", "/receiver")
48
+
49
+ @@ main
50
+ - if fb[:user]
51
+ Hi,
52
+ %fb:profile-pic{:uid => fb[:user]}
53
+ %fb:name{:uid => fb[:user], :useyou => 'false', :firstnameonly => 'true'}
54
+ !
55
+
@@ -0,0 +1,42 @@
1
+ #sinatra_authentication
2
+ #sinatra_authentication_flash= session[:flash]
3
+ %h1
4
+ Edit
5
+ - if @user.id == current_user.id
6
+ account
7
+ - else
8
+ - if @user.email
9
+ = @user.email
10
+ - elsif @user.fb_uid
11
+ <fb:name uid=#{@user.fb_uid} linked='false' />
12
+ - else
13
+ account
14
+ %form{:action => "/users/#{@user.id}/edit", :method => "post"}
15
+ .field
16
+ .label
17
+ %label{:for => "user_email"} Email
18
+ %input{ :id => "user_email", :name => "user[email]", :size => 30, :type => "text", :value => @user.email }
19
+ .field
20
+ .label
21
+ %label{:for => "user_password"} New password
22
+ %input{ :id => "user_password", :name => "user[password]", :size => 30, :type => "password" }
23
+ .field
24
+ .label
25
+ %label{:for => "user_password_confirmation"} Confirm
26
+ %input{ :id => "user_password_confirmation", :name => "user[password_confirmation]", :size => 30, :type => "password" }
27
+ -# don't render permission field if admin and editing yourself so you don't shoot yourself in the foot
28
+ - if current_user.admin? && current_user.id != @user.id
29
+ .field
30
+ .label
31
+ %label{:for => 'permission_level'} Permission level
32
+ %select{ :id => "permission_level", :name => "user[permission_level]" }
33
+ %option{:value => -1, :selected => @user.admin?}
34
+ Admin
35
+ %option{:value => 1, :selected => @user.permission_level == 1}
36
+ Authenticated user
37
+ .buttons
38
+ %input{ :value => "Update", :type => "submit" }
39
+ - if Sinatra.const_defined?('FacebookObject')
40
+ - unless @user.fb_uid
41
+ |
42
+ = render_facebook_connect_link('Link account with Facebook')
@@ -0,0 +1,31 @@
1
+ #sinatra_authentication
2
+ %h1.page_title Users
3
+ %table
4
+ %tr
5
+ %th
6
+ - if current_user.admin?
7
+ %th permission level
8
+ - @users.each do |user|
9
+ %tr
10
+ %td
11
+ - if user.email
12
+ = user.email
13
+ - elsif user.fb_uid
14
+ <fb:name uid=#{user.fb_uid} />
15
+ - else
16
+ "user #{user.id}"
17
+ - if current_user.admin?
18
+ %td= user.permission_level
19
+ %td
20
+ = user.name
21
+ %td
22
+ %a{:href => "/users/#{user.id}"} show
23
+ - if current_user.admin?
24
+ %td
25
+ %a{:href => "/users/#{user.id}/edit"} edit
26
+ %td
27
+ -# this doesn't work for tk
28
+ - if !user.site_admin?
29
+ %a{:href => "/users/#{user.id}/delete", :onclick => "return confirm('you sure?')"} delete
30
+ - else
31
+ site admin
@@ -0,0 +1,21 @@
1
+ #sinatra_authentication
2
+ #sinatra_authentication_flash= session[:flash]
3
+ %h1.page_title Login
4
+ %form{:action => "/login", :method => "post"}
5
+ .field
6
+ .label
7
+ %label{:for => "user_email'"} Email
8
+ %input{:id => "user_email", :name => "email", :size => 30, :type => "text"}
9
+ .field
10
+ .label
11
+ %label{:for => "user_password"} Password
12
+ %input{:id => "user_password", :name => "password", :size => 30, :type => "password"}
13
+ .buttons
14
+ %input{:value => "login", :type => "submit"}
15
+ %a{:href => "/signup", :class => 'sinatra_authentication_link'}
16
+ Signup
17
+ - if Sinatra.const_defined?('FacebookObject')
18
+ .third_party_signup
19
+ %h3.section_title One click login:
20
+ .login_link.facebook_login
21
+ = render_facebook_connect_link('Login using facebook', :size => 'large')
@@ -0,0 +1,9 @@
1
+ #sinatra_authentication
2
+ %h1.page_title
3
+ - if @user.email
4
+ = @user.email
5
+ - elsif @user.fb_uid
6
+ <fb:name uid=#{@user.fb_uid} linked='false' />
7
+ - if current_user.admin?
8
+ %h2 permission level
9
+ = @user.permission_level
@@ -0,0 +1,29 @@
1
+ #sinatra_authentication
2
+ #sinatra_authentication_flash= session[:flash]
3
+ %h1.page_title Signup
4
+ %form{:action => "/signup", :method => "post"}
5
+ .field
6
+ .label
7
+ %label{:for => "user_email"} Email
8
+ %input{ :id => "user_email", :name => "user[email]", :size => 30, :type => "text" }
9
+ .field
10
+ .label
11
+ %label{:for => "user_password"} Password
12
+ %input{ :id => "user_password", :name => "user[password]", :size => 30, :type => "password" }
13
+ .field
14
+ .label
15
+ %label{:for => "user_name"} Name
16
+ %input{ :id => "user_name", :name => "user[name]", :size => 30, :type => "text" }
17
+ .field
18
+ .label
19
+ %label{:for => "user_password_confirmation"} Confirm Password
20
+ %input{ :id => "user_password_confirmation", :name => "user[password_confirmation]", :size => 30, :type => "password" }
21
+ .buttons
22
+ %input{ :value => "Create account", :type => "submit" }
23
+ %a{:href => "/login", :class => 'sinatra_authentication_link'}
24
+ Login
25
+ - if Sinatra.const_defined?('FacebookObject')
26
+ .third_party_signup
27
+ %h3.section_title One click signup:
28
+ .login_link.facebook_login
29
+ = render_facebook_connect_link('Signup using facebook', :size => 'large')
@@ -0,0 +1,9 @@
1
+ class TestHelper
2
+ def self.gen_user
3
+ {'user[email]' => 'yodawg@gmail.com', 'user[password]' => 'password', 'user[password_confirmation]' => 'password'}
4
+ end
5
+ end
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'sinatra/base'
3
+ require 'haml'
4
+ require 'mongo_mapper'
5
+ require File.join(File.dirname(__FILE__), '../../lib/sinatra-authentication')
6
+
7
+ logger = Logger.new($stdout)
8
+ MongoMapper.connection = Mongo::Connection.new('db.mongohq.com', 27017, :logger => logger)
9
+ MongoMapper.database = "fdbk"
10
+ MongoMapper.database.authenticate(ENV['mongohq_user'], ENV['mongohq_pass'])
11
+
12
+ class TestApp < Sinatra::Base
13
+ use Rack::Session::Cookie, :secret => "heyhihello"
14
+
15
+ register Sinatra::LilAuthentication
16
+
17
+ set :environment, 'development'
18
+ set :public, 'public'
19
+ set :views, 'views'
20
+
21
+ get '/' do
22
+ haml "= render_login_logout", :layout => :layout
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'haml'
4
+ require 'rufus/tokyo'
5
+ require File.join(File.dirname(__FILE__), '../../lib/sinatra-authentication')
6
+
7
+ use Rack::Session::Cookie, :secret => "heyhihello"
8
+ TcUserTable.cabinet_path = File.dirname(__FILE__)
9
+
10
+ set :environment, 'development'
11
+ set :public, 'public'
12
+ set :views, 'views'
13
+
14
+ get '/' do
15
+ haml "= render_login_logout", :layout => :layout
16
+ end
@@ -0,0 +1,62 @@
1
+ require 'rubygems'
2
+ require 'haml'
3
+ require 'sinbook'
4
+ require 'rufus/tokyo'
5
+ require 'sinatra'
6
+ require File.join(File.dirname(__FILE__), '../../lib/sinatra-authentication')
7
+
8
+ use Rack::Session::Cookie, :secret => "heyhihello"
9
+ TcUserTable.cabinet_path = File.dirname(__FILE__)
10
+
11
+ facebook do
12
+ api_key 'aa2db1b96cb7b57f0c5b1d4d3d8f0a22'
13
+ secret '21d94ee63969ae3b3f833689838ca00f'
14
+ app_id 48652736613
15
+ url 'peoplewithjetpacks.com:4568/'
16
+ callback 'peoplewithjetpacks.com:4568/'
17
+ end
18
+
19
+ set :port, 4568
20
+
21
+ get '/' do
22
+ haml :main
23
+ end
24
+
25
+ get '/test' do
26
+ login_required
27
+ 'hihihi'
28
+ end
29
+
30
+ __END__
31
+
32
+ @@ layout
33
+ %html{:xmlns=>"http://www.w3.org/1999/xhtml", :'xmlns:fb'=>"http://www.facebook.com/2008/fbml"}
34
+ %head
35
+ %title Welcome to my Facebook Connect website!
36
+ %script{:type => 'text/javascript', :src => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US'}
37
+ %script{:type => 'text/javascript', :src => 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'}
38
+ :javascript
39
+ $(document).ready(function(){
40
+ /* test facebook crap works with ajax */
41
+ $('.sinatra-authentication-login').click(function(){
42
+ $.get($(this).attr('href'), {}, function(data){
43
+ $('#test_box').html(data);
44
+ });
45
+ return false;
46
+ });
47
+ });
48
+ %body
49
+ = render_login_logout
50
+ = yield
51
+ :javascript
52
+ FB.init("#{fb.api_key}", "/receiver")
53
+ #test_box
54
+
55
+ @@ main
56
+ - if fb[:user]
57
+ Hi,
58
+ %fb:profile-pic{:uid => fb[:user]}
59
+ %fb:name{:uid => fb[:user], :useyou => 'false', :firstnameonly => 'true'}
60
+ !
61
+ %br/
62
+