Skip to content

Commit

Permalink
fix authenticate method
Browse files Browse the repository at this point in the history
  • Loading branch information
gnello committed Apr 19, 2017
1 parent 010f6db commit 36c555c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# php-mattermost-driver (v3.7.0)

Completed Php Driver to interact with the [Mattermost Web Service API][4].
Completed Php Driver to interact with the [Mattermost Web Service API][4].
Version of the Mattermost server required: 3.7.0

Version of the Mattermost server required: 3.7.0
Please read [the api documentation][1] for further information on using this application.

## Installation
Expand Down Expand Up @@ -31,13 +31,7 @@ Read more about how to install and use Composer on your local machine [here][3].
]);

$driver = new Driver($container);
$login = $driver->authenticate();

if ($login) {
echo "SUCCESS!";
} else {
echo "SOMETHING WENT WRONG.";
}
$result = $driver->authenticate();
```

### Check results
Expand All @@ -63,7 +57,7 @@ $requestOptions = [
$result = $driver->getUserModel()->createUser($requestOptions);

//Get a user
$res = $driver->getUserModel()->getUserByUsername('username');
$result = $driver->getUserModel()->getUserByUsername('username');
```

### Team data model
Expand All @@ -83,4 +77,4 @@ In Development, coming soon!
[1]: https://api.mattermost.com/
[2]: http://www.php-fig.org/psr/psr-7/
[3]: https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx
[4]: https://about.mattermost.com/
[4]: https://about.mattermost.com/
9 changes: 3 additions & 6 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(Container $container)
}

/**
* @return bool
* @return null|\Psr\Http\Message\ResponseInterface
*/
public function authenticate()
{
Expand All @@ -75,16 +75,13 @@ public function authenticate()
/** @var Client $client */
$client = $this->container['client'];
$response = $client->post('/users/login', $options);
$statusCode = $response->getStatusCode();

if ($statusCode == 200) {
if ($response->getStatusCode() == 200) {
$token = $response->getHeader('Token')[0];
$client->setToken($token);

return true;
}

return false;
return $response;
}

/**
Expand Down

0 comments on commit 36c555c

Please sign in to comment.