module Wpxf::Db::Credentials

Provides functionality for storing and updating credentials.

Public Instance Methods

store_credentials(username, password = '', type = 'plain') click to toggle source

Store a new set of credentials in the database. @param username [String] the username. @param password [String] the password. @param type [String] the type of string stored in the password field. @return [Models::Credential] the newly created {Models::Credential}.

# File lib/wpxf/db/credentials.rb, line 10
def store_credentials(username, password = '', type = 'plain')
  credential = Wpxf::Models::Credential.first(
    host: target_host,
    port: target_port,
    username: username,
    type: type,
    workspace: active_workspace
  )

  credential = Wpxf::Models::Credential.new if credential.nil?
  credential.host = target_host
  credential.port = target_port
  credential.username = username
  credential.password = _determine_password_to_store(credential, password)
  credential.type = type
  credential.workspace = active_workspace

  credential.save
end

Private Instance Methods

_determine_password_to_store(model, new_password) click to toggle source
# File lib/wpxf/db/credentials.rb, line 32
def _determine_password_to_store(model, new_password)
  new_password = '' if new_password.nil?
  return model.password if new_password == '' && !model.password.nil?
  new_password
end