-
Notifications
You must be signed in to change notification settings - Fork 16
/
user.rb
47 lines (35 loc) · 1.08 KB
/
user.rb
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
class User < ActiveRecord::Base
has_secure_password validations: false
has_many :authorizations, dependent: :destroy
has_many :topics, foreign_key: :creator_id, dependent: :restrict_with_exception
has_many :topic_comments, dependent: :restrict_with_exception
validates :email, uniqueness: true, presence: true, email: true
validates :login, uniqueness: true, presence: true
validates :password_digest, presence: true
state_machine initial: :waiting_confirmation do
state :waiting_confirmation
state :inactive
state :active
event :confirm do
transition waiting_confirmation: :active
end
event :deactivate do
transition from: :active, to: :inactive
end
before_transition waiting_confirmation: :active, do: :set_confirmed_at
end
include UserRepository
def generate_confirmation_token
self.confirmation_token = Token.generate
end
def generate_reset_password_token
self.reset_password_token = Token.generate
end
def to_s
login
end
private
def set_confirmed_at
self.confirmed_at = Time.current
end
end