challah 0.7.0.pre → 0.7.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,8 +6,6 @@ Challah (pronounced HAH-lah) is a simple Rails authentication gem that provides
6
6
 
7
7
  Challah doesn’t provide any fancy controllers or views that clutter your app or force you to display information a certain way. That part is up to you. The functionality within Challah is designed to be a starting point for users and sign-ins you can tweak the rest to your app’s needs.
8
8
 
9
- ** Note: As of challah v0.7.0, roles and permissions are maintained in a separate gem as part of [challah-rolls](http://github.com/jdtornow/challah). **
10
-
11
9
  ## Requirements
12
10
 
13
11
  * Ruby 1.9.2+
@@ -49,9 +47,9 @@ Use the following task to create a new user:
49
47
 
50
48
  ## Models
51
49
 
52
- Challah provides the core `User` model for your app, and a database migration to go along with it. You can customize the model to your app's specific needs, just leave the `authable_user` line intact.
50
+ Challah provides the core `User` model for your app, and a database migration to go along with it. You can customize the model to your app's specific needs, just leave the `challah_user` line intact.
53
51
 
54
- A user is anyone that needs to be able to authenticate (log in) to the application. Each user requires a first name, last name, email address, username, role and password.
52
+ A user is anyone that needs to be able to authenticate (sign in) to the application. Each user requires a first name, last name, email address, username, and password.
55
53
 
56
54
  By default a user is marked as “active” and is able to log in to your application. If the active status column is toggled to false, then this user is no longer able to log in. The active status column can be used as a soft-delete function for users.
57
55
 
@@ -59,11 +57,7 @@ By default a user is marked as “active” and is able to log in to your applic
59
57
 
60
58
  As of version 0.7.0 of Challah, permissions and roles have been moved to their own gem in [Challah Rolls](https://github.com/jdtornow/challah-rolls). Add this gem to your project to get additional functionality for permissions and role based restrictions.
61
59
 
62
- ## Restricted access
63
-
64
- One of the main reasons to use a user- and permission-based system is to restrict access to certain portions of your application. Challah provides basic restriction methods for your controllers, views and directly from any User instance.
65
-
66
- ### Checking for a current user
60
+ ## Checking for a current user
67
61
 
68
62
  The basic way to restrict functionality within your app is to require that someone authenticate (log in) before they can see it. From within your controllers and views you can call the `current_user?` method to determine if someone has authenticated. This method doesn’t care about who the user is, or what it has access to, just that it has successfully authenticated and is a valid user.
69
63
 
@@ -131,7 +125,7 @@ If necessary, the sessions controller which handles creating new sessions and si
131
125
 
132
126
  ## Full documentation
133
127
 
134
- Documentation is available at: [http://rubydoc.info/gems/challah](http://rubydoc.info/gems/challah/frames)
128
+ Documentation is available at: [http://rubydoc.info/gems/challah](http://rubydoc.info/gems/challah)
135
129
 
136
130
  ## Example App
137
131
 
data/app/models/user.rb CHANGED
@@ -5,7 +5,7 @@ class User < ActiveRecord::Base
5
5
  # For a list of all methods included into User, see:
6
6
  #
7
7
  # http://rubydoc.info/gems/challah
8
- authable_user
8
+ challah_user
9
9
 
10
10
  # Uncomment the following line to add additional attributes to protect using the
11
11
  # User#update_account_attributes(params) methods
@@ -38,7 +38,7 @@ module Challah
38
38
  if defined?(ActiveRecord)
39
39
  Challah.options[:logger] = ActiveRecord::Base.logger
40
40
 
41
- ActiveRecord::Base.send(:extend, Challah::AuthableUser)
41
+ ActiveRecord::Base.send(:extend, Challah::User)
42
42
  ActiveRecord::Base.send(:include, Challah::Audit)
43
43
  end
44
44
  end
@@ -47,7 +47,7 @@ module Challah
47
47
  persistence_token, user_id = self.store.read
48
48
  return false if persistence_token.nil? or user_id.nil?
49
49
 
50
- store_user = ::User.find_by_id(user_id)
50
+ store_user = Challah.user_model.find_by_id(user_id)
51
51
 
52
52
  if store_user and store_user.active? and store_user.persistence_token == persistence_token
53
53
  if store_user.valid_session?
@@ -103,7 +103,7 @@ module Challah
103
103
  class << self
104
104
  # Manually create a new Session
105
105
  def create(user_or_user_id, request = nil, params = nil)
106
- user_record = ::User === user_or_user_id ? user_or_user_id : ::User.find_by_id(user_or_user_id)
106
+ user_record = Challah.user_model === user_or_user_id ? user_or_user_id : Challah.user_model.find_by_id(user_or_user_id)
107
107
 
108
108
  session = Session.new(request, params)
109
109
 
@@ -11,7 +11,7 @@ module Challah
11
11
  return nil unless Challah.options[:api_key_enabled]
12
12
 
13
13
  unless @key.to_s.blank?
14
- user = ::User.find_by_api_key(@key)
14
+ user = Challah.user_model.find_by_api_key(@key)
15
15
 
16
16
  if user and user.active?
17
17
  return user
@@ -10,7 +10,7 @@ module Challah
10
10
  # if we can successfully authenticate, return a User instance, otherwise nil
11
11
  def authenticate
12
12
  if username? and password?
13
- user = ::User.find_for_session(username)
13
+ user = Challah.user_model.find_for_session(username)
14
14
 
15
15
  if user
16
16
  if user.active?
@@ -1,11 +1,14 @@
1
1
  module Challah
2
- module AuthableUser
3
- def authable_user
2
+ module User
3
+ def challah_user
4
4
  unless included_modules.include?(InstanceMethods)
5
5
  include InstanceMethods
6
6
  extend ClassMethods
7
7
  end
8
8
 
9
+ # Set the reference to the model name for challah_user
10
+ Challah.user_model = self
11
+
9
12
  class_eval do
10
13
  cattr_accessor :protected_attributes
11
14
 
@@ -87,7 +90,7 @@ module Challah
87
90
  end
88
91
  end
89
92
 
90
- # Instance methods to be included once authable_user is set up.
93
+ # Instance methods to be included once challah_user is set up.
91
94
  module InstanceMethods
92
95
  # Returns true if this user is active, and should be able to log in. If
93
96
  # the active column is false, the user will not be able to authenticate
@@ -216,7 +219,7 @@ module Challah
216
219
  # For backwards compatibilty, this column may not always exist, so just ignore
217
220
  # this if the column doesn't exist.
218
221
  def check_email_hash
219
- if User.column_names.include?("email_hash")
222
+ if self.class.column_names.include?("email_hash")
220
223
  if email_changed?
221
224
  require 'digest/md5'
222
225
  self.email_hash = Digest::MD5.hexdigest(self.email.to_s.downcase.strip)
@@ -1,3 +1,3 @@
1
1
  module Challah
2
- VERSION = "0.7.0.pre" unless defined?(::Challah::VERSION)
2
+ VERSION = "0.7.0.pre2" unless defined?(::Challah::VERSION)
3
3
  end
data/lib/challah.rb CHANGED
@@ -3,8 +3,6 @@ require 'challah/version'
3
3
  module Challah
4
4
  autoload :Audit, 'challah/audit'
5
5
 
6
- autoload :AuthableUser, 'challah/authable/user'
7
-
8
6
  autoload :CookieStore, 'challah/cookie_store'
9
7
  autoload :SimpleCookieStore, 'challah/simple_cookie_store'
10
8
 
@@ -14,8 +12,12 @@ module Challah
14
12
  autoload :Session, 'challah/session'
15
13
  autoload :Techniques, 'challah/techniques'
16
14
 
15
+ autoload :User, 'challah/user'
16
+
17
17
  # Configuration options
18
18
  class << self
19
+ attr_accessor :user_model
20
+
19
21
  # Get or set options for the current Challah instance. In most cases these should be
20
22
  # changed within a config/initializers/ file in your app.
21
23
  #
data/lib/tasks/crud.rake CHANGED
@@ -6,7 +6,7 @@ namespace :challah do
6
6
  task :create => :environment do
7
7
  check_for_tables
8
8
 
9
- first_user = User.count == 0
9
+ first_user = ::User.count == 0
10
10
 
11
11
  banner('Creating a user')
12
12
 
@@ -40,7 +40,7 @@ namespace :challah do
40
40
  end
41
41
  end
42
42
 
43
- user = User.new({
43
+ user = ::User.new({
44
44
  :first_name => first_name,
45
45
  :last_name => last_name,
46
46
  :email => email,
@@ -77,7 +77,7 @@ def check_for_roles
77
77
  end
78
78
 
79
79
  def check_for_tables
80
- unless User.table_exists?
80
+ unless ::User.table_exists?
81
81
  puts "Oops, you need to run `rake challah:setup` before you create a user. The users table is required."
82
82
  exit 1
83
83
  end
data/test/session_test.rb CHANGED
@@ -100,7 +100,7 @@ class SessionTest < ActiveSupport::TestCase
100
100
  should "validate with a password" do
101
101
  user = create(:user, :username => 'test-user')
102
102
 
103
- User.stubs(:find_for_session).returns(user)
103
+ ::User.stubs(:find_for_session).returns(user)
104
104
 
105
105
  session = Session.new
106
106
  session.ip = '127.0.0.1'
@@ -116,7 +116,7 @@ class SessionTest < ActiveSupport::TestCase
116
116
  assert_equal true, session.persist?
117
117
  assert_equal true, session.save
118
118
 
119
- User.unstub(:find_for_session)
119
+ ::User.unstub(:find_for_session)
120
120
  end
121
121
 
122
122
  should "validate with an api key" do
@@ -124,7 +124,7 @@ class SessionTest < ActiveSupport::TestCase
124
124
 
125
125
  user = create(:user, :api_key => '123456abcdefg')
126
126
 
127
- User.stubs(:find_for_session).returns(user)
127
+ ::User.stubs(:find_for_session).returns(user)
128
128
 
129
129
  session = Session.new
130
130
  session.ip = '127.0.0.1'
@@ -139,7 +139,7 @@ class SessionTest < ActiveSupport::TestCase
139
139
  assert_equal false, session.persist?
140
140
  assert_equal false, session.save
141
141
 
142
- User.unstub(:find_for_session)
142
+ ::User.unstub(:find_for_session)
143
143
 
144
144
  Challah.options[:api_key_enabled] = false
145
145
  end
@@ -147,7 +147,7 @@ class SessionTest < ActiveSupport::TestCase
147
147
  should "reject if password is incorrect" do
148
148
  user = create(:user, :username => 'test-user')
149
149
 
150
- User.stubs(:find_for_session).returns(user)
150
+ ::User.stubs(:find_for_session).returns(user)
151
151
 
152
152
  session = Session.new
153
153
  session.username = 'test-user'
@@ -158,7 +158,7 @@ class SessionTest < ActiveSupport::TestCase
158
158
  assert_equal false, session.valid?
159
159
  assert_equal nil, session.user
160
160
 
161
- User.unstub(:find_for_session)
161
+ ::User.unstub(:find_for_session)
162
162
  end
163
163
 
164
164
  should "have a default_path attribute" do
data/test/user_test.rb CHANGED
@@ -20,20 +20,20 @@ class UserTest < ActiveSupport::TestCase
20
20
  user_one = create(:user, :username => 'test-user', :email => 'tester@example.com')
21
21
  user_two = create(:user, :username => 'test-user-2', :email => 'tester2@example.com')
22
22
 
23
- assert_equal user_one, User.find_for_session('test-user')
24
- assert_equal user_one, User.find_for_session('tester@example.com')
23
+ assert_equal user_one, ::User.find_for_session('test-user')
24
+ assert_equal user_one, ::User.find_for_session('tester@example.com')
25
25
 
26
- assert_equal user_two, User.find_for_session('test-user-2')
27
- assert_equal user_two, User.find_for_session('tester2@example.com')
26
+ assert_equal user_two, ::User.find_for_session('test-user-2')
27
+ assert_equal user_two, ::User.find_for_session('tester2@example.com')
28
28
 
29
- assert_equal nil, User.find_for_session(' ')
30
- assert_equal nil, User.find_for_session('not-existing')
29
+ assert_equal nil, ::User.find_for_session(' ')
30
+ assert_equal nil, ::User.find_for_session('not-existing')
31
31
  end
32
32
 
33
33
  should "have protected attributes" do
34
- assert Array === User.protected_attributes
34
+ assert Array === ::User.protected_attributes
35
35
 
36
- assert_difference 'User.protected_attributes.size', 1 do
36
+ assert_difference '::User.protected_attributes.size', 1 do
37
37
  User.protect_attributes(:blah)
38
38
  end
39
39
  end
@@ -41,7 +41,7 @@ class UserTest < ActiveSupport::TestCase
41
41
 
42
42
  context "A user instance" do
43
43
  should "have a name attribute that returns the full name" do
44
- user = User.new
44
+ user = ::User.new
45
45
 
46
46
  user.stubs(:first_name).returns('Cal')
47
47
  user.stubs(:last_name).returns('Ripken')
@@ -51,12 +51,12 @@ class UserTest < ActiveSupport::TestCase
51
51
  end
52
52
 
53
53
  should "have a default_path where this user will be sent upon login" do
54
- user = User.new
54
+ user = ::User.new
55
55
  assert_equal '/', user.default_path
56
56
  end
57
57
 
58
58
  should "have an active? user flag" do
59
- user = User.new
59
+ user = ::User.new
60
60
 
61
61
  user.active = true
62
62
  assert_equal true, user.active
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: challah
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.pre
4
+ version: 0.7.0.pre2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-02 00:00:00.000000000Z
12
+ date: 2012-08-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline
16
- requirement: &70218459155120 !ruby/object:Gem::Requirement
16
+ requirement: &70303020485460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70218459155120
24
+ version_requirements: *70303020485460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70218459154600 !ruby/object:Gem::Requirement
27
+ requirement: &70303020484760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70218459154600
35
+ version_requirements: *70303020484760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70218459154040 !ruby/object:Gem::Requirement
38
+ requirement: &70303020483920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70218459154040
46
+ version_requirements: *70303020483920
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bcrypt-ruby
49
- requirement: &70218459153580 !ruby/object:Gem::Requirement
49
+ requirement: &70303020483340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70218459153580
57
+ version_requirements: *70303020483340
58
58
  description: A simple Rails engine gem for authentication, authorization, users, roles
59
59
  and permissions.
60
60
  email:
@@ -84,7 +84,6 @@ files:
84
84
  - test/simple_cookie_store_test.rb
85
85
  - test/user_test.rb
86
86
  - lib/challah/audit.rb
87
- - lib/challah/authable/user.rb
88
87
  - lib/challah/controller.rb
89
88
  - lib/challah/cookie_store.rb
90
89
  - lib/challah/encrypter.rb
@@ -97,6 +96,7 @@ files:
97
96
  - lib/challah/techniques/password_technique.rb
98
97
  - lib/challah/techniques.rb
99
98
  - lib/challah/test.rb
99
+ - lib/challah/user.rb
100
100
  - lib/challah/version.rb
101
101
  - lib/challah.rb
102
102
  - lib/tasks/crud.rake