Skip to content

Addpassword #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions application/config/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@
'200' => 'OK.',
'201' => '用户尚未激活,请您前往注册邮箱查收激活邮件!',
'202' => '用户尚未通过审核,请您稍后登录!',
'203' => '用户未通过重置密码验证,请重新验证!',
'204' => '用户不存在,请注册!',
'205' => '注册已截止',
'206' => '两次密码不一致,请重新输入!',
'400' => '存在不合法输入,请检查手机号、邮箱等信息是否正确填写!',
'401' => '密码错误,请重新输入!',
'402' => '邮箱有误,请重新输入!',
'403' => '重置密码激活链接已成功发送,请查收!',
// Individual Registration Error.
'999' => '人员名单不能为空。',
'1000' => '第{order}个人的姓名不合法。',
Expand Down
19 changes: 19 additions & 0 deletions application/config/form_validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
)
);

Expand Down
81 changes: 81 additions & 0 deletions application/controllers/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*/
Expand Down
17 changes: 15 additions & 2 deletions application/libraries/MY_Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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='<br><br>贵高校本次比赛的ID是<b>' . $id . '</b>,<br><br>祝好!<br><br>北京大学自行车协会';
$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='<br><br>贵高校本次比赛的ID是<b>' . $id . '</b>,请领队同学务必牢记,并在比赛签到时出示。<br><br>祝好!<br><br>北京大学自行车协会';
$message = $school . ',<br><br>贵校车协交来的' . $fee . '元参赛费用已经收到,感谢你们对北大赛的大力支持!如有任何问题,请直接与各地区负责联系。' . $id_message;
Expand Down
14 changes: 14 additions & 0 deletions application/models/user_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
40 changes: 40 additions & 0 deletions application/views/forgetpw_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script type="text/javascript">
var controller = "<?=site_url('user/forgetpw')?>";
var directto = "<?=base_url()?>";
</script>
<div class="signcontainer">
<h3>请输入注册邮箱 </h3>
<br/><br/>
<label class="col-sm-4">电子邮箱</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="mail" id="mail">
</div><br/><br/>
<hr/>
<div class="col-sm-6">
<button class="btn btn-warning btn-block" id="btn-back">返回</button>
</div>
<div class="col-sm-6">
<button class="btn btn-success btn-block" id="btn-forgetpw">发送验证码</button>
</div>
</div>
<script>
$("#passconf").bind("keypress",function(event) {
if(event.keyCode == "13") {
$("#btn-forgetpw").disabled=true;
$("#btn-forgetpw").text("发送中...");
forgetpw();
$("#btn-forgetpw").disabled=false;
$("#btn-forgetpw").text("发送验证码");
}
});
$("#btn-back").click(function() {
window.location.href = "<?=site_url('user/login')?>";
});
$("#btn-forgetpw").click(function() {
this.disabled=true;
$(this).text("发送中...");
forgetpw();
this.disabled=false;
$(this).text("发送验证码");
});
</script>
20 changes: 20 additions & 0 deletions application/views/forgetpw_success.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Created by PhpStorm.
* User: Jeldor
* Date: 1/26/15
* Time: 19:18
*/
?>

<!DOCTYPE html>
<html>
<head>
<title>修改密码成功</title>
</head>
<body>

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

</body>
</html>
2 changes: 2 additions & 0 deletions application/views/login_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
</div>
<br/>
<br/>
<div class="col-sm-4" ><a href="<?=site_url('user/forgetpw')?>">忘记密码</a></div>
<br/>
<hr/>
<div class="col-sm-6">
<button class="btn btn-warning btn-block" id="btn-signup">注册</button>
Expand Down
2 changes: 2 additions & 0 deletions application/views/resetpw_activate_footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
</body>
</html>
8 changes: 8 additions & 0 deletions application/views/resetpw_activate_header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>北大赛账户激活</title>
<link rel="shortcut icon" href="/assets/images/essentials/capu.jpg">
</head>
<body>
59 changes: 59 additions & 0 deletions application/views/resetpw_activate_info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<script type="text/javascript">
var controller = "<?=site_url('user/resetpw')?>";
var directto = "<?=base_url()?>";
</script>
<div class="signcontainer">
<h3>重置密码 </h3>
<hr/>







<label class="col-sm-4">新密码</label>
<div class="col-sm-8">
<input type="password" class="form-control" name="password" id="password">
</div><br/><br/>
<label class="col-sm-4">新密码确认</label>
<div class="col-sm-8">
<input type="password" class="form-control" name="passconf" id="passconf">
</div><br/><br/>
<hr/>
<div class="col-sm-6">
<button class="btn btn-warning btn-block" id="btn-back">返回</button>
</div>
<div class="col-sm-6">
<button class="btn btn-success btn-block" id="btn-signup">重置</button>
</div>
</div>
<script>
$("#passconf").bind("keypress",function(event) {
if(event.keyCode == "13") {
$("#btn-signup").disabled=true;
$("#btn-signup").text("重置中...");
resetpw();
$("#btn-signup").disabled=false;
$("#btn-signup").text("重置");
}
});
$("#btn-back").click(function() {
window.location.href = "<?=site_url('user/login')?>";
});
$("#btn-signup").click(function() {
this.disabled=true;
$(this).text("重置中...");
resetpw();
this.disabled=false;
$(this).text("重置");
});
$(document).ready(function() {
var signUpDeadline = new Date("<?= $GLOBALS['SIGN_UP_DEADLINE']?>");
var now = new Date();
if (now > signUpDeadline) {
alert("注册已截止");
window.location.href = "<?=site_url('')?>"
}
});
</script>
Loading