diff --git a/application/config/constants.php b/application/config/constants.php
index f6ae211..946f8e5 100644
--- a/application/config/constants.php
+++ b/application/config/constants.php
@@ -74,10 +74,14 @@
'200' => 'OK.',
'201' => '用户尚未激活,请您前往注册邮箱查收激活邮件!',
'202' => '用户尚未通过审核,请您稍后登录!',
+ '203' => '用户未通过重置密码验证,请重新验证!',
'204' => '用户不存在,请注册!',
'205' => '注册已截止',
+ '206' => '两次密码不一致,请重新输入!',
'400' => '存在不合法输入,请检查手机号、邮箱等信息是否正确填写!',
'401' => '密码错误,请重新输入!',
+ '402' => '邮箱有误,请重新输入!',
+ '403' => '重置密码激活链接已成功发送,请查收!',
// Individual Registration Error.
'999' => '人员名单不能为空。',
'1000' => '第{order}个人的姓名不合法。',
diff --git a/application/config/form_validation.php b/application/config/form_validation.php
index 8975529..c70e162 100644
--- a/application/config/form_validation.php
+++ b/application/config/form_validation.php
@@ -59,6 +59,25 @@
'label' => '密码',
'rules' => 'required|md5'
)
+ ),
+ 'forgetpw' => array(
+ array(
+ 'field' => 'mail',
+ 'label' => '电子邮箱',
+ 'rules' => 'trim|required|valid_email|xss_clean'
+ )
+ ),
+ 'resetpw' => array(
+ array(
+ 'field' => 'password',
+ 'label' => '密码',
+ 'rules' => 'required|matches[passconf]|md5'
+ ),
+ array(
+ 'field' => 'passconf',
+ 'label' => '再次输入密码',
+ 'rules' => 'required|md5'
+ )
)
);
diff --git a/application/controllers/user.php b/application/controllers/user.php
index d94ecfa..ebf275e 100644
--- a/application/controllers/user.php
+++ b/application/controllers/user.php
@@ -110,6 +110,77 @@ public function signup() {
exit(err_msg($err_code));
}
}
+ public function forgetpw() {
+
+ if ($this->input->server('REQUEST_METHOD') == 'GET') {
+ if ($this->session->userdata('logged_in')) {
+ redirect(base_url(), 'refresh');
+ }
+ $this->load->view('header_homepage');
+ $this->load->view('add_hilight_nav2');
+ $this->load->view('forgetpw_form');
+ $this->load->view('footer');
+ }
+
+ if ($this->input->server('REQUEST_METHOD') == 'POST') {
+ $login_info = $this->input->post();
+
+ header('Content-Type: application/json');
+ if ($this->form_validation->run('forgetpw') == false) {
+ $err_code = '400';
+ exit(err_msg($err_code));
+ }
+ $user_info = $this->user->get_user_by_email($login_info['mail']);
+ if ($user_info == NULL) {
+ exit(err_msg('204'));
+ } elseif (!$user_info['activated']) {
+ exit(err_msg('201'));
+ } elseif (!$user_info['confirmed']) {
+ exit(err_msg('202'));
+ } else {
+ $err_code = '200';
+ $token = $this->user->set_token($user_info['mail']);
+ $this->email->send_resetpw_confirm_mail($user_info['mail']);
+ }
+ exit(err_msg('403'));
+ }
+ }
+
+ public function resetpw() {
+
+ if ($this->input->server('REQUEST_METHOD') == 'GET') {
+ if ($this->session->userdata('logged_in')) {
+ redirect(base_url(), 'refresh');
+ }
+ $this->load->view('header_homepage');
+ $this->load->view('add_hilight_nav2');
+ $this->load->view('resetpw_form');
+ $this->load->view('footer');
+ }
+
+ if ($this->input->server('REQUEST_METHOD') == 'POST') {
+ $login_info = $this->input->post();
+
+ header('Content-Type: application/json');
+ if ($this->form_validation->run('resetpw') == false) {
+ $err_code = '400';
+ exit(err_msg($err_code));
+ }
+ $user_info = $this->user->get_user_by_email($login_info['mail']);
+ if ($user_info == NULL) {
+ exit(err_msg('204'));
+ } elseif (!$user_info['activated']) {
+ exit(err_msg('201'));
+ } elseif (!$user_info['confirmed']) {
+ exit(err_msg('202'));
+ } else {
+ $err_code = '200';
+ $token = $this->user->set_token($user_info['mail']);
+ $this->email->send_resetpw_confirm_mail($user_info['mail']);
+ }
+ exit(err_msg('403'));
+ }
+ }
/*
* Show registration result for the user.
@@ -197,6 +268,16 @@ public function activate() {
$this->load->view('activate_footer');
}
+ public function resetpw_activate() {
+ $this->load->model('user_model', 'user');
+ $token = $this->uri->segment(3);
+ $status = $this->user->activate($token);
+ $data = array('status' => $status);
+ $this->load->view('header_homepage');
+ $this->load->view('resetpw_form',$data);
+ $this->load->view('footer');
+ }
+
/*
* Export an Excel file containing all the information.
*/
diff --git a/application/libraries/MY_Email.php b/application/libraries/MY_Email.php
index 6e6da1d..7327ecc 100644
--- a/application/libraries/MY_Email.php
+++ b/application/libraries/MY_Email.php
@@ -59,7 +59,7 @@ public function send_mail(
* Send account confirmation email.
*/
public function send_account_confirm_mail($mail) {
- $subject = '第十六届全国高校自行车交流赛帐户确认(含ID)';
+ $subject = '第十七届全国高校自行车交流赛帐户确认(含ID)';
$token = $this->ci->user->get_token($mail);
$link = site_url('user/activate') . '/' . $token;
$id = $this->ci->user->get_id($mail);
@@ -68,11 +68,24 @@ public function send_account_confirm_mail($mail) {
$this->send_mail($mail, $subject, $message);
}
+ public function send_resetpw_confirm_mail($mail) {
+
+ $subject = '第十七届全国高校自行车交流赛帐户修改密码';
+ $token = $this->ci->user->get_token($mail);
+ $link = site_url('user/resetpw_activate') . '/' . $token;
+ $id = $this->ci->user->get_id($mail);
+ $id_message='
贵高校本次比赛的ID是' . $id . ',
祝好!
北京大学自行车协会';
+ $message = '请点击以下链接重置帐户密码' . $link . $id_message;
+ $this->send_mail($mail, $subject, $message);
+
+ }
+
+
/*
* Send mail after money is received.
*/
public function send_fee_received_mail($mail, $school, $fee) {
- $subject = '第十六届全国高校自行车交流赛缴费确认';
+ $subject = '第十七届全国高校自行车交流赛缴费确认';
$id = $this->ci->user->get_id($mail);
$id_message='
贵高校本次比赛的ID是' . $id . ',请领队同学务必牢记,并在比赛签到时出示。
祝好!
北京大学自行车协会';
$message = $school . ',
贵校车协交来的' . $fee . '元参赛费用已经收到,感谢你们对北大赛的大力支持!如有任何问题,请直接与各地区负责联系。' . $id_message;
diff --git a/application/models/user_model.php b/application/models/user_model.php
index d3a5bcb..9276d0a 100644
--- a/application/models/user_model.php
+++ b/application/models/user_model.php
@@ -243,6 +243,20 @@ public function activate($token) {
}
}
+ public function resetpw_activate($token) {
+ if (!$token) {
+ return 2;
+ } else {
+ $query = $this->db->where('token', $token)->get('users');
+ if ($query->num_rows() == 0) {
+ return 1;
+ } else {
+ $this->db->where('token', $token)->update('users', array('token' => '0'));
+ return 0;
+ }
+ }
+ }
+
/*
* This function freezes a certain user.
*/
diff --git a/application/views/forgetpw_form.php b/application/views/forgetpw_form.php
new file mode 100644
index 0000000..13fa29e
--- /dev/null
+++ b/application/views/forgetpw_form.php
@@ -0,0 +1,40 @@
+
+