-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaccount.php
executable file
·83 lines (68 loc) · 2.32 KB
/
daccount.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
<?php
class Daccount extends DNS_Model
{
//缓存下账户,多次获取时不需要重复读取数据库
private $cache = array();
public function __construct() {
parent::__construct();
}
/**
* 获取DNSPOD账户列表
* @param type $user_id
* @return type
*/
public function get_list($user_id = 0)
{
$user_id = (int)$user_id;
if (isset($this->cache[$user_id])) {
return $this->cache[$user_id];
}
$query = $this->db
->select('`id`,`dnspod_username`,`dnspod_password`,`nickname`,`created_at`')
->from('account')
->where('uid', $user_id)
->get()
;
if ($query->num_rows() == 0) {
return array();
}
$account_list = parent::_ary_change_key($query->result_array(), 'id', 'intval');
$this->cache[$user_id] = $account_list;
return $account_list;
}
/**
* 添加DNSPOD账户
* @param array $data
* @return boolean
*/
public function add(array &$data)
{
$fields_required = array('uid', 'dnspod_username', 'dnspod_password', 'nickname');
foreach ($fields_required as $f) {
if ( ! isset($data[$f]) OR empty($data[$f])) {
$this->error = $f.'不能为空';
return false;
}
}
if ($this->account_exists($data['uid'], $data['dnspod_username'])) {
$this->error = '该账户已经在您帐下!';
return false;
}
$data['uid'] = (int)$data['uid'];
//密码加密后保存
$this->load->library('encrypt');
$data['dnspod_password'] = $this->encrypt->encode($data['dnspod_password']);
$this->db->insert('account', $data);
return true;
}
public function account_exists($uid, $username = '')
{
$query = $this->db
->select('COUNT(*) AS `num`')
->from('account')
->where('uid', (int)$uid)
->where('dnspod_username', $username)
->get();
return ($query->first_row()->num > 0);
}
}