Source of file Login.php

Size: 1,442 Bytes - Last Modified: 2018-11-03T09:50:48-04:00

G:/AdobeConnectClient/src/Commands/Login.php

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
<?php

namespace AdobeConnectClient\Commands;

use AdobeConnectClient\Command;
use AdobeConnectClient\Converter\Converter;
use AdobeConnectClient\Exceptions\NoDataException;
use AdobeConnectClient\Helpers\StatusValidate;
use AdobeConnectClient\Helpers\HeaderParse;

/**
 * Call the Login action and save the session cookie.
 *
 * More info see {@link https://helpx.adobe.com/content/help/en/adobe-connect/webservices/login.html}
 */
class Login extends Command
{
    /**
     * @var array
     */
    protected $parameters;

    /**
     * @param string $login
     * @param string $password
     */
    public function __construct($login, $password)
    {
        $this->parameters = [
            'action' => 'login',
            'login' => (string) $login,
            'password' => (string) $password
        ];
    }

    /**
     * @inheritdoc
     *
     * @return bool
     */
    protected function process()
    {
        $response = $this->client->doGet($this->parameters);
        $responseConverted = Converter::convert($response);

        try {
            StatusValidate::validate($responseConverted['status']);
        } catch (NoDataException $e) { // Invalid Login
            $this->client->setSession('');
            return false;
        }
        $cookieHeader = HeaderParse::parse($response->getHeader('Set-Cookie'));
        $this->client->setSession($cookieHeader[0]['BREEZESESSION']);
        return true;
    }
}