Class: UserAuth::Models::User

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/user_auth/models/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/user_auth/models/user.rb', line 7

def password
  @password
end

#password_changingObject

Returns the value of attribute password_changing.



8
9
10
# File 'lib/user_auth/models/user.rb', line 8

def password_changing
  @password_changing
end

Instance Method Details

#clear_refresh_tokens!Object



37
38
39
# File 'lib/user_auth/models/user.rb', line 37

def clear_refresh_tokens!
  refresh_tokens_dataset.destroy
end

#email=(email) ⇒ Object



25
26
27
# File 'lib/user_auth/models/user.rb', line 25

def email=(email)
  super(email.try(:downcase))
end

#refresh_token!Object



33
34
35
# File 'lib/user_auth/models/user.rb', line 33

def refresh_token!
  RefreshToken.find_or_create(user: self).token
end

#to_jsonObject



29
30
31
# File 'lib/user_auth/models/user.rb', line 29

def to_json
  info.merge(email: email, user_id: id).symbolize_keys
end

#validateObject



11
12
13
14
15
16
17
18
# File 'lib/user_auth/models/user.rb', line 11

def validate
  super
  validates_presence :email
  validates_unique :email
  validates_format(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :email, message: "is not a valid email address")
  validates_presence :password if new? || password_changing
  validates_min_length 8, :password if new? || password_changing
end