forked from cynial/STBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
188 lines (163 loc) · 4.29 KB
/
profile.php
File metadata and controls
188 lines (163 loc) · 4.29 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* STBlog Blogging System
*
* 基于Codeigniter的单用户多权限开源博客系统
*
* STBlog is an open source multi-privilege blogging System built on the
* well-known PHP framework Codeigniter.
*
* @package STBLOG
* @author Saturn <[email protected]>
* @copyright Copyright (c) 2009 - 2010, cnsaturn.com.
* @license GNU General Public License 2.0
* @link http://code.google.com/p/stblog/
* @version 0.1.0
*/
// ------------------------------------------------------------------------
/**
* STBLOG Profile Controller Class
*
* 个人设置控制器
*
* @package STBLOG
* @subpackage Controller
* @category Admin Controller
* @author Saturn <[email protected]>
* @link http://code.google.com/p/stblog/
*/
class Profile extends ST_Auth_Controller {
/**
* 传递到对应视图的数据
*
* @access private
* @var array
*/
private $_data = array();
/**
* 构造函数
*
* @access public
* @return void
*/
public function __construct()
{
parent::__construct();
$this->_data['page_title'] = '个人设置';
$this->_data['parentPage'] = 'dashboard';
$this->_data['currentPage'] = 'profile';
}
/**
* 默认执行函数
*
* @access public
* @return void
*/
public function index()
{
$this->auth->exceed('contributor');
$this->load->view('admin/profile', $this->_data);
}
/**
* 修改个人密码
*
* @access public
* @return void
*/
public function updatePassword()
{
$this->form_validation->set_rules('password', '新的密码', 'required|min_length[6]|trim|matches[confirm]');
$this->form_validation->set_rules('confirm', '确认的密码', 'required|min_length[6]|trim');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('admin/profile', $this->_data);
}
else
{
$user = $this->users_mdl->get_user_by_id($this->user->uid);
if($user)
{
$user['password'] = $this->input->post('password', TRUE);
$this->users_mdl->update_user($this->user->uid, $user, FALSE);
}
$this->session->set_flashdata('success', '您的密码已经更新');
redirect('admin/profile');
}
}
/**
* 修改个人信息
*
* @access public
* @return void
*/
public function updateProfile()
{
$this->form_validation->set_rules('screenName', '昵称', 'trim|callback__screenName_check');
$this->form_validation->set_rules('url', '个人主页', 'trim|prep_url');
$this->form_validation->set_rules('mail', '邮箱地址', 'required|trim|valid_email|callback__email_check');
if($this->form_validation->run() == FALSE)
{
$this->load->view('admin/profile', $this->_data);
}
else
{
$user = $this->users_mdl->get_user_by_id($this->user->uid);
if($user)
{
$user['screenName'] = $this->input->post('screenName') ? $this->input->post('screenName',TRUE):trim($user['name']);
$user['url'] = $this->input->post('url',TRUE);
$user['mail'] = $this->input->post('mail',TRUE);
$this->users_mdl->update_user($this->user->uid, $user);
}
$this->auth->process_login($user);//extend the lease
$this->session->set_flashdata('success', '您的档案已经更新');
redirect('admin/profile');
}
}
/**
* 回调函数:检查Email是否唯一
*
* @access public
* @param $str 输入值
* @return bool
*/
public function _email_check($str)
{
if(!empty($str))
{
if($this->users_mdl->check_exist('mail', $str, $this->user->uid))
{
$this->form_validation->set_message('_email_check', '系统已经存在一个为 '.$str.' 的邮箱');
return FALSE;
}
else
{
return TRUE;
}
}
}
/**
* 回调函数:检查screenName是否唯一
*
* @access public
* @param $str 输入值
* @return bool
*/
public function _screenName_check($str)
{
if(!empty($str))
{
if($this->users_mdl->check_exist('screenName',$str, $this->user->uid))
{
$this->form_validation->set_message('_screenName_check', '系统已经存在一个为 '.$str.' 的昵称');
return FALSE;
}
else
{
return TRUE;
}
}
}
}
/* End of file Profile.php */
/* Location: ./application/controllers/admin/Profile.php */