class JunglePath::Controller::User

Public Class Methods

new(current_identity, params, db) click to toggle source
Calls superclass method
# File lib/jungle_path/controller/authentication.rb, line 12
def initialize(current_identity, params, db)
  super(current_identity, params, db, JunglePath::Schema::User)
end
validate_hash_with_password(hash, password) click to toggle source
# File lib/jungle_path/controller/authentication.rb, line 68
def self.validate_hash_with_password(hash, password)
  JunglePath::Authentication::PasswordHash.validatePassword(password, hash)
end

Private Class Methods

validate_password_message(password) click to toggle source
# File lib/jungle_path/controller/authentication.rb, line 73
def self.validate_password_message(password)
  message = nil
  # returns message if password is not a minimum strength...
  message = "Password is either missing or too short." unless password and password.length > 0
end

Public Instance Methods

insert(include_secure_columns: false) click to toggle source
# File lib/jungle_path/controller/authentication.rb, line 16
def insert(include_secure_columns: false)
  params = self.class.add_audit_parameter_values_for_insert(@params, @current_user, @current_key, @table_class)
  model = @table_class.new params

  password = params[:password]
  message = self.class.validate_password_message(password)
  if message
    self.class.validate_insert(model, message)
    raise JunglePath::Exceptions::InvalidPassword, "#{message}", caller
  end
  # todo: validate password strength, etc. here!
  model.hash = JunglePath::Authentication::PasswordHash.createHash(password)

  self.class.validate_insert(model)
  begin
    result = @db.insert._model(model)
    result = self.class.handle_include_secure_columns_flag(result, include_secure_columns, @table_class)
  rescue Sequel::UniqueConstraintViolation => e
    # already there? update instead...
    #puts "not unique!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    user_query = JunglePath::Schema::User.new({user_name: params[:user_name]})
    user = @db.select._model_by_any(user_query)
    #puts "user: #{user}."
    params[:id] = user.id if user
    if user
      update
      user = @db.select._model(user)
    else
      raise
    end
  end
end
update() click to toggle source
# File lib/jungle_path/controller/authentication.rb, line 49
def update
  params = self.class.add_audit_parameter_values_for_update(@params, @current_user, @current_key, @table_class)
  model = @table_class.new params

  password = params[:password]
  if password
    message = self.class.validate_password_message(password)
    if message
      self.class.validate_update(model, message)
      raise JunglePath::Exceptions::InvalidPassword, "#{message}", caller
    end
    # todo: validate password strength, etc. here!
    model.hash = JunglePath::Authentication::PasswordHash.createHash(password)
  end

  self.class.validate_update(model)
  result = @db.update._model(model)
end