-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path25-activation-lifecycle.patch
68 lines (53 loc) · 2.3 KB
/
25-activation-lifecycle.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
activation-lifecycle
From: Bryan Larsen <[email protected]>
# Adding User Activation
It's standard procedure to ask users to verify their email address
before allowing them to sign into the system. Not surprisingly, Hobo
makes this very easy to do.
The default user model does not contain support for activating email
addresses, but it does contain support for something very similar:
resetting the password.
If you look inside your `app/models/user.rb` file, you will find this
functionality inside the *Signup Lifecycle*.
[Lifecycles](/manual/lifecycles) are the Hobo mechanism for
implementing state machines.
Currently, there should be only one state inside this state machine.
This seems like a fairly broad hint that we should another state to
implement our sign up procedures. Let's add an `inactive` state to
counter the `active` state that's present, and make it the default.
We should also add a block to our creation step to deliver the email.
We'll also add another `request_password_reset` transition becuase
it is possible that inactivated users will click on the forgot
password link.
SHOW_PATCH
---
app/models/user.rb | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/app/models/user.rb b/app/models/user.rb
index ca07357..4e3ba1f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -22,17 +22,23 @@ class User < ActiveRecord::Base
# --- Signup lifecycle --- #
lifecycle do
-
- state :active, :default => true
+ state :inactive, :default => true
+ state :active
create :signup, :available_to => "Guest",
:params => [:name, :email_address, :password, :password_confirmation],
- :become => :active
-
+ :become => :inactive, :new_key => true do
+ UserMailer.deliver_activation(self, lifecycle.key) unless email_address.blank?
+ end
+
transition :request_password_reset, { :active => :active }, :new_key => true do
UserMailer.deliver_forgot_password(self, lifecycle.key)
end
+ transition :request_password_reset, { :inactive => :inactive }, :new_key => true do
+ UserMailer.deliver_activation(self, lifecycle.key)
+ end
+
transition :reset_password, { :active => :active }, :available_to => :key_holder,
:params => [ :password, :password_confirmation ]