authlogic_email_token 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82c6ebcef382eeba4a9db915cc926f4dbf250b6f
4
- data.tar.gz: 13fda182503d9ea91e6d9a2971165ca9c2050560
3
+ metadata.gz: 57a2824d5e5150536475eedf6d5307381d851dbd
4
+ data.tar.gz: 45b526b5dbf9e00ba96773ac3f1a54b708356b0e
5
5
  SHA512:
6
- metadata.gz: 8dba7244d2f51afeaa34616aeb2f5df29f921803fc9f48d1e38b3887ef893ef777839452c27750e1cd17ee7528c73f35d346c1fcdb7c6d8af71be03b9d712281
7
- data.tar.gz: ada7d45d51568a5893da5966eda865c7d179c86662aa497714d0b5be7a2c79a5bad6f55e4e68b9af122f4b8ec34266d2a6033adc18f96177ead8b5e4ed03fd0e
6
+ metadata.gz: f2d3a5f2de18520957d3efe718879c72fa64cb78684f1b71a011f63b0ab56fe95293c3b0e029e03443279704f34e9d9d20f1405330afaa3473646e755f7bebcb
7
+ data.tar.gz: dacab199324c87d1c0d7b33c0a2dc971fc5da3dc73bf44a369a7a0dc6680c2ea11457b491eb49a67a3f8c6a26f96cbd1b51f26cab28d0f4056d85c9b2c69d2e6
@@ -4,7 +4,7 @@
4
4
  # Include this module in your +User+ model and add a +new_email+ column to the +users+
5
5
  # table:
6
6
  #
7
- # add_column :users, :new_email, :string, null: true, after: :email
7
+ # add_column :users, :new_email, :string, after: :email
8
8
  #
9
9
  # You can then use the +new_email+ attribute in your account settings form like so:
10
10
  #
@@ -25,7 +25,6 @@
25
25
  #
26
26
 
27
27
  module Authlogic::ActsAsAuthentic::EmailToken::Confirmation
28
-
29
28
  # Call this when you have verified the user's email address. (Typically, as a result of
30
29
  # the user clicking the link in a confirmation email.)
31
30
  #
@@ -42,7 +41,7 @@ module Authlogic::ActsAsAuthentic::EmailToken::Confirmation
42
41
  # +activation_method+.)
43
42
  def confirm_email
44
43
  send(self.class.activation_method) if respond_to?(self.class.activation_method)
45
- if new_email.present?
44
+ if read_attribute(:new_email).present?
46
45
  self.email = new_email
47
46
  self.new_email = nil
48
47
  end
@@ -84,6 +83,13 @@ module Authlogic::ActsAsAuthentic::EmailToken::Confirmation
84
83
  # MyOtherMailer.whatever_message(user).deliver
85
84
  # end
86
85
  #
86
+ # Or, instead of providing a block, you can override the default names like so:
87
+ #
88
+ # acts_as_authentic do |c|
89
+ # c.confirmation_mailer_class = :MyOtherMailer
90
+ # c.confirmation_mailer_method = :whatever_message
91
+ # end
92
+ #
87
93
  # Recommended usage looks something like this:
88
94
  #
89
95
  # class UsersController < ApplicationController
@@ -115,7 +121,11 @@ module Authlogic::ActsAsAuthentic::EmailToken::Confirmation
115
121
  if block_given?
116
122
  yield
117
123
  else
118
- UserMailer.email_confirmation(self, controller).deliver
124
+ name = self.class.confirmation_mailer_class.to_s
125
+ klass = name.split('::').inject(Object) do |mod, klass|
126
+ mod.const_get klass
127
+ end
128
+ klass.send(self.class.confirmation_mailer_method, self, controller).deliver
119
129
  end
120
130
  true
121
131
  else
@@ -30,16 +30,33 @@ module Authlogic::ActsAsAuthentic::EmailToken
30
30
  rw_config(:activation_method, value, :activate)
31
31
  end
32
32
  alias_method :activation_method=, :activation_method
33
+
34
+ # Configures the name of the confirmation mailer class.
35
+ # +Authlogic::ActsAsAuthentic::EmailToken::maybe_deliver_email_confirmation!+
36
+ # for more info.
37
+ def confirmation_mailer_class(value = nil)
38
+ rw_config(:confirmation_mailer_class, value, :UserMailer)
39
+ end
40
+ alias_method :confirmation_mailer_class=, :confirmation_mailer_class
41
+
42
+ # Configures the name of the confirmation mailer method.
43
+ # +Authlogic::ActsAsAuthentic::EmailToken::maybe_deliver_email_confirmation!+
44
+ # for more info.
45
+ def confirmation_mailer_method(value = nil)
46
+ rw_config(:confirmation_mailer_method, value, :email_confirmation)
47
+ end
48
+ alias_method :confirmation_mailer_method=, :confirmation_mailer_method
33
49
  end
34
50
 
35
51
  module Methods
36
52
  def self.included(klass)
37
53
  # Do nothing if the email_token column is missing. If the email_token column
38
54
  # is present but not email_token_updated_at, raise.
39
- if !klass.column_names.include? 'email_token'
55
+ if !klass.column_names.map(&:to_s).include? 'email_token'
40
56
  return
41
- elsif !klass.column_names.include? 'email_token_updated_at'
57
+ elsif !klass.column_names.map(&:to_s).include? 'email_token_updated_at'
42
58
  raise(
59
+ ::Authlogic::ActsAsAuthentic::EmailToken::DBStructureError,
43
60
  "#{klass.name} has an email_token column but not email_token_updated_at. " +
44
61
  " You must add the latter. (Should be :datetime, null: false.)"
45
62
  )
@@ -80,6 +97,8 @@ module Authlogic::ActsAsAuthentic::EmailToken
80
97
  age = age.to_i
81
98
 
82
99
  # Authlogic builds its SQL by hand, but I prefer Arel. The logic is the same.
100
+ # No need to add an IS NOT NULL clause, because above, we return if the given
101
+ # token is blank.
83
102
  t = arel_table
84
103
  conditions = t[:email_token].eq(token)
85
104
  if age > 0
@@ -104,7 +123,7 @@ module Authlogic::ActsAsAuthentic::EmailToken
104
123
  self.email_token_updated_at = Time.now
105
124
  self.email_token = Authlogic::Random.friendly_token
106
125
  end
107
-
126
+
108
127
  # Same as reset_email_token, but then saves the record afterwards.
109
128
  def reset_email_token!
110
129
  reset_email_token
@@ -112,4 +131,6 @@ module Authlogic::ActsAsAuthentic::EmailToken
112
131
  end
113
132
  end
114
133
  end
134
+
135
+ class DBStructureError < StandardError; end
115
136
  end
@@ -1,3 +1,4 @@
1
+ require 'authlogic'
1
2
  require 'authlogic/acts_as_authentic/email_token'
2
3
  require 'authlogic/acts_as_authentic/email_token/confirmation'
3
4
  require 'authlogic/acts_as_authentic/email_token/railtie' if defined?(Rails)
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authlogic_email_token
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarrett Colby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-29 00:00:00.000000000 Z
11
+ date: 2014-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: authlogic
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: timecop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: database_cleaner
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1'
55
97
  description: Adds email_token and email_token_updated_at columns. Works like Authlogic's
56
98
  perishable_token, but doesn't reset on every request. Designed primarily for verifying
57
99
  users' email addresses.