Permalink
Browse files

merging new_config_style to master

  • Loading branch information...
NoamB committed Apr 21, 2011
2 parents 3ee1c96 + ac0026b commit 0dd2b35d765c81e17af5715b733ff09e54c7f607
View
@@ -17,4 +17,5 @@ group :development do
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.2"
gem 'simplecov', '>= 0.3.8', :require => false # Will install simplecov-html as a dependency
+ gem 'timecop'
end
View
@@ -109,6 +109,7 @@ GEM
simplecov-html (0.3.9)
sqlite3-ruby (1.3.2)
thor (0.14.6)
+ timecop (0.3.5)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.23)
@@ -129,4 +130,5 @@ DEPENDENCIES
ruby-debug19
simplecov (>= 0.3.8)
sqlite3-ruby
+ timecop
yard (~> 0.6.0)
View
@@ -33,6 +33,48 @@ Documentation: http://rubydoc.info/gems/sorcery/0.3.1/frames
Check out the tutorials in the github wiki!
+== API Summary
+
+
+Below is a summary of the library methods. Most method names are self explaining and the rest are commented:
+
+ # core
+ require_login # this is a before filter
+ login(username,password,remember_me = false)
+ logout
+ logged_in?
+ current_user
+ redirect_back_or_to # used when a user tries to access a page while logged out, is asked to login, and we want to return him back to the page he originally wanted.
+ @user.external? # external users, such as facebook/twitter etc.
+ User.authenticates_with_sorcery!
+
+ # activity logging
+ current_users
+
+ # http basic auth
+ require_login_from_http_basic # this is a before filter
+
+ # external
+ login_at(provider) # sends the user to an external service (twitter etc.) to authenticate.
+ login_from(provider) # tries to login from the external provider's callback.
+ create_from(provider) # create the user in the local app db.
+
+ # remember me
+ remember_me!
+ forget_me!
+
+ # reset password
+ User.load_from_reset_password_token(token)
+ @user.deliver_reset_password_instructions!
+ @user.reset_password!(params)
+
+ # user activation
+ User.load_from_activation_token(token)
+ @user.activate!
+
+Please see the tutorials in the github wiki for detailed usage information.
+
+
== Installation:
@@ -49,29 +91,15 @@ Otherwise simply
gem install sorcery
-== Configuration:
-
+== Rails 3 Configuration:
-1. config/application.rb
- config.sorcery.submodules = [:user_activation, :remember_me] # add the submodules you want to use
- # You can also configure here any controller and any controller-submodule option here. For example:
- config.sorcery.session_timeout = 10.minutes
+For Rails 3 create an initializer file using:
-2. app/models/user.rb (or another model of your choice, but a User class is assumed by default)
+ rake sorcery:bootstrap
- activate_sorcery! do |config|
- config.user_activation_mailer = MyMailer
- config.username_attribute_name = :email
- end
-
-3. app/controllers/application_controller.rb (OPTIONAL: this is actually needed only in some cases)
-
- activate_sorcery! do |config|
- config.session_timeout = 10.minutes
- end
-
-The configuration options vary with the submodules you've chosen to use, so check the documentation or the wiki tutorials regarding the specific submodule.
+This will create the file as config/initializers/sorcery.rb .
+Inside it the comments will tell you everything you need to know.
For your convenience, Sorcery includes a migrations generator for Rails, which can be used like so:
@@ -88,44 +116,30 @@ To generate migrations for both the core AND 'remember_me' submodule:
These migrations use the default fields. You can choose to use these migrations or make your own tables and fields. Sorcery tries not to impose a database structure and naming scheme on your application.
-== API Summary
-
-Below is a summary of the library methods. Most method names are self explaining and the rest are commented:
-
- # core
- require_login # this is a before filter
- login(username,password,remember_me = false)
- logout
- logged_in?
- current_user
- redirect_back_or_to # used when a user tries to access a page while logged out, is asked to login, and we want to return him back to the page he originally wanted.
- @user.external? # external users, such as facebook/twitter etc.
-
- # activity logging
- current_users
-
- # http basic auth
- require_login_from_http_basic # this is a before filter
+== Sinatra Configuration:
- # external
- login_at(provider) # sends the user to an external service (twitter etc.) to authenticate.
- login_from(provider) # tries to login from the external provider's callback.
- create_from(provider) # create the user in the local app db.
- # remember me
- remember_me!
- forget_me!
+For Sinatra you'll need to create the initializer manually. You can do it in the main app file or in a separate file you require (see example in example app). The code looks as follows:
- # reset password
- User.load_from_reset_password_token(token)
- @user.deliver_reset_password_instructions!
- @user.reset_password!(params)
+ Sorcery::Controller::Config.submodules = [] # specify here the submodules you want to include
+
+ Sorcery::Controller::Config.configure do |config|
+ config.session_timeout = 10.minutes
+ ...
+ ...
+
+ config.user_config do |user|
+ user.username_attribute_name = :email
+ ...
+ ...
+
+ end
+ end
- # user activation
- User.load_from_activation_token(token)
- @user.activate!
+Finally, to make all the code above take effect, we'll need to re-include the sorcery controller module:
-Please see the tutorials in the github wiki for detailed usage information.
+ include Sorcery::Controller::Adapters::Sinatra
+ include Sorcery::Controller
== Full Features List by module:
@@ -189,28 +203,43 @@ I've got many plans which include (by priority):
* Have an idea? Let me know, and it might get into the gem!
Other stuff:
+* Improve specs speed
+* Provide an easy way to run specs after install
* Improve documentation
* Tty to reduce the number of library methods, and find better names to some
+== Backward compatibility
+
+
+While the lib is young I'm breaking backward compatibility quite often.
+I'm constantly finding better ways to do things and throwing away old ways.
+To let you know when things are changing in a non-compatible way, I'm bumping the minor version of the gem.
+The patch version changes are backward compatible.
+
+In short, an app that works with 0.3.1 should be able to upgrade to 0.3.2 with no code changes.
+The same cannot be said about upgrading to 0.4.0 and above, however.
+
+
== Contributing to sorcery
Your feedback is very welcome and will make this gem much much better for you, me and everyone else.
Besides feedback on code, features, suggestions and bug reports, you may want to actually make an impact on the code.
For this:
-* Fork the project.
-* Make your feature addition or bug fix.
-* Add tests for it. I've used RSpec so far, please remain consistent with it.
-* Commit, do not mess with Rakefiles, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-* Send me a pull request. Bonus points for topic branches.
+* Fork it.
+* Fix it.
+* Test it.
+* Commit it.
+* Send me a pull request so I'll... Pull it.
-If you feel my work has made your life easier, and you would like to thank me through a donation, my paypal email is in the contact details.
+If you feel sorcery has made your life easier, and you would like to express your thanks via a donation, my paypal email is in the contact details.
== Contact
+
Feel free to ask questions using these contact details:
email: nbenari@gmail.com ( also for paypal )
View
@@ -41,11 +41,11 @@ end
require 'yard'
YARD::Rake::YardocTask.new
-desc 'Default: Run all specs.'
-task :default => :all_specs
+desc 'Default: Run all sorcery specs.'
+task :default => :all_sorcery_specs
-desc "Run all specs"
-task :all_specs do
+desc "Run all sorcery specs"
+task :all_sorcery_specs do
Dir['spec/**/Rakefile'].each do |rakefile|
directory_name = File.dirname(rakefile)
sh <<-CMD
View
@@ -2,7 +2,6 @@ module Sorcery
module Controller
def self.included(klass)
klass.class_eval do
- extend ClassMethods
include InstanceMethods
Config.submodules.each do |mod|
begin
@@ -11,19 +10,9 @@ def self.included(klass)
# don't stop on a missing submodule.
end
end
- Config.update!
- end
- end
-
- module ClassMethods
- def activate_sorcery!(&block)
- yield Config if block_given?
- after_config!
- end
-
- def after_config!
- Config.after_config.each {|c| send(c)}
end
+ Config.update!
+ Config.configure!
end
module InstanceMethods
@@ -126,7 +115,7 @@ module Config
class << self
attr_accessor :submodules,
- :user_class, # what class to use as the user class. Set automatically when you call activate_sorcery! in the User class.
+ :user_class, # what class to use as the user class. Set automatically when you call authenticates_with_sorcery! in the User class.
:not_authenticated_action, # what controller action to call for non-authenticated users.
@@ -137,9 +126,7 @@ class << self
:after_login,
:after_failed_login,
:before_logout,
- :after_logout,
- :after_config
-
+ :after_logout
def init!
@defaults = {
@@ -151,7 +138,6 @@ def init!
:@after_failed_login => [],
:@before_logout => [],
:@after_logout => [],
- :@after_config => [],
:@save_return_to_url => true
}
end
@@ -168,6 +154,18 @@ def update!
instance_variable_set(k,v) if !instance_variable_defined?(k)
end
end
+
+ def user_config(&blk)
+ block_given? ? @user_config = blk : @user_config
+ end
+
+ def configure(&blk)
+ @configure_blk = blk
+ end
+
+ def configure!
+ @configure_blk.call(self) if @configure_blk
+ end
end
init!
reset!
@@ -1,44 +0,0 @@
-# module Sorcery
-# module Controller
-# module Submodules
-# # This module allows you to authenticate to the site using a mail server.
-# # Let's say your organization is called blup, and everyone has someklutz@blup.com,
-# # Instead of registering a new username and password for an internal web application,
-# # why not simply reuse your email credentials?
-# # Of course this means that if the mail server is down, nobody can authenticate to your app.
-# # I might add a fallback for that in the future.
-# module Email
-# def self.included(base)
-# base.send(:include, InstanceMethods)
-# Config.module_eval do
-# class << self
-# attr_reader :email_protocols # email protocols like pop3, IMAP etc.
-#
-# def merge_mail_defaults!
-# @defaults.merge!(:@email_protocols => [])
-# end
-#
-# def email_protocols=(protocols)
-# protocols.each do |protocol|
-# include Protocols.const_get(protocol.to_s.split("_").map {|p| p.capitalize}.join(""))
-# end
-# end
-# end
-# merge_mail_defaults!
-# end
-# end
-#
-# module InstanceMethods
-# protected
-#
-# # sends user to authenticate at the provider's website.
-# # after authentication the user is redirected to the callback defined in the provider config
-# def login_at(protocol)
-#
-# end
-#
-# end
-# end
-# end
-# end
-# end
@@ -9,7 +9,7 @@ def self.included(base)
base.send(:include, InstanceMethods)
Config.module_eval do
class << self
- attr_accessor :controller_to_realm_map # how many failed logins allowed.
+ attr_accessor :controller_to_realm_map # What realm to display for which controller name.
def merge_http_basic_auth_defaults!
@defaults.merge!(:@controller_to_realm_map => {"application" => "Application"})
View
@@ -23,5 +23,9 @@ class Engine < Rails::Engine
end
end
+ rake_tasks do
+ load "sorcery/railties/tasks.rake"
+ end
+
end
end
Oops, something went wrong.

0 comments on commit 0dd2b35

Please sign in to comment.