Module: Wpxf::Db::Credentials

Included in:
Module
Defined in:
lib/wpxf/db/credentials.rb

Overview

Provides functionality for storing and updating credentials.

Instance Method Summary collapse

Instance Method Details

#store_credentials(username, password = '', type = 'plain') ⇒ Models::Credential

Store a new set of credentials in the database.

Parameters:

  • username (String)

    the username.

  • password (String) (defaults to: '')

    the password.

  • type (String) (defaults to: 'plain')

    the type of string stored in the password field.

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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