-
Notifications
You must be signed in to change notification settings - Fork 1
/
Q2ANKConnect.php
78 lines (67 loc) · 1.42 KB
/
Q2ANKConnect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
require_once 'nk-php-sdk/src/NK.php';
class Q2ANKConnect
{
const NKCONNECT_KEY = 'nkconnect_site_key';
const NKCONNECT_SECRET = 'nkconnect_site_secret';
const LOGIN_SOURCE = 'nkconnect';
/**
*
* @var NKConnect
*/
private $auth;
private static $instance;
public static function instance()
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
private function init()
{
if ($this->auth === null) {
$this->auth = new NKConnect($this->get_config());
}
}
private function get_config()
{
$config = new NKConfig();
$config->key = qa_opt(self::NKCONNECT_KEY);
$config->secret = qa_opt(self::NKCONNECT_SECRET);
$config->permissions = array(
NKPermissions::BASIC_PROFILE,
NKPermissions::EMAIL_PROFILE
);
return $config;
}
public function get_login_button()
{
$button = null;
try{
$auth = $this->getAuth();
$auth->handleCallback();
$button = $auth->button();
}catch (NKConnectUnusableException $e){
error_log($e->getMessage());
}
return $button;
}
/**
* @return NKConnnect
*/
public function getAuth()
{
$this->init();
return $this->auth;
}
/**
*
* @return bool
*/
public static function is_ready_data()
{
return qa_opt(self::NKCONNECT_KEY) != "" && qa_opt(self::NKCONNECT_SECRET) != "";
}
}
?>