Class: User

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
lib/generators/jinda/templates/app/models/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_omniauth(auth) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/generators/jinda/templates/app/models/user.rb', line 35

def self.from_omniauth(auth)
  # Rails now no longer support slice 
  # where(auth.slice(:uid, :provider, :email)).first_or_create do |user|
where(uid: auth.uid, provider: auth.provider, email: auth.info.email).first_or_create do |user|
  case auth.provider 
    when 'identity'
      identity = Identity.find auth.uid
      user.code = identity.code
      user.email = identity.email
    else
      user.email = auth.info.email
      user.uid = auth.uid
      user.provider = auth.provider
      user.code = auth.info.name
      user.role = "M"
      user.image = auth.info.image
    end
  end
end

Instance Method Details

#generate_token(column) ⇒ Object

Add to create forgot password



24
25
26
27
28
29
# File 'lib/generators/jinda/templates/app/models/user.rb', line 24

def generate_token(column)
  begin
    self[column] = SecureRandom.urlsafe_base64
  end
  #end while User.exists?(column => self[column])
end

#has_role(role1) ⇒ Object



31
32
33
# File 'lib/generators/jinda/templates/app/models/user.rb', line 31

def has_role(role1)
  return role.upcase.split(',').include?(role1.upcase)
end

#ma_secured?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/generators/jinda/templates/app/models/user.rb', line 55

def ma_secured?
  role.upcase.split(',').include?(ma_secured_ROLE)
end

#send_password_resetObject



59
60
61
62
63
64
# File 'lib/generators/jinda/templates/app/models/user.rb', line 59

def send_password_reset
  generate_token(:password_reset_token)
  self.password_reset_sent_at = Time.zone.now
  save!
  UserMailer.password_reset(self).deliver
end