master
E. Almqvist 3 years ago
parent 183dd611f7
commit 8228016ee6
  1. 15
      src/db_models.rb

@ -52,6 +52,19 @@ class User < EntityModel
self.update({reputation: val}, "id = ?", @id)
end
def update_creds(data)
# Validate input
return false, SETTINGS_ERRORS[:name_len] unless data[:name].length.between?(MIN_NAME_LEN, MAX_NAME_LEN)
return false, SETTINGS_ERRORS[:bio_len] unless data[:bio_text].length.between?(MIN_BIO_LEN, MAX_BIO_LEN)
# Filter unchanged data
data.keys.each do |k|
data.delete(k) if @data[k.to_s] == data[k]
end
User.update(data, "id = ?", @id) unless data.length < 1
return true, nil
end
# Find user by ID, returns a user object
def self.find_by_id(id)
data = self.get("*", "id = ?", id).first
@ -73,7 +86,7 @@ class User < EntityModel
check_email_valid = email.match(EMAIL_REGEX) != nil
# Name
check_name_len = name.length >= MIN_NAME_LEN
check_name_len = name.length.between?(MIN_NAME_LEN, MAX_NAME_LEN)
# Password
check_pass_equals = password == password_confirm

Loading…
Cancel
Save