Permalink
Browse files

renamed plugin to a little more original name

  • Loading branch information...
1 parent 1efa7b2 commit 5fd1c29cfd665f98e993ee1a544da0c341b7b4ee @NoamB committed Jan 24, 2011
Showing with 410 additions and 410 deletions.
  1. +3 −3 README.rdoc
  2. +3 −3 Rakefile
  3. +1 −1 features/support/env.rb
  4. +0 −26 lib/simple_auth.rb
  5. +0 −18 lib/simple_auth/engine.rb
  6. +26 −0 lib/sorcery.rb
  7. +2 −2 lib/{simple_auth → sorcery}/controller.rb
  8. +3 −3 lib/{simple_auth → sorcery}/crypto_providers/aes256.rb
  9. +4 −4 lib/{simple_auth → sorcery}/crypto_providers/bcrypt.rb
  10. +2 −2 lib/{simple_auth → sorcery}/crypto_providers/md5.rb
  11. +2 −2 lib/{simple_auth → sorcery}/crypto_providers/sha1.rb
  12. +2 −2 lib/{simple_auth → sorcery}/crypto_providers/sha256.rb
  13. +2 −2 lib/{simple_auth → sorcery}/crypto_providers/sha512.rb
  14. +18 −0 lib/sorcery/engine.rb
  15. +18 −18 lib/{simple_auth → sorcery}/model.rb
  16. +7 −7 lib/{simple_auth → sorcery}/model/submodules/password_confirmation.rb
  17. +16 −16 lib/{simple_auth → sorcery}/model/submodules/password_encryption.rb
  18. +9 −9 lib/{simple_auth → sorcery}/model/submodules/password_reset.rb
  19. +5 −5 lib/{simple_auth → sorcery}/model/submodules/remember_me.rb
  20. +11 −11 lib/{simple_auth → sorcery}/model/submodules/user_activation.rb
  21. +1 −1 spec/Gemfile
  22. +2 −2 spec/Gemfile.lock
  23. +1 −1 spec/rails3/Gemfile
  24. +2 −2 spec/rails3/Gemfile.lock
  25. +1 −1 spec/rails3/app_root/app/mailers/{simple_auth_mailer.rb → sorcery_mailer.rb}
  26. +1 −1 spec/rails3/app_root/app/models/user.rb
  27. 0 spec/rails3/app_root/app/views/{simple_auth_mailer → sorcery_mailer}/activation_email.html.erb
  28. 0 spec/rails3/app_root/app/views/{simple_auth_mailer → sorcery_mailer}/activation_email.text.erb
  29. 0 ...rails3/app_root/app/views/{simple_auth_mailer → sorcery_mailer}/activation_success_email.html.erb
  30. 0 ...rails3/app_root/app/views/{simple_auth_mailer → sorcery_mailer}/activation_success_email.text.erb
  31. 0 spec/rails3/app_root/app/views/{simple_auth_mailer → sorcery_mailer}/reset_password_email.html.erb
  32. 0 spec/rails3/app_root/app/views/{simple_auth_mailer → sorcery_mailer}/reset_password_email.text.erb
  33. +11 −11 spec/rails3/application_controller_spec.rb
  34. +5 −5 spec/rails3/password_reset_spec.rb
  35. +3 −3 spec/rails3/remember_me_spec.rb
  36. +8 −8 spec/rails3/spec_helper.rb
  37. +13 −13 spec/rails3/user_activation_spec.rb
  38. +29 −29 spec/rails3/user_password_encryption_spec.rb
  39. +16 −16 spec/rails3/user_spec.rb
  40. +0 −182 spec/simple_auth_crypto_providers_spec.rb
  41. +182 −0 spec/sorcery_crypto_providers_spec.rb
  42. +1 −1 spec/spec_helper.rb
View
@@ -1,4 +1,4 @@
-= simple_auth
+= sorcery
Inspired by restful_authentication, Authlogic and Devise (in that order).
Crypto code taken almost unchanged from Authlogic.
@@ -8,11 +8,11 @@ Crypto code taken almost unchanged from Authlogic.
* Simple interface, but don't kill simplicity with syntactic sugar.
* Easy Configuration, customization and extending.
* Keep MVC cleanly separated - DB is for models, sessions are for controllers. Models stay unaware of sessions.
-* Minimal amounts of magic - keeps code easy to understand and maintain.
+* Magic, not voodoo.
* No generated code polluting the developer's code.
* No tons of configuration code needed to add to the User model or Controller
-== Contributing to simple_auth
+== Contributing to sorcery
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
View
@@ -11,10 +11,10 @@ require 'rake'
require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
- gem.name = "simple_auth"
- gem.homepage = "http://github.com/NoamB/simple_auth"
+ gem.name = "sorcery"
+ gem.homepage = "http://github.com/NoamB/sorcery"
gem.license = "MIT"
- gem.summary = "Simple authentication for Rails 3 applications"
+ gem.summary = "Magical authentication for Rails 3 applications"
gem.description = "Provides common authentication needs such as signing in/out, activating by email, resetting password and deleting accounts."
gem.email = "nbenari@gmail.com"
gem.authors = ["Noam"]
View
@@ -8,6 +8,6 @@
end
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
-require 'simple_auth'
+require 'sorcery'
require 'rspec/expectations'
View
@@ -1,26 +0,0 @@
-module SimpleAuth
- autoload :Model, 'simple_auth/model'
- module Model
- module Submodules
- autoload :PasswordConfirmation, 'simple_auth/model/submodules/password_confirmation'
- autoload :PasswordEncryption, 'simple_auth/model/submodules/password_encryption'
- autoload :UserActivation, 'simple_auth/model/submodules/user_activation'
- autoload :PasswordReset, 'simple_auth/model/submodules/password_reset'
- autoload :RememberMe, 'simple_auth/model/submodules/remember_me'
- end
- module Adapters
- autoload :ActiveRecord, 'simple_auth/model/adapters/active_record'
- end
- end
- autoload :Controller, 'simple_auth/controller'
- module CryptoProviders
- autoload :AES256, 'simple_auth/crypto_providers/aes256'
- autoload :BCrypt, 'simple_auth/crypto_providers/bcrypt'
- autoload :MD5, 'simple_auth/crypto_providers/md5'
- autoload :SHA1, 'simple_auth/crypto_providers/sha1'
- autoload :SHA256, 'simple_auth/crypto_providers/sha256'
- autoload :SHA512, 'simple_auth/crypto_providers/sha512'
- end
-
- require 'simple_auth/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
-end
View
@@ -1,18 +0,0 @@
-require 'simple_auth'
-require 'rails'
-
-module SimpleAuth
- # The SimpleAuth engine takes care of extending ActiveRecord (if used) and ActionController,
- # With the plugin logic.
- # ActionController is also automatically activated with the plugin to save you the trouble.
- class Engine < Rails::Engine
- initializer "extend Model with simple_auth" do |app|
- ActiveRecord::Base.send(:include, SimpleAuth::Model) if defined?(ActiveRecord)
- end
-
- initializer "extend Controller with simple_auth" do |app|
- ActionController::Base.send(:include, SimpleAuth::Controller)
- ActionController::Base.activate_simple_auth!
- end
- end
-end
View
@@ -0,0 +1,26 @@
+module Sorcery
+ autoload :Model, 'sorcery/model'
+ module Model
+ module Submodules
+ autoload :PasswordConfirmation, 'sorcery/model/submodules/password_confirmation'
+ autoload :PasswordEncryption, 'sorcery/model/submodules/password_encryption'
+ autoload :UserActivation, 'sorcery/model/submodules/user_activation'
+ autoload :PasswordReset, 'sorcery/model/submodules/password_reset'
+ autoload :RememberMe, 'sorcery/model/submodules/remember_me'
+ end
+ module Adapters
+ autoload :ActiveRecord, 'sorcery/model/adapters/active_record'
+ end
+ end
+ autoload :Controller, 'sorcery/controller'
+ module CryptoProviders
+ autoload :AES256, 'sorcery/crypto_providers/aes256'
+ autoload :BCrypt, 'sorcery/crypto_providers/bcrypt'
+ autoload :MD5, 'sorcery/crypto_providers/md5'
+ autoload :SHA1, 'sorcery/crypto_providers/sha1'
+ autoload :SHA256, 'sorcery/crypto_providers/sha256'
+ autoload :SHA512, 'sorcery/crypto_providers/sha512'
+ end
+
+ require 'sorcery/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
+end
@@ -1,4 +1,4 @@
-module SimpleAuth
+module Sorcery
module Controller
def self.included(klass)
klass.class_eval do
@@ -7,7 +7,7 @@ def self.included(klass)
end
module ClassMethods
- def activate_simple_auth!(*submodules)
+ def activate_sorcery!(*submodules)
Config.submodules = submodules
yield Config if block_given?
@@ -1,11 +1,11 @@
require "openssl"
-module SimpleAuth
+module Sorcery
module CryptoProviders
# This encryption method is reversible if you have the supplied key. So in order to use this encryption method you must supply it with a key first.
# In an initializer, or before your application initializes, you should do the following:
#
- # SimpleAuth::Model::ConfigAES256.key = "my 32 bytes long key"
+ # Sorcery::Model::ConfigAES256.key = "my 32 bytes long key"
#
# My final comment is that this is a strong encryption method, but its main weakness is that its reversible. If you do not need to reverse the hash
# then you should consider Sha512 or BCrypt instead.
@@ -35,7 +35,7 @@ def matches?(crypted, *tokens)
private
def aes
- raise ArgumentError.new("#{name} expects a 32 bytes long key. Please use SimpleAuth::Model::Config.encryption_key to set it.") if ( @key.nil? || @key == "" )
+ raise ArgumentError.new("#{name} expects a 32 bytes long key. Please use Sorcery::Model::Config.encryption_key to set it.") if ( @key.nil? || @key == "" )
@aes ||= OpenSSL::Cipher::Cipher.new("AES-256-ECB")
end
end
@@ -4,7 +4,7 @@
"sudo gem install bcrypt-ruby"
end
-module SimpleAuth
+module Sorcery
module CryptoProviders
# For most apps Sha512 is plenty secure, but if you are building an app that stores nuclear launch codes you might want to consier BCrypt. This is an extremely
# secure hashing algorithm, mainly because it is slow. A brute force attack on a BCrypt encrypted password would take much longer than a brute force attack on a
@@ -34,9 +34,9 @@ module CryptoProviders
#
# gem install bcrypt-ruby
#
- # Tell activate_simple_auth! to use it:
+ # Tell activate_sorcery! to use it:
#
- # activate_simple_auth! do |c|
+ # activate_sorcery! do |c|
# c.encryption_algorithm = :bcrypt
# end
#
@@ -62,7 +62,7 @@ def matches?(hash, *tokens)
hash == join_tokens(tokens)
end
- # This method is used as a flag to tell SimpleAuth to "resave" the password upon a successful login, using the new cost
+ # This method is used as a flag to tell Sorcery to "resave" the password upon a successful login, using the new cost
def cost_matches?(hash)
hash = new_from_hash(hash)
if hash.nil? || hash == {}
@@ -1,12 +1,12 @@
require "digest/md5"
-module SimpleAuth
+module Sorcery
module CryptoProviders
# This class was made for the users transitioning from md5 based systems.
# I highly discourage using this crypto provider as it superbly inferior
# to your other options.
#
- # Please use any other provider offered by SimpleAuth.
+ # Please use any other provider offered by Sorcery.
class MD5
class << self
attr_accessor :join_token
@@ -1,9 +1,9 @@
require "digest/sha1"
-module SimpleAuth
+module Sorcery
module CryptoProviders
# This class was made for the users transitioning from restful_authentication. I highly discourage using this
- # crypto provider as it inferior to your other options. Please use any other provider offered by SimpleAuth.
+ # crypto provider as it inferior to your other options. Please use any other provider offered by Sorcery.
class SHA1
class << self
def join_token
@@ -1,7 +1,7 @@
require "digest/sha2"
-module SimpleAuth
- # The activate_simple_auth method has a custom_crypto_provider configuration option. This allows you to use any type of encryption you like.
+module Sorcery
+ # The activate_sorcery method has a custom_crypto_provider configuration option. This allows you to use any type of encryption you like.
# Just create a class with a class level encrypt and matches? method. See example below.
#
# === Example
@@ -1,7 +1,7 @@
require "digest/sha2"
-module SimpleAuth
- # The activate_simple_auth method has a custom_crypto_provider configuration option. This allows you to use any type of encryption you like.
+module Sorcery
+ # The activate_sorcery method has a custom_crypto_provider configuration option. This allows you to use any type of encryption you like.
# Just create a class with a class level encrypt and matches? method. See example below.
#
# === Example
View
@@ -0,0 +1,18 @@
+require 'sorcery'
+require 'rails'
+
+module Sorcery
+ # The Sorcery engine takes care of extending ActiveRecord (if used) and ActionController,
+ # With the plugin logic.
+ # ActionController is also automatically activated with the plugin to save you the trouble.
+ class Engine < Rails::Engine
+ initializer "extend Model with sorcery" do |app|
+ ActiveRecord::Base.send(:include, Sorcery::Model) if defined?(ActiveRecord)
+ end
+
+ initializer "extend Controller with sorcery" do |app|
+ ActionController::Base.send(:include, Sorcery::Controller)
+ ActionController::Base.activate_sorcery!
+ end
+ end
+end
@@ -1,67 +1,67 @@
-module SimpleAuth
+module Sorcery
# This module handles all plugin operations which are related to the Model layer in the MVC pattern.
# It should be included into the ORM base class.
# In the case of Rails this is usually ActiveRecord (actually, in that case, the plugin does this automatically).
#
- # When included it defines a single method: 'activate_simple_auth!' which when called adds the other capabilities to the class.
+ # When included it defines a single method: 'activate_sorcery!' which when called adds the other capabilities to the class.
# This method is also the place to configure the plugin in the Model layer.
module Model
def self.included(klass)
klass.class_eval do
class << self
- def activate_simple_auth!
- @simple_auth_config = Config.new
+ def activate_sorcery!
+ @sorcery_config = Config.new
self.class_eval do
extend ClassMethods # included here, before submodules, so they can be overriden by them.
include InstanceMethods
- @simple_auth_config.submodules = ::SimpleAuth::Controller::Config.submodules
- @simple_auth_config.submodules.each do |mod|
+ @sorcery_config.submodules = ::Sorcery::Controller::Config.submodules
+ @sorcery_config.submodules.each do |mod|
include Submodules.const_get(mod.to_s.split("_").map {|p| p.capitalize}.join(""))
end
end
- yield @simple_auth_config if block_given?
+ yield @sorcery_config if block_given?
- @simple_auth_config.post_config_validations.each { |pcv| pcv.call(@simple_auth_config) }
+ @sorcery_config.post_config_validations.each { |pcv| pcv.call(@sorcery_config) }
end
end
end
end
module InstanceMethods
# Returns the class instance variable for configuration, when called by an instance.
- def simple_auth_config
- self.class.simple_auth_config
+ def sorcery_config
+ self.class.sorcery_config
end
protected
def generic_send_email(method)
- config = simple_auth_config
- mail = config.simple_auth_mailer.send(config.send(method),self)
- if defined?(ActionMailer) and config.simple_auth_mailer.superclass == ActionMailer::Base
+ config = sorcery_config
+ mail = config.sorcery_mailer.send(config.send(method),self)
+ if defined?(ActionMailer) and config.sorcery_mailer.superclass == ActionMailer::Base
mail.deliver
end
end
end
module ClassMethods
# Returns the class instance variable for configuration, when called by the class itself.
- def simple_auth_config
- @simple_auth_config
+ def sorcery_config
+ @sorcery_config
end
# The default authentication method.
# Takes a username and password,
# Finds the user by the username and compares the user's password to the one supplied to the method.
# returns the user if success, nil otherwise.
def authenticate(username, password)
- user = where("#{@simple_auth_config.username_attribute_name} = ?", username).first
- user if user && @simple_auth_config.pre_authenticate_validations.all? {|proc| proc.call(user, @simple_auth_config)} && (user.send(@simple_auth_config.password_attribute_name) == password)
+ user = where("#{@sorcery_config.username_attribute_name} = ?", username).first
+ user if user && @sorcery_config.pre_authenticate_validations.all? {|proc| proc.call(user, @sorcery_config)} && (user.send(@sorcery_config.password_attribute_name) == password)
end
end
- # Each class which calls 'activate_simple_auth!' receives an instance of this class.
+ # Each class which calls 'activate_sorcery!' receives an instance of this class.
# This enables two different classes to use this plugin with different configurations.
# Every submodule which gets loaded may add accessors to this class so that all options will be configure from a single place.
class Config
@@ -1,24 +1,24 @@
-module SimpleAuth
+module Sorcery
module Model
module Submodules
# This submodule adds the ability to verify that the user filled the password twice,
# and that both times were the same string.
module PasswordConfirmation
def self.included(base)
- # changes to the SimpleAuth::Model::Config class
- base.simple_auth_config.class_eval do
+ # changes to the Sorcery::Model::Config class
+ base.sorcery_config.class_eval do
attr_accessor :password_confirmation_attribute_name
end
- # changes to simple_auth_config class instance variable
- base.simple_auth_config.instance_eval do
+ # changes to sorcery_config class instance variable
+ base.sorcery_config.instance_eval do
@defaults.merge!(:@password_confirmation_attribute_name => :password_confirmation)
reset!
end
# changes to the actual model
base.class_eval do
- attr_accessor @simple_auth_config.password_confirmation_attribute_name
+ attr_accessor @sorcery_config.password_confirmation_attribute_name
validate :password_confirmed
end
@@ -29,7 +29,7 @@ module InstanceMethods
protected
def password_confirmed
- config = simple_auth_config
+ config = sorcery_config
if self.send(config.password_attribute_name) && self.send(config.password_attribute_name) != self.send(config.password_confirmation_attribute_name)
self.errors.add(:base,"password and password_confirmation do not match!")
end
Oops, something went wrong.

0 comments on commit 5fd1c29

Please sign in to comment.