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 @@ + +
+

请输入注册邮箱

+

+ +
+ +


+
+
+ +
+
+ +
+
+ diff --git a/application/views/forgetpw_success.php b/application/views/forgetpw_success.php new file mode 100644 index 0000000..5ec0f09 --- /dev/null +++ b/application/views/forgetpw_success.php @@ -0,0 +1,20 @@ + + + + + +修改密码成功 + + + +

修改密码成功,请登录您的邮箱查收激活邮件来激活您的帐户!

+ + + \ No newline at end of file diff --git a/application/views/login_form.php b/application/views/login_form.php index 8308a89..e8b71f2 100644 --- a/application/views/login_form.php +++ b/application/views/login_form.php @@ -18,6 +18,8 @@

+
忘记密码
+

diff --git a/application/views/resetpw_activate_footer.php b/application/views/resetpw_activate_footer.php new file mode 100644 index 0000000..691287b --- /dev/null +++ b/application/views/resetpw_activate_footer.php @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/application/views/resetpw_activate_header.php b/application/views/resetpw_activate_header.php new file mode 100644 index 0000000..66bae66 --- /dev/null +++ b/application/views/resetpw_activate_header.php @@ -0,0 +1,8 @@ + + + + +北大赛账户激活 + + + diff --git a/application/views/resetpw_activate_info.php b/application/views/resetpw_activate_info.php new file mode 100644 index 0000000..8fe4ced --- /dev/null +++ b/application/views/resetpw_activate_info.php @@ -0,0 +1,59 @@ + +
+

重置密码

+
+ + + + + + + + +
+ +


+ +
+ +


+
+
+ +
+
+ +
+
+ diff --git a/application/views/resetpw_form.php b/application/views/resetpw_form.php new file mode 100644 index 0000000..a4cb460 --- /dev/null +++ b/application/views/resetpw_form.php @@ -0,0 +1,66 @@ + + + +
+

重置密码

+
+ +
+ +


+ +
+ +


+
+
+ +
+
+ +
+
+
+ + + +

激活码无效或您已成功激活。

+
+ + +

激活码不存在。

+
+ + + diff --git a/application/views/resetpw_success.php b/application/views/resetpw_success.php new file mode 100644 index 0000000..5ec0f09 --- /dev/null +++ b/application/views/resetpw_success.php @@ -0,0 +1,20 @@ + + + + + +修改密码成功 + + + +

修改密码成功,请登录您的邮箱查收激活邮件来激活您的帐户!

+ + + \ No newline at end of file diff --git a/assets/js/.Rhistory b/assets/js/.Rhistory new file mode 100644 index 0000000..e69de29 diff --git a/assets/js/race.js b/assets/js/race.js index 1f8bfe2..1738a25 100755 --- a/assets/js/race.js +++ b/assets/js/race.js @@ -184,6 +184,71 @@ function postSignup() { } +function forgetpw() { + var mail = $("#mail").val(); + + //The following part of code is for front-end validation. + + + if (mail == "") { + alert("邮箱不能为空!"); + $("#mail").focus(); + return; + } + + //Organize the data and post to the controller. + var data = { + mail: mail, + }; + $.post(controller, data, function(data) { + if (data.code == "200") { + alert("发送验证码成功!请登录您的邮箱查看激活邮件!"); + window.location.assign(directto); + } else { + alert(data.msg); + } + }) + +} + +function resetpw() { + var password = $.md5($("#password").val()); + var passconf = $.md5($("#passconf").val()); + + //The following part of code is for front-end validation. + + if (password == "") { + alert("密码不能为空!"); + $("#password").focus(); + return; + } + if (passconf == "") { + alert("请确认您的密码!"); + $("#passconf").focus(); + return; + } + if (passconf != password) { + alert("两次输入的密码不同,请重新确认!"); + $("#passconf").focus(); + return; + } + + //Organize the data and post to the controller. + var data = { + password: password, + passconf: passconf + }; + $.post(controller, data, function(data) { + if (data.code == "200") { + alert("修改密码成功!请重新登录您的账户!"); + window.location.assign(directto); + } else { + alert(data.msg); + } + }) + +} + /* * This function is called when clicking 'save'. * It will store the individual information into cookie. diff --git a/resetpw_activate_info.php b/resetpw_activate_info.php new file mode 100644 index 0000000..8e0fba7 --- /dev/null +++ b/resetpw_activate_info.php @@ -0,0 +1 @@ +

\ No newline at end of file