sinatra-authentication 0.0.5 → 0.1.0
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 +3 -1
- data/lib/models/datamapper_user.rb +6 -2
- data/lib/models/dm_adapter.rb +6 -0
- data/lib/models/rufus_tokyo_user.rb +39 -18
- data/lib/models/tc_adapter.rb +17 -7
- data/lib/sinatra-authentication.rb +67 -12
- data/lib/views/edit.haml +16 -1
- data/lib/views/index.haml +8 -2
- data/lib/views/login.haml +3 -0
- data/lib/views/show.haml +5 -2
- data/readme.markdown +45 -0
- data/sinatra-authentication.gemspec +87 -0
- data/test/lib/dm_app.rb +1 -1
- data/test/lib/dm_sinbook.rb +55 -0
- data/test/lib/tc_app.rb +1 -1
- data/test/lib/tc_sinbook.rb +62 -0
- metadata +17 -2
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
|
7
7
|
Jeweler::Tasks.new do |gemspec|
|
8
8
|
gemspec.name = 'sinatra-authentication'
|
9
|
-
gemspec.version = '0.0
|
9
|
+
gemspec.version = '0.1.0'
|
10
10
|
gemspec.description = "Simple authentication plugin for sinatra."
|
11
11
|
gemspec.summary = "Simple authentication plugin for sinatra."
|
12
12
|
gemspec.homepage = "http://github.com/maxjustus/sinatra-authentication"
|
@@ -17,7 +17,9 @@ begin
|
|
17
17
|
gemspec.add_dependency "dm-validations"
|
18
18
|
gemspec.add_dependency "dm-timestamps"
|
19
19
|
gemspec.add_dependency "rufus-tokyo"
|
20
|
+
gemspec.add_dependency "sinbook"
|
20
21
|
end
|
22
|
+
Jeweler::GemcutterTasks.new
|
21
23
|
rescue LoadError
|
22
24
|
puts "Jeweler (or a dependency) not available. Install it first!"
|
23
25
|
end
|
@@ -2,11 +2,14 @@ class DmUser
|
|
2
2
|
include DataMapper::Resource
|
3
3
|
|
4
4
|
property :id, Serial
|
5
|
-
property :email, String, :
|
5
|
+
property :email, String, :length => (5..40), :unique => true, :format => :email_address
|
6
6
|
property :hashed_password, String
|
7
|
-
property :salt, String
|
7
|
+
property :salt, String
|
8
8
|
property :created_at, DateTime
|
9
9
|
property :permission_level, Integer, :default => 1
|
10
|
+
if Sinatra.const_defined?('FacebookObject')
|
11
|
+
property :fb_uid, String
|
12
|
+
end
|
10
13
|
|
11
14
|
attr_accessor :password, :password_confirmation
|
12
15
|
#protected equievelant? :protected => true doesn't exist in dm 0.10.0
|
@@ -30,6 +33,7 @@ class DmUser
|
|
30
33
|
def site_admin?
|
31
34
|
self.id == 1
|
32
35
|
end
|
36
|
+
|
33
37
|
protected
|
34
38
|
|
35
39
|
def method_missing(m, *args)
|
data/lib/models/dm_adapter.rb
CHANGED
@@ -59,29 +59,50 @@ class TcUser
|
|
59
59
|
pk = attributes.delete(:pk) if attributes[:pk]
|
60
60
|
|
61
61
|
email_regexp = /(\A(\s*)\Z)|(\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z)/i
|
62
|
-
if
|
63
|
-
password
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
62
|
+
if attributes['email'] =~ email_regexp
|
63
|
+
if attributes['password'] == attributes.delete('password_confirmation') && attributes['password'] != nil
|
64
|
+
password = attributes.delete('password')
|
65
|
+
attributes.merge!({'salt' => User.random_string(10)}) if !attributes['salt']
|
66
|
+
attributes.merge!('hashed_password' => User.encrypt(password, attributes['salt']))
|
67
|
+
permission_level = attributes['permission_level'] ? attributes['permission_level'] : '1'
|
68
|
+
attributes.merge!('permission_level' => permission_level)
|
69
|
+
unless attributes['created_at']
|
70
|
+
attributes.merge!('created_at' => Time.now.to_s)
|
71
|
+
attributes.merge!('created_at_i' => Time.now.to_i.to_s)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
existing_user = TcUser.query do |q|
|
76
|
+
q.add 'email', :streq, attributes['email']
|
77
|
+
end[0]
|
78
|
+
|
79
|
+
if existing_user && existing_user['pk'] != attributes['pk']
|
80
|
+
return false
|
81
|
+
else
|
82
|
+
connection = TcUserTable.new
|
83
|
+
pk ||= connection.genuid.to_s
|
84
|
+
#site admin if their first
|
85
|
+
attributes.merge!({'permission_level' => '-2'}) if pk == '1'
|
86
|
+
result = connection[pk] = attributes
|
87
|
+
#might not need this in newer version of rufus
|
88
|
+
result.merge!({:pk => pk})
|
89
|
+
connection.close
|
90
|
+
self.new(result)
|
91
|
+
end
|
80
92
|
else
|
81
93
|
false
|
82
94
|
end
|
83
95
|
end
|
84
96
|
|
97
|
+
def self.set!(attributes)
|
98
|
+
connection = TcUserTable.new
|
99
|
+
pk = connection.genuid.to_s
|
100
|
+
result = connection[pk] = attributes
|
101
|
+
result.merge!({:pk => pk})
|
102
|
+
connection.close
|
103
|
+
self.new(result)
|
104
|
+
end
|
105
|
+
|
85
106
|
def self.delete(pk)
|
86
107
|
connection = TcUserTable.new
|
87
108
|
connection.delete(pk)
|
data/lib/models/tc_adapter.rb
CHANGED
@@ -19,16 +19,22 @@ module TcAdapter
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def get(hash)
|
22
|
-
|
23
|
-
if hash[:email]
|
24
|
-
result = TcUser.query do |q|
|
25
|
-
q.add 'email', :streq, hash[:email]
|
26
|
-
end[0]
|
27
|
-
#the zero is because this returns an array but get should return the first result
|
28
|
-
elsif hash[:id]
|
22
|
+
if hash[:id]
|
29
23
|
pk = hash[:id]
|
30
24
|
result = TcUser.get(pk)
|
25
|
+
else
|
26
|
+
result = TcUser.query do |q|
|
27
|
+
hash.each do |key, value|
|
28
|
+
q.add key.to_s, :streq, value.to_s
|
29
|
+
end
|
30
|
+
end[0]
|
31
31
|
end
|
32
|
+
#elsif hash[:email]
|
33
|
+
# result = TcUser.query do |q|
|
34
|
+
# q.add 'email', :streq, hash[:email]
|
35
|
+
# end[0]
|
36
|
+
#the zero is because this returns an array but get should return the first result
|
37
|
+
#end
|
32
38
|
|
33
39
|
if result
|
34
40
|
self.new result
|
@@ -49,6 +55,10 @@ module TcAdapter
|
|
49
55
|
end
|
50
56
|
end
|
51
57
|
|
58
|
+
def set!(attributes)
|
59
|
+
self.new TcUser.set!(attributes)
|
60
|
+
end
|
61
|
+
|
52
62
|
def delete(pk)
|
53
63
|
#true or false
|
54
64
|
!!TcUser.delete(pk)
|
@@ -34,10 +34,6 @@ module Sinatra
|
|
34
34
|
get '/users/:id' do
|
35
35
|
login_required
|
36
36
|
|
37
|
-
#INVESTIGATE
|
38
|
-
#
|
39
|
-
#WHY THE HECK WON'T GET RETURN ANYTHING?
|
40
|
-
#if I user User.get(params[:id]) it returns nil for some inexplicable reason
|
41
37
|
@user = User.get(:id => params[:id])
|
42
38
|
haml get_view_as_string("show.haml"), :layout => use_layout?
|
43
39
|
end
|
@@ -58,7 +54,13 @@ module Sinatra
|
|
58
54
|
post '/login' do
|
59
55
|
if user = User.authenticate(params[:email], params[:password])
|
60
56
|
session[:user] = user.id
|
61
|
-
|
57
|
+
if session[:return_to]
|
58
|
+
redirect_url = session[:return_to]
|
59
|
+
session[:return_to] = false
|
60
|
+
redirect redirect_url
|
61
|
+
else
|
62
|
+
redirect '/'
|
63
|
+
end
|
62
64
|
else
|
63
65
|
redirect '/login'
|
64
66
|
end
|
@@ -87,7 +89,7 @@ module Sinatra
|
|
87
89
|
|
88
90
|
get '/users/:id/edit' do
|
89
91
|
login_required
|
90
|
-
redirect "/users" unless current_user.admin? || current_user == params[:id]
|
92
|
+
redirect "/users" unless current_user.admin? || current_user.id.to_s == params[:id]
|
91
93
|
|
92
94
|
@user = User.get(:id => params[:id])
|
93
95
|
haml get_view_as_string("edit.haml"), :layout => use_layout?
|
@@ -95,7 +97,7 @@ module Sinatra
|
|
95
97
|
|
96
98
|
post '/users/:id/edit' do
|
97
99
|
login_required
|
98
|
-
redirect "/users" unless current_user.admin? || current_user == params[:id]
|
100
|
+
redirect "/users" unless current_user.admin? || current_user.id.to_s == params[:id]
|
99
101
|
|
100
102
|
user = User.get(:id => params[:id])
|
101
103
|
user_attributes = params[:user]
|
@@ -105,15 +107,16 @@ module Sinatra
|
|
105
107
|
end
|
106
108
|
|
107
109
|
if user.update(user_attributes)
|
108
|
-
redirect
|
110
|
+
redirect '/'
|
109
111
|
else
|
110
|
-
|
112
|
+
session[:notice] = 'whoops, looks like there were some problems with your updates'
|
113
|
+
redirect "/users/#{user.id}/edit"
|
111
114
|
end
|
112
115
|
end
|
113
116
|
|
114
117
|
get '/users/:id/delete' do
|
115
118
|
login_required
|
116
|
-
redirect "/users" unless current_user.admin? || current_user == params[:id]
|
119
|
+
redirect "/users" unless current_user.admin? || current_user.id.to_s == params[:id]
|
117
120
|
|
118
121
|
if User.delete(params[:id])
|
119
122
|
session[:flash] = "way to go, you deleted a user"
|
@@ -122,12 +125,46 @@ module Sinatra
|
|
122
125
|
end
|
123
126
|
redirect '/'
|
124
127
|
end
|
128
|
+
|
129
|
+
|
130
|
+
if Sinatra.const_defined?('FacebookObject')
|
131
|
+
get '/connect' do
|
132
|
+
if fb[:user]
|
133
|
+
if current_user.class != GuestUser
|
134
|
+
user = current_user
|
135
|
+
else
|
136
|
+
user = User.get(:fb_uid => fb[:user])
|
137
|
+
end
|
138
|
+
|
139
|
+
if user
|
140
|
+
if !user.fb_uid || user.fb_uid != fb[:user]
|
141
|
+
user.update :fb_uid => fb[:user]
|
142
|
+
end
|
143
|
+
session[:user] = user.id
|
144
|
+
else
|
145
|
+
user = User.set!(:fb_uid => fb[:user])
|
146
|
+
session[:user] = user.id
|
147
|
+
end
|
148
|
+
end
|
149
|
+
redirect '/'
|
150
|
+
end
|
151
|
+
|
152
|
+
get '/receiver' do
|
153
|
+
%[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
154
|
+
<html xmlns="http://www.w3.org/1999/xhtml" >
|
155
|
+
<body>
|
156
|
+
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script>
|
157
|
+
</body>
|
158
|
+
</html>]
|
159
|
+
end
|
160
|
+
end
|
125
161
|
end
|
126
162
|
end
|
127
163
|
|
128
164
|
module Helpers
|
129
165
|
def login_required
|
130
|
-
if
|
166
|
+
#not as efficient as checking the session. but this inits the fb_user if they are logged in
|
167
|
+
if current_user.class != GuestUser
|
131
168
|
return true
|
132
169
|
else
|
133
170
|
session[:return_to] = request.fullpath
|
@@ -176,7 +213,15 @@ module Sinatra
|
|
176
213
|
# a tad janky?
|
177
214
|
logout_parameters.delete(:rel)
|
178
215
|
result += "<a href='/users/#{current_user.id}/edit' class='#{css_classes} sinatra-authentication-edit' #{parameters}>edit account</a> "
|
179
|
-
|
216
|
+
if Sinatra.const_defined?('FacebookObject')
|
217
|
+
if fb[:user]
|
218
|
+
result += "<a href='javascript:FB.Connect.logoutAndRedirect(\"/logout\");' class='#{css_classes} sinatra-authentication-logout' #{logout_parameters}>logout</a>"
|
219
|
+
else
|
220
|
+
result += "<a href='/logout' class='#{css_classes} sinatra-authentication-logout' #{logout_parameters}>logout</a>"
|
221
|
+
end
|
222
|
+
else
|
223
|
+
result += "<a href='/logout' class='#{css_classes} sinatra-authentication-logout' #{logout_parameters}>logout</a>"
|
224
|
+
end
|
180
225
|
else
|
181
226
|
result += "<a href='/signup' class='#{css_classes} sinatra-authentication-signup' #{parameters}>signup</a> "
|
182
227
|
result += "<a href='/login' class='#{css_classes} sinatra-authentication-login' #{parameters}>login</a>"
|
@@ -184,6 +229,16 @@ module Sinatra
|
|
184
229
|
|
185
230
|
result += "</div>"
|
186
231
|
end
|
232
|
+
|
233
|
+
if Sinatra.const_defined?('FacebookObject')
|
234
|
+
def render_facebook_connect_link(text = 'Login using facebook')
|
235
|
+
%[<a href="#" onclick="FB.Connect.requireSession(function(){document.location = '/connect';}); return false;" class="fbconnect_login_button FBConnectButton FBConnectButton_Small">
|
236
|
+
<span id="RES_ID_fb_login_text" class="FBConnectButton_Text">
|
237
|
+
#{text}
|
238
|
+
</span>
|
239
|
+
</a>]
|
240
|
+
end
|
241
|
+
end
|
187
242
|
end
|
188
243
|
|
189
244
|
register LilAuthentication
|
data/lib/views/edit.haml
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
#sinatra_authentication
|
2
2
|
%h1
|
3
3
|
Editing
|
4
|
-
|
4
|
+
- if @user.id == current_user.id
|
5
|
+
account
|
6
|
+
- else
|
7
|
+
- if @user.email
|
8
|
+
= @user.email
|
9
|
+
- elsif @user.fb_uid
|
10
|
+
<fb:name uid=#{@user.fb_uid} linked='false' />
|
11
|
+
- else
|
12
|
+
account
|
5
13
|
%form{:action => "/users/#{@user.id}/edit", :method => "post"}
|
14
|
+
%input{ :id => "user_email", :name => "user[email]", :size => 30, :type => "text", :value => @user.email }
|
15
|
+
email
|
16
|
+
%br
|
6
17
|
%input{ :id => "user_password", :name => "user[password]", :size => 30, :type => "password" }
|
7
18
|
new password
|
8
19
|
%br
|
@@ -19,3 +30,7 @@
|
|
19
30
|
permission level
|
20
31
|
%br
|
21
32
|
%input{ :value => "update", :type => "submit" }
|
33
|
+
- if Sinatra.const_defined?('FacebookObject')
|
34
|
+
- unless @user.fb_uid
|
35
|
+
|
|
36
|
+
= render_facebook_connect_link('Link account with facebook')
|
data/lib/views/index.haml
CHANGED
@@ -2,12 +2,18 @@
|
|
2
2
|
%h1 Users
|
3
3
|
%table
|
4
4
|
%tr
|
5
|
-
%th
|
5
|
+
%th
|
6
6
|
- if current_user.admin?
|
7
7
|
%th permission level
|
8
8
|
- @users.each do |user|
|
9
9
|
%tr
|
10
|
-
%td
|
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}"
|
11
17
|
- if current_user.admin?
|
12
18
|
%td= user.permission_level
|
13
19
|
%td
|
data/lib/views/login.haml
CHANGED
data/lib/views/show.haml
CHANGED
data/readme.markdown
CHANGED
@@ -28,6 +28,11 @@ with a super secret key, like so:
|
|
28
28
|
* get/post '/users/:id/edit'
|
29
29
|
* get '/users/:id/delete'
|
30
30
|
|
31
|
+
## ADDITIONAL ROUTES WHEN USING SINBOOK FOR FACEBOOK INTEGRATION:
|
32
|
+
|
33
|
+
* get '/reciever'
|
34
|
+
* get '/connect'
|
35
|
+
|
31
36
|
If you fetch any of the user pages using ajax, they will automatically render without a layout
|
32
37
|
|
33
38
|
## HELPER METHODS:
|
@@ -90,3 +95,43 @@ and if you want to open a connection with the cabinet directly, you can do somet
|
|
90
95
|
q.add 'email', :strinc, 'gmail'
|
91
96
|
end
|
92
97
|
user_connection.close
|
98
|
+
|
99
|
+
## FACEBOOK
|
100
|
+
|
101
|
+
# at present, sinatra authentication supports sinbook for interacting with the facebook api.
|
102
|
+
|
103
|
+
If you want to allow users to login using facebook, just require 'sinbook' before requiring 'sinatra-authentication'.
|
104
|
+
The routes '/reciever' and '/connect' will be added. as well as connect links on the login and edit account pages.
|
105
|
+
You'll still have to include and initialize the facebook connect javascript in your layout yourself, like so:
|
106
|
+
|
107
|
+
(This example layout assumes you're using sinbook)
|
108
|
+
|
109
|
+
!!!
|
110
|
+
%head
|
111
|
+
%title Welcome to my Facebook Connect website!
|
112
|
+
%script{:type => 'text/javascript', :src => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US'}
|
113
|
+
%body
|
114
|
+
= yield
|
115
|
+
:javascript
|
116
|
+
FB.init("#{fb.api_key}", "/receiver")
|
117
|
+
|
118
|
+
Just remember to specify '/reciever' as the path to the xd-receiver file in your call to 'FB.init'.
|
119
|
+
|
120
|
+
The render_login_logout helper 'logout' link will log the user out of facebook and your app.
|
121
|
+
|
122
|
+
I've also included a little helper method 'render_facebook_connect_link' for rendering the facebook connect link with the correct 'onconnect' javascript callback.
|
123
|
+
The callback redirects to '/connect' which is important because the way I've implemented facebook connect support is by pinging '/connect' after the user
|
124
|
+
successfully connects with facebook. If you choose to render the connect button yourself, be sure to have the 'onconnect' callback include "window.location = '/connect'".
|
125
|
+
'/connect' redirects to '/' on completion.
|
126
|
+
|
127
|
+
The 'render_facebook_connect_link' helper uses html instead of fbml, so ajax requests to '/login' or "/users/#{user.id}/edit"
|
128
|
+
will render the connect link without you needing to parse any fbml.
|
129
|
+
|
130
|
+
If the user is already logged into the app and connects with facebook via the user edit page,
|
131
|
+
it adds their fb_uid to their profile in the database.
|
132
|
+
which will allow them to log in using their email and password, OR their facebook account.
|
133
|
+
|
134
|
+
If they aren't already logged in to the app through the normal login form,
|
135
|
+
it creates a new user in the database without an email address or password.
|
136
|
+
They can later add this data by going to "/users/#{current_user.id}/edit",
|
137
|
+
which will allow them to log in using their email address and password, OR their facebook account.
|
@@ -0,0 +1,87 @@
|
|
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.1.0"
|
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{2009-11-27}
|
13
|
+
s.description = %q{Simple authentication plugin for sinatra.}
|
14
|
+
s.email = %q{maxjustus@gmail.com}
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"History.txt",
|
18
|
+
"Manifest",
|
19
|
+
"Rakefile",
|
20
|
+
"TODO",
|
21
|
+
"lib/models/abstract_user.rb",
|
22
|
+
"lib/models/datamapper_user.rb",
|
23
|
+
"lib/models/dm_adapter.rb",
|
24
|
+
"lib/models/rufus_tokyo_user.rb",
|
25
|
+
"lib/models/tc_adapter.rb",
|
26
|
+
"lib/sinatra-authentication.rb",
|
27
|
+
"lib/views/edit.haml",
|
28
|
+
"lib/views/index.haml",
|
29
|
+
"lib/views/login.haml",
|
30
|
+
"lib/views/show.haml",
|
31
|
+
"lib/views/signup.haml",
|
32
|
+
"readme.markdown",
|
33
|
+
"sinatra-authentication.gemspec",
|
34
|
+
"test/datamapper_test.rb",
|
35
|
+
"test/lib/dm_app.rb",
|
36
|
+
"test/lib/dm_sinbook.rb",
|
37
|
+
"test/lib/helper.rb",
|
38
|
+
"test/lib/tc_app.rb",
|
39
|
+
"test/lib/tc_sinbook.rb",
|
40
|
+
"test/route_tests.rb",
|
41
|
+
"test/rufus_tokyo_test.rb"
|
42
|
+
]
|
43
|
+
s.homepage = %q{http://github.com/maxjustus/sinatra-authentication}
|
44
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
s.rubygems_version = %q{1.3.5}
|
47
|
+
s.summary = %q{Simple authentication plugin for sinatra.}
|
48
|
+
s.test_files = [
|
49
|
+
"test/lib/dm_sinbook.rb",
|
50
|
+
"test/lib/tc_app.rb",
|
51
|
+
"test/lib/tc_sinbook.rb",
|
52
|
+
"test/lib/helper.rb",
|
53
|
+
"test/lib/dm_app.rb",
|
54
|
+
"test/datamapper_test.rb",
|
55
|
+
"test/rufus_tokyo_test.rb",
|
56
|
+
"test/route_tests.rb"
|
57
|
+
]
|
58
|
+
|
59
|
+
if s.respond_to? :specification_version then
|
60
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
61
|
+
s.specification_version = 3
|
62
|
+
|
63
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
64
|
+
s.add_runtime_dependency(%q<sinatra>, [">= 0"])
|
65
|
+
s.add_runtime_dependency(%q<dm-core>, [">= 0"])
|
66
|
+
s.add_runtime_dependency(%q<dm-validations>, [">= 0"])
|
67
|
+
s.add_runtime_dependency(%q<dm-timestamps>, [">= 0"])
|
68
|
+
s.add_runtime_dependency(%q<rufus-tokyo>, [">= 0"])
|
69
|
+
s.add_runtime_dependency(%q<sinbook>, [">= 0"])
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<sinatra>, [">= 0"])
|
72
|
+
s.add_dependency(%q<dm-core>, [">= 0"])
|
73
|
+
s.add_dependency(%q<dm-validations>, [">= 0"])
|
74
|
+
s.add_dependency(%q<dm-timestamps>, [">= 0"])
|
75
|
+
s.add_dependency(%q<rufus-tokyo>, [">= 0"])
|
76
|
+
s.add_dependency(%q<sinbook>, [">= 0"])
|
77
|
+
end
|
78
|
+
else
|
79
|
+
s.add_dependency(%q<sinatra>, [">= 0"])
|
80
|
+
s.add_dependency(%q<dm-core>, [">= 0"])
|
81
|
+
s.add_dependency(%q<dm-validations>, [">= 0"])
|
82
|
+
s.add_dependency(%q<dm-timestamps>, [">= 0"])
|
83
|
+
s.add_dependency(%q<rufus-tokyo>, [">= 0"])
|
84
|
+
s.add_dependency(%q<sinbook>, [">= 0"])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
data/test/lib/dm_app.rb
CHANGED
@@ -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
|
+
|
data/test/lib/tc_app.rb
CHANGED
@@ -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
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-authentication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Justus Spransy
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-27 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -62,6 +62,16 @@ dependencies:
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: "0"
|
64
64
|
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: sinbook
|
67
|
+
type: :runtime
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
65
75
|
description: Simple authentication plugin for sinatra.
|
66
76
|
email: maxjustus@gmail.com
|
67
77
|
executables: []
|
@@ -88,10 +98,13 @@ files:
|
|
88
98
|
- lib/views/show.haml
|
89
99
|
- lib/views/signup.haml
|
90
100
|
- readme.markdown
|
101
|
+
- sinatra-authentication.gemspec
|
91
102
|
- test/datamapper_test.rb
|
92
103
|
- test/lib/dm_app.rb
|
104
|
+
- test/lib/dm_sinbook.rb
|
93
105
|
- test/lib/helper.rb
|
94
106
|
- test/lib/tc_app.rb
|
107
|
+
- test/lib/tc_sinbook.rb
|
95
108
|
- test/route_tests.rb
|
96
109
|
- test/rufus_tokyo_test.rb
|
97
110
|
has_rdoc: true
|
@@ -123,7 +136,9 @@ signing_key:
|
|
123
136
|
specification_version: 3
|
124
137
|
summary: Simple authentication plugin for sinatra.
|
125
138
|
test_files:
|
139
|
+
- test/lib/dm_sinbook.rb
|
126
140
|
- test/lib/tc_app.rb
|
141
|
+
- test/lib/tc_sinbook.rb
|
127
142
|
- test/lib/helper.rb
|
128
143
|
- test/lib/dm_app.rb
|
129
144
|
- test/datamapper_test.rb
|