-
Notifications
You must be signed in to change notification settings - Fork 5
/
Casdoor.php
130 lines (115 loc) · 3.03 KB
/
Casdoor.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
// ABSPATH prevent public user to directly access your .php files through URL.
defined('ABSPATH') or die('No script kiddies please!');
/**
* The main class of plugin
*/
class Casdoor
{
public $version = '1.0.0';
public static $_instance = null;
protected $default_settings = [
'active' => 0,
'client_id' => '',
'client_secret' => '',
'backend' => '',
'organization' => 'built-in',
'server_oauth_trigger' => 'oauth',
'server_auth_endpoint' => 'authorize',
'server_token_endpont' => 'token',
'server_user_endpoint' => 'me'
];
public function __construct()
{
add_action('init', [__CLASS__, 'includes']);
add_action('init', [__CLASS__, 'custom_login']);
}
/**
* populate the instance if the plugin for extendability
*
* @return Casdoor
*/
public static function instance()
{
if (is_null(self::$_instance)) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* plugin includes called during load of plugin
*
* @return void
*/
public static function includes()
{
require_once(CASDOOR_PLUGIN_DIR . '/includes/functions.php');
require_once(CASDOOR_PLUGIN_DIR . '/includes/admin-options.php');
require_once(CASDOOR_PLUGIN_DIR . '/includes/Rewrites.php');
}
/**
* Plugin Setup
*/
public function setup()
{
$options = get_option('casdoor_options');
if (!isset($options['backend'])) {
update_option('casdoor_options', $this->default_settings);
}
$this->install();
}
/**
* When wp-login.php was visited, redirect to the login page of casdoor
*
* @return void
*/
public static function custom_login()
{
global $pagenow;
$activated = absint(casdoor_get_option('active'));
if ('wp-login.php' == $pagenow && $_GET['action'] != 'logout' && $activated) {
$url = get_casdoor_login_url();
wp_redirect($url);
exit();
}
}
public function logout()
{
$auto_sso = absint(casdoor_get_option('auto_sso'));
if (!$auto_sso) {
wp_redirect(home_url());
die();
}
}
/**
* Loads the plugin styles and scripts into scope
*
* @return void
*/
public function wp_enqueue()
{
// Registers the script if $src provided (does NOT overwrite), and enqueues it.
wp_enqueue_script('jquery-ui-accordion');
// Registers the style if source provided (does NOT overwrite) and enqueues.
wp_enqueue_style('casdoor_admin');
wp_enqueue_script('casdoor_admin');
}
/**
* Plugin Initializer
*/
public function plugin_init()
{
}
/**
* Plugin Install
*/
public function install()
{
}
/**
* Plugin Upgrade
*/
public function upgrade()
{
}
}