thoughtbot-clearance 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -55,6 +55,12 @@ In test/unit/user_test.rb:
55
55
  include Clearance::UserTest
56
56
  end
57
57
 
58
+ In test/unit/user_mailer_test.rb:
59
+
60
+ class UserMailerTest < Test::Unit::TestCase
61
+ include Clearance::UserMailerTest
62
+ end
63
+
58
64
  In test/functional/sessions_controller_test.rb:
59
65
 
60
66
  class SessionsControllerTest < ActionController::TestCase
@@ -93,23 +99,18 @@ h2. User Model
93
99
  In app/models/user.rb:
94
100
 
95
101
  class User < ActiveRecord::Base
96
- include Clearance::Model
102
+ include Clearance::Models::User
97
103
  end
98
104
 
99
- h2. Mailer
105
+ h2. User Mailer
100
106
 
101
- In app/models/mailer.rb:
107
+ In app/models/user_mailer.rb:
102
108
 
103
- class Mailer < ActionMailer::Base
109
+ class UserMailer < ActionMailer::Base
104
110
 
105
111
  default_url_options[:host] = HOST
106
112
 
107
- def change_password(user)
108
- from "donotreply@example.com"
109
- recipients user.email
110
- subject "[YOUR APP] Request to change your password"
111
- body :user => user
112
- end
113
+ include Clearance::Mailers::User
113
114
 
114
115
  end
115
116
 
@@ -196,7 +197,7 @@ h2. Authors
196
197
 
197
198
  * thoughtbot, inc.
198
199
  * Dan Croak
200
+ * Jason Morrison
201
+ * Mike Burns
199
202
  * Josh Nichols
200
203
  * Mike Breen
201
- * Mike Burns
202
- * Jason Morrison
data/clearance.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "clearance"
3
- s.version = "0.1.8"
4
- s.date = "2008-10-09"
3
+ s.version = "0.1.9"
4
+ s.date = "2008-10-10"
5
5
  s.summary = "Simple, complete Rails authentication."
6
6
  s.email = "dcroak@thoughtbot.com"
7
7
  s.homepage = "http://github.com/thoughtbot/clearance"
@@ -11,7 +11,8 @@ Gem::Specification.new do |s|
11
11
  "clearance.gemspec",
12
12
  "lib/clearance.rb",
13
13
  "lib/clearance/app/controllers/application_controller.rb",
14
- "lib/clearance/app/models/model.rb",
14
+ "lib/clearance/app/models/user.rb",
15
+ "lib/clearance/app/models/user_mailer.rb",
15
16
  "lib/clearance/app/controllers/sessions_controller.rb",
16
17
  "lib/clearance/test/functionals/sessions_controller_test.rb",
17
18
  "lib/clearance/test/test_helper.rb",
@@ -0,0 +1,80 @@
1
+ module Clearance
2
+ module Models
3
+ module User
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+
8
+ attr_accessible :email, :password, :password_confirmation
9
+ attr_accessor :password, :password_confirmation
10
+
11
+ validates_presence_of :email
12
+ validates_presence_of :password, :if => :password_required?
13
+ validates_confirmation_of :password, :if => :password_required?
14
+ validates_uniqueness_of :email
15
+
16
+ before_save :initialize_salt, :encrypt_password
17
+
18
+ extend ClassMethods
19
+ include InstanceMethods
20
+
21
+ protected
22
+
23
+ include ProtectedInstanceMethods
24
+
25
+ end
26
+ end
27
+
28
+ module ClassMethods
29
+ def authenticate(email, password)
30
+ user = find_by_email email
31
+ user && user.authenticated?(password) ? user : nil
32
+ end
33
+ end
34
+
35
+ module InstanceMethods
36
+ def authenticated?(password)
37
+ crypted_password == encrypt(password)
38
+ end
39
+
40
+ def encrypt(password)
41
+ Digest::SHA1.hexdigest "--#{salt}--#{password}--"
42
+ end
43
+
44
+ def remember_token?
45
+ remember_token_expires_at && Time.now.utc < remember_token_expires_at
46
+ end
47
+
48
+ def remember_me!
49
+ remember_me_until 2.weeks.from_now.utc
50
+ end
51
+
52
+ def remember_me_until(time)
53
+ self.update_attribute :remember_token_expires_at, time
54
+ self.update_attribute :remember_token, encrypt("#{email}--#{remember_token_expires_at}")
55
+ end
56
+
57
+ def forget_me!
58
+ self.update_attribute :remember_token_expires_at, nil
59
+ self.update_attribute :remember_token, nil
60
+ end
61
+ end
62
+
63
+ module ProtectedInstanceMethods
64
+ def initialize_salt
65
+ self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{email}--") if new_record?
66
+ end
67
+
68
+ def encrypt_password
69
+ return if password.blank?
70
+ self.crypted_password = encrypt(password)
71
+ end
72
+
73
+ def password_required?
74
+ crypted_password.blank? || !password.blank?
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,23 @@
1
+ module Clearance
2
+ module Mailers
3
+ module User
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+
8
+ include InstanceMethods
9
+
10
+ end
11
+ end
12
+
13
+ module InstanceMethods
14
+ def change_password(user)
15
+ from "donotreply@example.com"
16
+ recipients user.email
17
+ subject "[YOUR APP] Request to change your password"
18
+ body :user => user
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/clearance.rb CHANGED
@@ -2,7 +2,8 @@ require 'clearance/app/controllers/application_controller'
2
2
  require 'clearance/app/controllers/sessions_controller'
3
3
  require 'clearance/app/controllers/users_controller'
4
4
  require 'clearance/app/controllers/passwords_controller'
5
- require 'clearance/app/models/model'
5
+ require 'clearance/app/models/user'
6
+ require 'clearance/app/models/user_mailer'
6
7
  require 'clearance/test/test_helper'
7
8
  require 'clearance/test/functionals/sessions_controller_test'
8
9
  require 'clearance/test/functionals/users_controller_test'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thoughtbot-clearance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoughtbot, inc.
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2008-10-09 00:00:00 -07:00
17
+ date: 2008-10-10 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -31,7 +31,8 @@ files:
31
31
  - clearance.gemspec
32
32
  - lib/clearance.rb
33
33
  - lib/clearance/app/controllers/application_controller.rb
34
- - lib/clearance/app/models/model.rb
34
+ - lib/clearance/app/models/user.rb
35
+ - lib/clearance/app/models/user_mailer.rb
35
36
  - lib/clearance/app/controllers/sessions_controller.rb
36
37
  - lib/clearance/test/functionals/sessions_controller_test.rb
37
38
  - lib/clearance/test/test_helper.rb
@@ -1,78 +0,0 @@
1
- module Clearance
2
- module Model
3
-
4
- def self.included(base)
5
- base.class_eval do
6
-
7
- attr_accessible :email, :password, :password_confirmation
8
- attr_accessor :password, :password_confirmation
9
-
10
- validates_presence_of :email
11
- validates_presence_of :password, :if => :password_required?
12
- validates_confirmation_of :password, :if => :password_required?
13
- validates_uniqueness_of :email
14
-
15
- before_save :initialize_salt, :encrypt_password
16
-
17
- extend ClassMethods
18
- include InstanceMethods
19
-
20
- protected
21
-
22
- include ProtectedInstanceMethods
23
-
24
- end
25
- end
26
-
27
- module ClassMethods
28
- def authenticate(email, password)
29
- user = find_by_email email
30
- user && user.authenticated?(password) ? user : nil
31
- end
32
- end
33
-
34
- module InstanceMethods
35
- def authenticated?(password)
36
- crypted_password == encrypt(password)
37
- end
38
-
39
- def encrypt(password)
40
- Digest::SHA1.hexdigest "--#{salt}--#{password}--"
41
- end
42
-
43
- def remember_token?
44
- remember_token_expires_at && Time.now.utc < remember_token_expires_at
45
- end
46
-
47
- def remember_me!
48
- remember_me_until 2.weeks.from_now.utc
49
- end
50
-
51
- def remember_me_until(time)
52
- self.update_attribute :remember_token_expires_at, time
53
- self.update_attribute :remember_token, encrypt("#{email}--#{remember_token_expires_at}")
54
- end
55
-
56
- def forget_me!
57
- self.update_attribute :remember_token_expires_at, nil
58
- self.update_attribute :remember_token, nil
59
- end
60
- end
61
-
62
- module ProtectedInstanceMethods
63
- def initialize_salt
64
- self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{email}--") if new_record?
65
- end
66
-
67
- def encrypt_password
68
- return if password.blank?
69
- self.crypted_password = encrypt(password)
70
- end
71
-
72
- def password_required?
73
- crypted_password.blank? || !password.blank?
74
- end
75
- end
76
-
77
- end
78
- end