Class: Notee::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/notee/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#editor_idObject

Returns the value of attribute editor_id.



31
32
33
# File 'app/models/notee/user.rb', line 31

def editor_id
  @editor_id
end

#fileObject

accessors



28
29
30
# File 'app/models/notee/user.rb', line 28

def file
  @file
end

#passwordObject

Returns the value of attribute password.



29
30
31
# File 'app/models/notee/user.rb', line 29

def password
  @password
end

#password_confirmObject

Returns the value of attribute password_confirm.



30
31
32
# File 'app/models/notee/user.rb', line 30

def password_confirm
  @password_confirm
end

Instance Method Details

#confirm_passwordObject



51
52
53
# File 'app/models/notee/user.rb', line 51

def confirm_password
  return false unless password == password_confirm
end

#encrypt(password) ⇒ Object



47
48
49
# File 'app/models/notee/user.rb', line 47

def encrypt(password)
  OpenSSL::Digest::MD5.hexdigest(password)
end

#encrypt_passwordObject



55
56
57
# File 'app/models/notee/user.rb', line 55

def encrypt_password
  self.encrypted_password = encrypt(password)
end

#manage_profile_imgObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/notee/user.rb', line 59

def manage_profile_img
  return unless file
  return if User.exists?(profile_img: file)

  image_dir = Rails.root.to_s + '/public/notee/profile/'
  FileUtils.mkdir_p(image_dir) unless FileTest.exist?(image_dir)
  image_name = Time.now.strftime('%Y%m%d%H%M%S') + '--' + SecureRandom.uuid + '.jpg'
  transaction do
    open(image_dir + '/' + image_name, 'wb') do |output|
      output.write(file.read)
    end
  end
  self.profile_img = image_name
end

#sign_in(name_or_email, password) ⇒ Object



38
39
40
41
42
43
44
45
# File 'app/models/notee/user.rb', line 38

def (name_or_email, password)
  user = find_by(name: name_or_email)
  user = find_by(email: name_or_email) unless user
  return false unless user
  return false unless user.encrypted_password == encrypt(password)

  user
end