API16:JClientHelper/setCredentials
From Joomla! Documentation
Description
Method to set client login credentials
<! removed transcluded page call, red link never existed >
Syntax
setCredentials($client, $user, $pass)
| Parameter Name | Default Value | Description |
|---|---|---|
| $client | Client name, currently only 'ftp' is supported | |
| $user | Username | |
| $pass | Password |
Returns
boolean True if the given login credentials have been set and are valid
Defined in
libraries/joomla/client/helper.php
Importing
jimport( 'joomla.client.helper' );
Source Body
function setCredentials($client, $user, $pass)
{
$return = false;
$client = strtolower($client);
// Test if the given credentials are valid
switch ($client)
{
case 'ftp':
$config = &JFactory::getConfig();
$options = array(
'enabled' => $config->getValue('config.ftp_enable'),
'host' => $config->getValue('config.ftp_host'),
'port' => $config->getValue('config.ftp_port'),
);
if ($options['enabled'])
{
jimport('joomla.client.ftp');
$ftp = &JFTP::getInstance($options['host'], $options['port']);
// Test the conection 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 = &JFactory::getSession();
$session->set($client.'.user', $user, 'JClientHelper');
$session->set($client.'.pass', $pass, 'JClientHelper');
// Force re-creation of the data saved within JClientHelper::getCredentials()
JClientHelper::getCredentials($client, true);
}
return $return;
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples