-
Notifications
You must be signed in to change notification settings - Fork 2
/
Action.php
121 lines (107 loc) · 3.65 KB
/
Action.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
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* 行动组件
*
* @Author 陆之岇(Kraity)
* @Studio 南博网络科技工作室
* @GitHub https://github.com/krait-team
*/
class Nabo_Action extends Typecho_Widget implements Widget_Interface_Do
{
/**
* @var Typecho_Db
*/
protected $db;
/**
* @var Widget_User
*/
protected $user;
/**
* @var Widget_Options
*/
protected $options;
/**
* @param $options
* @throws Typecho_Exception
*/
public function updateOption($options)
{
foreach ($options as $name => $value) {
if ($this->db->fetchObject($this->db->select(array('COUNT(*)' => 'num'))
->from('table.options')->where('name = ? AND user = ?', $name, $this->user->uid))->num > 0) {
$this->widget('Widget_Abstract_Options')
->update(array('value' => $value), $this->db->sql()->where('name = ? AND user = ?', $name, $this->user->uid));
} else {
$this->widget('Widget_Abstract_Options')->insert(array(
'name' => $name,
'value' => $value,
'user' => $this->user->uid
));
}
}
}
/**
* @throws Typecho_Db_Exception
* @throws Typecho_Exception
*/
public function updateProfile()
{
$this->user->pass('subscriber');
if (Nabo_Plugin::profile(false)->validate()) {
$this->response->goBack();
}
// temporary
$temporary = $this->request->from('uin', 'markdown', 'pushKey', 'allowPush', 'allowCert', '_markdown');
$this->updateOption([
'markdown' => $temporary['_markdown'] ? 1 : 0
]);
unset($temporary['_markdown']);
if (empty($temporary['uin'])) {
$error = true;
} else {
if ($temporary['uin'] < 100001) {
$this->throwRedirect('南博号不正确');
}
$error = false;
}
if ($temporary['pushSafe'] == 1 && (empty($temporary['pushKey']) || strlen($temporary['pushKey']) < 32)) {
$this->throwRedirect('推送密匙不正确, 无法开启推送');
}
if ($temporary['allowCert'] == 1) {
if ($error) {
$this->throwRedirect('南博号不正确, 无法开启密匙登录');
}
$first = $this->db->fetchRow($this->db->select()
->from('table.nabo')
->where('uid = ?', $this->user->uid));
if (empty($first['certKey'])) {
$this->throwRedirect('未进行扫码绑定, 无法开启密匙登录');
}
}
$this->db->query($this->db->update('table.nabo')
->rows($temporary)
->where('uid = ?', $this->user->uid));
$this->throwRedirect('南博用户基本信息已经被更新', 'success');
}
/**
* @param $notice
* @param string $typeFix
* @throws Typecho_Exception
*/
private function throwRedirect($notice, $typeFix = 'error')
{
$this->widget('Widget_Notice')->set(_t($notice), 'notice', $typeFix);
$this->response->redirect(Typecho_Common::url('extending.php?panel=Nabo%2FManage.php', $this->options->adminUrl));
}
/**
* @throws Typecho_Db_Exception
* @throws Typecho_Exception
*/
public function action()
{
$this->db = Typecho_Db::get();
Typecho_Widget::widget('Widget_User')->to($this->user);
$this->options = Typecho_Widget::widget('Widget_Options');
$this->on($this->request->is('do=update-profile'))->updateProfile();
}
}