Actions

API16

JClientHelper/setCredentials

From Joomla! Documentation

< API16:JClientHelper
Revision as of 21:55, 12 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Method to set client login credentials

[<! removed edit link to red link >]

<! 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 edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />