/**
* Method to set client login credentials
*
* @param string $client Client name, currently only 'ftp' is supported
* @param string $user Username
* @param string $pass Password
*
* @return boolean True if the given login credentials have been set and are valid
*
* @since 1.7.0
*/
public static function setCredentials($client, $user, $pass)
{
$return = false;
$client = strtolower($client);
// Test if the given credentials are valid
switch ($client) {
case 'ftp':
$app = Factory::getApplication();
$options = array('enabled' => $app->get('ftp_enable'), 'host' => $app->get('ftp_host'), 'port' => $app->get('ftp_port'));
if ($options['enabled']) {
$ftp = FtpClient::getInstance($options['host'], $options['port']);
// Test the connection and try to log in
if ($ftp->isConnected()) {
if ($ftp->login($user, $pass)) {
$return = true;
}
$ftp->quit();
}
}
break;
default:
break;
}
if ($return) {
// Save valid credentials to the session
$session = Factory::getSession();
$session->set($client . '.user', $user, 'JClientHelper');
$session->set($client . '.pass', $pass, 'JClientHelper');
// Force re-creation of the data saved within JClientHelper::getCredentials()
self::getCredentials($client, true);
}
return $return;
}