forked from nedludd/sinatra-authentication
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated readme, added examples, changed view path variable name
- Loading branch information
Max
committed
Apr 18, 2010
1 parent
b143f57
commit 2cf578e
Showing
13 changed files
with
377 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
require 'haml' | ||
require 'dm-core' | ||
require 'rack-flash' | ||
require 'sinatra-authentication' | ||
|
||
class DmUser | ||
property :name, String | ||
end | ||
|
||
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/test.db") | ||
DataMapper.auto_migrate! | ||
|
||
set :sinatra_authentication_view_path, Pathname(__FILE__).dirname.expand_path + "extend_views/" | ||
use Rack::Session::Cookie, :secret => "heyhihello" | ||
use Rack::Flash | ||
|
||
set :environment, 'development' | ||
set :public, 'public' | ||
set :views, 'views' | ||
|
||
get '/' do | ||
haml "= render_login_logout", :layout => :layout | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
require 'haml' | ||
require 'sinbook' | ||
require 'dm-core' | ||
require 'sinatra-authentication' | ||
|
||
facebook do | ||
api_key 'aa2db1b96cb7b57f0c5b1d4d3d8f0a22' | ||
secret '21d94ee63969ae3b3f833689838ca00f' | ||
app_id 48652736613 | ||
url 'peoplewithjetpacks.com:4568/' | ||
callback 'peoplewithjetpacks.com:4568/' | ||
end | ||
|
||
set :port, 4568 | ||
|
||
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/test.db") | ||
DataMapper.auto_migrate! | ||
|
||
use Rack::Session::Cookie, :secret => "heyhihello" | ||
|
||
set :environment, 'development' | ||
set :public, 'public' | ||
set :views, 'views' | ||
|
||
get '/' do | ||
haml :main | ||
end | ||
|
||
get '/test' do | ||
login_required | ||
'hihihi' | ||
end | ||
|
||
__END__ | ||
|
||
@@ layout | ||
%html{:xmlns=>"http://www.w3.org/1999/xhtml", :'xmlns:fb'=>"http://www.facebook.com/2008/fbml"} | ||
%head | ||
%title Welcome to my Facebook Connect website! | ||
%script{:type => 'text/javascript', :src => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US'} | ||
%body | ||
= render_login_logout | ||
= yield | ||
:javascript | ||
FB.init("#{fb.api_key}", "/receiver") | ||
|
||
@@ main | ||
- if fb[:user] | ||
Hi, | ||
%fb:profile-pic{:uid => fb[:user]} | ||
%fb:name{:uid => fb[:user], :useyou => 'false', :firstnameonly => 'true'} | ||
! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#sinatra_authentication | ||
#sinatra_authentication_flash= flash[:notice] | ||
%h1 | ||
Edit | ||
- if @user.id == current_user.id | ||
account | ||
- else | ||
- if @user.email | ||
= @user.email | ||
- elsif @user.fb_uid | ||
<fb:name uid=#{@user.fb_uid} linked='false' /> | ||
- else | ||
account | ||
%form{:action => "/users/#{@user.id}/edit", :method => "post"} | ||
.field | ||
.label | ||
%label{:for => "user_email"} Email | ||
%input{ :id => "user_email", :name => "user[email]", :size => 30, :type => "text", :value => @user.email } | ||
.field | ||
.label | ||
%label{:for => "user_password"} New password | ||
%input{ :id => "user_password", :name => "user[password]", :size => 30, :type => "password" } | ||
.field | ||
.label | ||
%label{:for => "user_password_confirmation"} Confirm | ||
%input{ :id => "user_password_confirmation", :name => "user[password_confirmation]", :size => 30, :type => "password" } | ||
-# don't render permission field if admin and editing yourself so you don't shoot yourself in the foot | ||
- if current_user.admin? && current_user.id != @user.id | ||
.field | ||
.label | ||
%label{:for => 'permission_level'} Permission level | ||
%select{ :id => "permission_level", :name => "user[permission_level]" } | ||
%option{:value => -1, :selected => @user.admin?} | ||
Admin | ||
%option{:value => 1, :selected => @user.permission_level == 1} | ||
Authenticated user | ||
.buttons | ||
%input{ :value => "Update", :type => "submit" } | ||
- if Sinatra.const_defined?('FacebookObject') | ||
- unless @user.fb_uid | ||
| | ||
= render_facebook_connect_link('Link account with Facebook') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#sinatra_authentication | ||
%h1.page_title Users | ||
%table | ||
%tr | ||
%th | ||
- if current_user.admin? | ||
%th permission level | ||
- @users.each do |user| | ||
%tr | ||
%td | ||
- if user.email | ||
= user.email | ||
- elsif user.fb_uid | ||
<fb:name uid=#{user.fb_uid} /> | ||
- else | ||
"user #{user.id}" | ||
- if current_user.admin? | ||
%td= user.permission_level | ||
%td | ||
= user.name | ||
%td | ||
%a{:href => "/users/#{user.id}"} show | ||
- if current_user.admin? | ||
%td | ||
%a{:href => "/users/#{user.id}/edit"} edit | ||
%td | ||
-# this doesn't work for tk | ||
- if !user.site_admin? | ||
%a{:href => "/users/#{user.id}/delete", :onclick => "return confirm('you sure?')"} delete | ||
- else | ||
site admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#sinatra_authentication | ||
#sinatra_authentication_flash= flash[:notice] | ||
%h1.page_title Login | ||
%form{:action => "/login", :method => "post"} | ||
.field | ||
.label | ||
%label{:for => "user_email'"} Email | ||
%input{:id => "user_email", :name => "email", :size => 30, :type => "text"} | ||
.field | ||
.label | ||
%label{:for => "user_password"} Password | ||
%input{:id => "user_password", :name => "password", :size => 30, :type => "password"} | ||
.buttons | ||
%input{:value => "login", :type => "submit"} | ||
%a{:href => "/signup", :class => 'sinatra_authentication_link'} | ||
Signup | ||
- if Sinatra.const_defined?('FacebookObject') | ||
.third_party_signup | ||
%h3.section_title One click login: | ||
.login_link.facebook_login | ||
= render_facebook_connect_link('Login using facebook', :size => 'large') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#sinatra_authentication | ||
%h1.page_title | ||
- if @user.email | ||
= @user.email | ||
- elsif @user.fb_uid | ||
<fb:name uid=#{@user.fb_uid} linked='false' /> | ||
- if current_user.admin? | ||
%h2 permission level | ||
= @user.permission_level |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
%h1 This view is overridden | ||
#sinatra_authentication | ||
#sinatra_authentication_flash= flash[:notice] | ||
%h1.page_title Signup | ||
%form{:action => "/signup", :method => "post"} | ||
.field | ||
.label | ||
%label{:for => "user_email"} Email | ||
%input{ :id => "user_email", :name => "user[email]", :size => 30, :type => "text" } | ||
.field | ||
.label | ||
%label{:for => "user_password"} Password | ||
%input{ :id => "user_password", :name => "user[password]", :size => 30, :type => "password" } | ||
.field | ||
.label | ||
%label{:for => "user_name"} Name | ||
%input{ :id => "user_name", :name => "user[name]", :size => 30, :type => "text" } | ||
.field | ||
.label | ||
%label{:for => "user_password_confirmation"} Confirm Password | ||
%input{ :id => "user_password_confirmation", :name => "user[password_confirmation]", :size => 30, :type => "password" } | ||
.buttons | ||
%input{ :value => "Create account", :type => "submit" } | ||
%a{:href => "/login", :class => 'sinatra_authentication_link'} | ||
Login | ||
- if Sinatra.const_defined?('FacebookObject') | ||
.third_party_signup | ||
%h3.section_title One click signup: | ||
.login_link.facebook_login | ||
= render_facebook_connect_link('Signup using facebook', :size => 'large') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'rubygems' | ||
require 'sinatra/base' | ||
require 'haml' | ||
require 'mongo_mapper' | ||
require 'sinatra-authentication' | ||
|
||
logger = Logger.new($stdout) | ||
MongoMapper.connection = Mongo::Connection.new('db.mongohq.com', 27017, :logger => logger) | ||
MongoMapper.database = "fdbk" | ||
MongoMapper.database.authenticate(ENV['mongohq_user'], ENV['mongohq_pass']) | ||
|
||
class TestApp < Sinatra::Base | ||
use Rack::Session::Cookie, :secret => "heyhihello" | ||
|
||
set :environment, 'development' | ||
set :public, 'public' | ||
set :views, 'views' | ||
|
||
get '/' do | ||
haml "= render_login_logout", :layout => :layout | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
require 'haml' | ||
require 'rufus/tokyo' | ||
require 'sinatra-authentication' | ||
|
||
use Rack::Session::Cookie, :secret => "heyhihello" | ||
TcUserTable.cabinet_path = File.dirname(__FILE__) | ||
|
||
set :environment, 'development' | ||
set :public, 'public' | ||
set :views, 'views' | ||
|
||
get '/' do | ||
haml "= render_login_logout", :layout => :layout | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require 'rubygems' | ||
require 'haml' | ||
require 'sinbook' | ||
require 'rufus/tokyo' | ||
require 'sinatra' | ||
require 'sinatra-authentication' | ||
|
||
use Rack::Session::Cookie, :secret => "heyhihello" | ||
TcUserTable.cabinet_path = File.dirname(__FILE__) | ||
|
||
facebook do | ||
api_key 'aa2db1b96cb7b57f0c5b1d4d3d8f0a22' | ||
secret '21d94ee63969ae3b3f833689838ca00f' | ||
app_id 48652736613 | ||
url 'peoplewithjetpacks.com:4568/' | ||
callback 'peoplewithjetpacks.com:4568/' | ||
end | ||
|
||
set :port, 4568 | ||
|
||
get '/' do | ||
haml :main | ||
end | ||
|
||
get '/test' do | ||
login_required | ||
'hihihi' | ||
end | ||
|
||
__END__ | ||
|
||
@@ layout | ||
%html{:xmlns=>"http://www.w3.org/1999/xhtml", :'xmlns:fb'=>"http://www.facebook.com/2008/fbml"} | ||
%head | ||
%title Welcome to my Facebook Connect website! | ||
%script{:type => 'text/javascript', :src => 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US'} | ||
%script{:type => 'text/javascript', :src => 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'} | ||
:javascript | ||
$(document).ready(function(){ | ||
/* test facebook crap works with ajax */ | ||
$('.sinatra-authentication-login').click(function(){ | ||
$.get($(this).attr('href'), {}, function(data){ | ||
$('#test_box').html(data); | ||
}); | ||
return false; | ||
}); | ||
}); | ||
%body | ||
= render_login_logout | ||
= yield | ||
:javascript | ||
FB.init("#{fb.api_key}", "/receiver") | ||
#test_box | ||
|
||
@@ main | ||
- if fb[:user] | ||
Hi, | ||
%fb:profile-pic{:uid => fb[:user]} | ||
%fb:name{:uid => fb[:user], :useyou => 'false', :firstnameonly => 'true'} | ||
! | ||
%br/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.