src/Client.php
/**
     * Login with provided credential. Will use credential from setCredential if
     * $username or $password empty.
     */
Login with provided credential. Will use credential from setCredential if
$username or $password empty.
Login with provided credential . Will use credential from setCredential if $username or $password empty .
public function login($username = null, $password = null):bool {
        if(empty($username) || empty($password)) {
            $username = $this->u_username;
            $password = $this->u_password;
            if(empty($username) || empty($password)) {
                throw new Exceptions\CredentialException("Password/Username is empty!");
            }
        }
        $client = $this->guzzleClient;
        $resp = $client->request('GET', self::$cas_login);
        $ex_match = [];
        preg_match_all(self::EXPATTERN, $resp->getBody(), $ex_match);
        try {
            $resp = $client->request('POST', self::$cas_login, [
                'form_params'=> [
                    'username'  => $username,
                    'password'  => $password,
                    'execution' => $ex_match[1][0],
                    '_eventId'  => 'submit',
                    'submit'    => 'LOGIN'
                ]
            ]);
        } catch (GuzzleHttp\Exception\ClientException $e) {
            throw new Exceptions\CredentialException('Password Salah');
        }
        if(preg_match(self::ERRPATTERN, $resp->getBody()))
            throw new Exceptions\CredentialException('Password Salah');
        return true;
    }
public function login ( $ username = null , $ password = null ) : bool { if ( empty ( $ username ) || empty ( $ password ) ) { $ username = $ this -> u_username ; $ password = $ this -> u_password ; if ( empty ( $ username ) || empty ( $ password ) ) { throw new Exceptions \ CredentialException ( " Password/Username is empty! " ) ; } } $ client = $ this -> guzzleClient ; $ resp = $ client -> request ( 'GET' , self :: $ cas_login ) ; $ ex_match = [ ] ; preg_match_all ( self :: EXPATTERN , $ resp -> getBody ( ) , $ ex_match ) ; try { $ resp = $ client -> request ( 'POST' , self :: $ cas_login , [ 'form_params' => [ 'username' => $ username , 'password' => $ password , 'execution' => $ ex_match [ 1 ] [ 0 ] , '_eventId' => 'submit' , 'submit' => 'LOGIN' ] ] ) ; } catch ( GuzzleHttp \ Exception \ ClientException $ e ) { throw new Exceptions \ CredentialException ( 'Password Salah' ) ; } if ( preg_match ( self :: ERRPATTERN , $ resp -> getBody ( ) ) ) throw new Exceptions \ CredentialException ( 'Password Salah' ) ; return true ; }
Login with provided credential.
Login with provided credential .
// make session, save it to query // build query, then fetch it //error checking