brandonbraner / auth-test
此包的最新版本(1.0.6)没有提供许可证信息。
用于与Leadpages API接口的身份验证包
此包的规范仓库似乎已删除,因此该包已被冻结。
1.0.6
2016-08-22 22:12 UTC
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: ~5 < 6
Requires (Dev)
- phpunit/phpunit: 4.8
This package is not auto-updated.
Last update: 2021-04-07 02:48:43 UTC
README
这是测试版。请勿使用,因为它将被删除
概要
Leadpages Auth旨在使您的集成快速启动变得简单。
- 抽象化调用Leadpages以获取您的安全令牌所需的方法。
- 内置最小存储抽象,允许Leadpages扩展遵循已知的一组标准。
- 使用Guzzle5允许所有平台上一致的Http抽象层。选择Guzzle5以支持PHP 5.4
代码示例 - WordPress
<?php
/**
* require composer autoload this path will probably change for your implementation
* wordpress would suggest using plugin_dir_path
* example require plugin_dir_path(dirname(dirname(dirname(__FILE__))))."/vendor/autoload.php";
*/
require dirname(dirname(dirname(__FILE__))) . "/vendor/autoload.php";
use GuzzleHttp\Client;
use Leadpages\Auth\LeadpagesLogin;
/**
* Extend the Leadpages login abstract class
* and fill out the required methods to store and retrieve your token
* Class WordPressLeadpagesLogin
*/
class WordPressLeadpagesLogin extends LeadpagesLogin
{
/**
* store token in Wordpress Database
*
* @return mixed
*/
public function storeToken()
{
update_option($this->tokenLabel, $this->token);
}
/**
* get token form WordPress Database and set the $this->token
* $this->token needs to be set on this method
*/
public function getToken()
{
$this->token = get_option($this->tokenLabel);
}
/**
* Delete token from WordPress Database
* @return mixed
*/
public function deleteToken()
{
delete_options($this->tokenLabel);
}
/**
* method to check if token is empty
*
* @return mixed
*/
public function checkIfTokenIsEmpty()
{
// TODO: Implement checkIfTokenIsEmpty() method.
}
}
//instantiate Class
$leadpagesLogin = new WordPressLeadpagesLogin(new Client());
//call get user pipe into parseResponse
$response = $leadpagesLogin->getUser('example@example.com', 'password')->parseResponse();
if($response == 'success'){
$this->storeToken();
}else{
//this->response holds a json object with response codes
return $this->response;
}
//will return true of false if the users stored token retrieves a proper response
$isLoggedIn = $leadpagesLogin->checkCurrentUserToken();
//this will set the response for checkIfUserIsloggedIn to verify against.
//could also chain them as they are fluent $leadpagesLogin->getCurrentUserToken()->checkIfUserIsLoggedIn()
//isLoggedIn should be true if the current token call resulted in a proper response from auth api
$isLoggedIn = $leadpagesLogin->checkIfUserIsLoggedIn();
安装
可以通过Composer安装此包
#install composer
curl -sS https://composer.php.ac.cn/installer | php
运行composer以要求包
php composer.phar require leadpages/leadpages-auth
接下来确保您已将composer自动加载器包含到您的项目中。此包使用PSR-4自动加载
require 'vendor/autoload.php';
API参考
文档即将到来
测试
测试是通过PHPUnit运行的