Test Failed
Push — master ( 634833...ea7adf )
by Vítězslav
03:19
created

Kontakt::authenticate()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 1
nop 2
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * FlexiPeeHP - Objekt kontaktu.
4
 *
5
 * @author     Vítězslav Dvořák <[email protected]>
6
 * @copyright  (C) 2015-2017 Spoje.Net
7
 */
8
9
namespace FlexiPeeHP;
10
11
/**
12
 * Kontakt adresáře
13
 *
14
 * @link https://demo.flexibee.eu/c/demo/kontakt/properties
15
 */
16
class Kontakt extends FlexiBeeRW
17
{
18
    /**
19
     * Evidence užitá objektem.
20
     *
21
     * @var string
22
     */
23
    public $evidence = 'kontakt';
24
25
    /**
26
     * Authenticate by contact
27
     *
28
     * @link https://www.flexibee.eu/api/dokumentace/ref/autentizace-kontaktu/ Contact Auth
29
     * @param string $login
30
     * @param string $password
31
     * @return boolean
32
     */
33
    public function authenticate($login, $password)
34
    {
35
        $defaultHttpHeaders                       = $this->defaultHttpHeaders;
36
        $this->defaultHttpHeaders['Content-Type'] = 'application/x-www-form-urlencoded';
37
        $this->setPostFields(http_build_query(['username' => $login, 'password' => $password]));
38
        $result                                   = $this->performRequest($this->evidence.'/authenticate',
39
            'POST', 'xml');
40
        $this->defaultHttpHeaders                 = $defaultHttpHeaders;
41
        $this->addStatusMessage($result['message'],
42
            $result['success'] == 'true' ? 'success' : 'warning' );
43
        return $result['success'] == 'true';
44
    }
45
}
46