Skip to content

Commit

Permalink
adding new config style
Browse files Browse the repository at this point in the history
  • Loading branch information
NoamB committed Apr 20, 2011
1 parent 3797b1f commit 619c191
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 73 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy
70 changes: 35 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@ GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.5)
actionpack (= 3.0.5)
actionmailer (3.0.7)
actionpack (= 3.0.7)
mail (~> 2.2.15)
actionpack (3.0.5)
activemodel (= 3.0.5)
activesupport (= 3.0.5)
actionpack (3.0.7)
activemodel (= 3.0.7)
activesupport (= 3.0.7)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.4)
i18n (~> 0.5.0)
rack (~> 1.2.1)
rack-mount (~> 0.6.13)
rack-mount (~> 0.6.14)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
activemodel (3.0.5)
activesupport (= 3.0.5)
activemodel (3.0.7)
activesupport (= 3.0.7)
builder (~> 2.1.2)
i18n (~> 0.4)
activerecord (3.0.5)
activemodel (= 3.0.5)
activesupport (= 3.0.5)
i18n (~> 0.5.0)
activerecord (3.0.7)
activemodel (= 3.0.7)
activesupport (= 3.0.7)
arel (~> 2.0.2)
tzinfo (~> 0.3.23)
activeresource (3.0.5)
activemodel (= 3.0.5)
activesupport (= 3.0.5)
activesupport (3.0.5)
addressable (2.2.4)
activeresource (3.0.7)
activemodel (= 3.0.7)
activesupport (= 3.0.7)
activesupport (3.0.7)
addressable (2.2.5)
arel (2.0.9)
bcrypt-ruby (2.1.4)
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
faraday (0.5.7)
faraday (0.6.1)
addressable (~> 2.2.4)
multipart-post (~> 1.1.0)
rack (< 2, >= 1.1.0)
i18n (0.5.0)
json (1.5.1)
mail (2.2.15)
mail (2.2.17)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
Expand All @@ -49,30 +49,30 @@ GEM
multi_json (0.0.5)
multipart-post (1.1.0)
oauth (0.4.4)
oauth2 (0.1.1)
faraday (~> 0.5.0)
oauth2 (0.4.0)
faraday (~> 0.6.0)
multi_json (~> 0.0.4)
polyglot (0.3.1)
rack (1.2.2)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
rails (3.0.5)
actionmailer (= 3.0.5)
actionpack (= 3.0.5)
activerecord (= 3.0.5)
activeresource (= 3.0.5)
activesupport (= 3.0.5)
rails (3.0.7)
actionmailer (= 3.0.7)
actionpack (= 3.0.7)
activerecord (= 3.0.7)
activeresource (= 3.0.7)
activesupport (= 3.0.7)
bundler (~> 1.0)
railties (= 3.0.5)
railties (3.0.5)
actionpack (= 3.0.5)
activesupport (= 3.0.5)
railties (= 3.0.7)
railties (3.0.7)
actionpack (= 3.0.7)
activesupport (= 3.0.7)
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.8.7)
sinatra (1.2.1)
sinatra (1.2.3)
rack (~> 1.1)
tilt (< 2.0, >= 1.2.2)
sorcery (0.3.1)
Expand All @@ -90,12 +90,12 @@ GEM
tilt (1.2.2)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.25)
tzinfo (0.3.26)

PLATFORMS
ruby

DEPENDENCIES
sinatra (>= 1.2.0)
sorcery (= 0.2.1)
sorcery (= 0.3.1)
sqlite3-ruby
17 changes: 1 addition & 16 deletions models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,5 @@ class User < ActiveRecord::Base
accepts_nested_attributes_for :authentications
validates_confirmation_of :password, :on => :create, :message => "should match confirmation"

activate_sorcery! do |config|
config.username_attribute_name = :email

config.user_activation_mailer = SorceryMailer

config.reset_password_mailer = SorceryMailer
config.reset_password_expiration_period = 10.minutes
config.reset_password_time_between_emails = nil

config.activity_timeout = 1.minutes

config.consecutive_login_retries_amount_limit = 10
config.login_lock_time_period = 2.minutes

config.authentications_class = Authentication
end
authenticates_with_sorcery!
end
25 changes: 3 additions & 22 deletions myapp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,11 @@

require File.join(File.dirname(__FILE__),'models','sorcery_mailer')

# models
# sorcery
require 'sorcery'
Sorcery::Controller::Config.submodules = [:user_activation, :http_basic_auth, :remember_me, :reset_password, :session_timeout, :brute_force_protection, :activity_logging, :external]
include Sorcery::Controller::Adapters::Sinatra
include Sorcery::Controller

Sinatra::Application.activate_sorcery! do |config|
config.session_timeout = 10.minutes
config.session_timeout_from_last_action = false

config.controller_to_realm_map = {"application" => "Application", "users" => "Users"}

config.external_providers = [:twitter, :facebook]
require_relative 'sorcery_config'

config.twitter.key = "eYVNBjBDi33aa9GkA3w"
config.twitter.secret = "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8"
config.twitter.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=twitter"
config.twitter.user_info_mapping = {:email => "screen_name"}

config.facebook.key = "34cebc81c08a521bc66e212f947d73ec"
config.facebook.secret = "5b458d179f61d4f036ee66a497ffbcd0"
config.facebook.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=facebook"
config.facebook.user_info_mapping = {:email => "name"}
end
# models
require File.join(File.dirname(__FILE__),'models','authentication')
require File.join(File.dirname(__FILE__),'models','user')

Expand Down
40 changes: 40 additions & 0 deletions sorcery_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Sorcery::Controller::Config.submodules = [:user_activation, :http_basic_auth, :remember_me, :reset_password, :session_timeout, :brute_force_protection, :activity_logging, :external]

Sorcery::Controller::Config.configure do |config|
config.session_timeout = 10.minutes
config.session_timeout_from_last_action = false

config.controller_to_realm_map = {"application" => "Application", "users" => "Users"}

config.external_providers = [:twitter, :facebook]

config.twitter.key = "eYVNBjBDi33aa9GkA3w"
config.twitter.secret = "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8"
config.twitter.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=twitter"
config.twitter.user_info_mapping = {:email => "screen_name"}

config.facebook.key = "34cebc81c08a521bc66e212f947d73ec"
config.facebook.secret = "5b458d179f61d4f036ee66a497ffbcd0"
config.facebook.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=facebook"
config.facebook.user_info_mapping = {:email => "name"}

config.user_config do |user|
user.username_attribute_name = :email

user.user_activation_mailer = SorceryMailer

user.reset_password_mailer = SorceryMailer
user.reset_password_expiration_period = 10.minutes
user.reset_password_time_between_emails = nil

user.activity_timeout = 1.minutes

user.consecutive_login_retries_amount_limit = 10
user.login_lock_time_period = 2.minutes

user.authentications_class = Authentication
end
end

include Sorcery::Controller::Adapters::Sinatra
include Sorcery::Controller

0 comments on commit 619c191

Please sign in to comment.