Skip to content

Commit ba5fb33

Browse files
committed
✨ 增加LinuxDO-OAuth2登录支持
1 parent 04d7d57 commit ba5fb33

File tree

9 files changed

+358
-149
lines changed

9 files changed

+358
-149
lines changed

assets/img/oauth/linuxdo.png

4.14 KB
Loading

inc/ajax/page-oauth-login.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ function pk_oauth_quick_buttons($echo = false, $redirect = '')
1717
foreach ($oauth_list as $key => $val) {
1818
if (!isset($val['system']) || !$val['system'] || pk_is_checked('oauth_' . $key)) {
1919
$url = $val['url'] ?? pk_oauth_url_page_ajax($key, $redirect);
20-
$icon = isset($val['icon']) ? "<i class='{$val['icon']}'></i>" : '';
20+
$icon = isset($val['icon']) ? str_starts_with($val['icon'], 'http') ? "<img src='{$val['icon']}' width='15' class='mr-1' alt='{$val['label']}'/>":"<i class='{$val['icon']} mr-1'></i>" : '';
2121
$color_type = $val['color_type'] ?? 'primary';
22-
$out .= "<a class='btn btn-{$color_type} btn-ssm mr5 mb5'
22+
$out .= "<a class='btn btn-{$color_type} btn-ssm mr5 mb5 d-flex align-items-center'
2323
data-no-instant
2424
href='{$url}'>
2525
{$icon}

inc/fun/core.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function pk_ajax_resp_error($msg = 'fail', $data = null)
3030
require_once PUOCK_ABS_DIR . '/inc/setting/index.php';
3131
require_once PUOCK_ABS_DIR . '/inc/ext/init.php';
3232
require_once PUOCK_ABS_DIR . '/inc/fun/ajax.php';
33-
require_once PUOCK_ABS_DIR . '/inc/fun/oauth.php';
33+
require_once PUOCK_ABS_DIR . '/inc/oauth/oauth.php';
3434
require_once PUOCK_ABS_DIR . '/inc/fun/security.php';
3535
require_once PUOCK_ABS_DIR . '/inc/fun/comment-ajax.php';
3636
require_once PUOCK_ABS_DIR . '/inc/fun/widget.php';

inc/oauth/callback/linuxdo.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
require_once dirname(__DIR__) . '/../../../../../wp-load.php';
4+
5+
pk_oauth_callback_execute('linuxdo','');
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ function pk_oauth_list($user = null)
2727
'openid' => $user ? get_the_author_meta('qq_oauth', $user->ID) : null,
2828
'class' => OAuth2::class,
2929
'name_field' => 'nickname',
30-
'icon'=>'fa-brands fa-qq',
31-
'color_type'=>'danger',
30+
'icon' => 'fa-brands fa-qq',
31+
'color_type' => 'danger',
3232
'secret_field' => 'key',
3333
'system' => true,
3434
],
3535
'github' => [
3636
'label' => 'GitHub',
3737
'openid' => $user ? get_the_author_meta('github_oauth', $user->ID) : null,
3838
'class' => \Yurun\OAuthLogin\Github\OAuth2::class,
39-
'icon'=>'fa-brands fa-github',
40-
'color_type'=>'primary',
39+
'icon' => 'fa-brands fa-github',
40+
'color_type' => 'primary',
4141
'name_field' => 'name',
4242
'system' => true,
4343
],
@@ -46,20 +46,29 @@ function pk_oauth_list($user = null)
4646
'openid' => $user ? get_the_author_meta('weibo_oauth', $user->ID) : null,
4747
'class' => \Yurun\OAuthLogin\Weibo\OAuth2::class,
4848
'name_field' => 'name',
49-
'icon'=>'fa-brands fa-weibo',
50-
'color_type'=>'danger',
49+
'icon' => 'fa-brands fa-weibo',
50+
'color_type' => 'danger',
5151
'id_field' => 'key',
5252
'system' => true,
5353
],
5454
'gitee' => [
5555
'label' => '码云',
5656
'openid' => $user ? get_the_author_meta('gitee_oauth', $user->ID) : null,
5757
'class' => \Yurun\OAuthLogin\Gitee\OAuth2::class,
58-
'icon'=>'fa-solid fa-globe',
59-
'color_type'=>'info',
58+
'icon' => 'fa-solid fa-globe',
59+
'color_type' => 'info',
6060
'name_field' => 'name',
6161
'system' => true,
6262
],
63+
'linuxdo' => [
64+
'label' => 'LinuxDo',
65+
'openid' => $user ? get_the_author_meta('linuxdo_oauth', $user->ID) : null,
66+
'class' => \Yurun\OAuthLogin\LinuxDo\OAuth2::class,
67+
'icon' => PUOCK_ABS_URI . '/assets/img/oauth/linuxdo.png',
68+
'color_type' => 'warning',
69+
'name_field' => 'name',
70+
'system' => true,
71+
]
6372
];
6473
return apply_filters('pk_oauth_list', $list);
6574
}
@@ -187,6 +196,11 @@ function pk_oauth_callback()
187196
{
188197
$type = $_GET['type'];
189198
$redirect = $_GET['redirect'];
199+
pk_oauth_callback_execute($type, $redirect);
200+
}
201+
202+
function pk_oauth_callback_execute($type, $redirect)
203+
{
190204
if (!empty($redirect)) {
191205
$redirect = urldecode($redirect);
192206
}

inc/setting/options/OptionAuth.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,40 @@ function get_fields(): array
209209
],
210210
]
211211
],
212+
[
213+
'id' => '-',
214+
'label' => 'LinuxDO ' . __('登录配置', PUOCK),
215+
'type' => 'panel',
216+
'open' => pk_is_checked('oauth_linuxdo'),
217+
'tips' => '<a target="_blank" href="https://connect.linux.do">' . __('申请步骤及说明', PUOCK) . '</a>',
218+
'children' => [
219+
[
220+
'id' => '-',
221+
'label' => __('第三方登录回调地址提示', PUOCK),
222+
'type' => 'info',
223+
'infoType' => 'info',
224+
'tips' => '通用回调地址(callback url)为: <code>' . PUOCK_ABS_URI . '/inc/oauth/callback/linuxdo.php</code>'
225+
],
226+
[
227+
'id' => 'oauth_linuxdo',
228+
'label' => 'LinuxDO ' . __('登录', PUOCK),
229+
'type' => 'switch',
230+
'sdt' => 'false',
231+
],
232+
[
233+
'id' => 'oauth_linuxdo_id',
234+
'label' => 'LinuxDO Client ID',
235+
'sdt' => '',
236+
'showRefId' => 'oauth_linuxdo',
237+
],
238+
[
239+
'id' => 'oauth_linuxdo_secret',
240+
'label' => 'LinuxDO Client Secret',
241+
'sdt' => '',
242+
'showRefId' => 'oauth_linuxdo',
243+
],
244+
]
245+
],
212246
],
213247
];
214248
}

0 commit comments

Comments
 (0)