/** * 找回密码 */ public function find() { $step = max(1, (int) $this->input->get('step')); $error = ''; if (IS_POST) { switch ($step) { case 1: if (!$this->check_captcha('code')) { $this->member_msg(lang('m-000')); } if ($uid = get_cookie('find')) { $this->member_msg(lang('m-093'), dr_member_url('login/find', array('step' => 2, 'uid' => $uid)), 1); } else { $name = $this->input->post('name', TRUE); $name = in_array($name, array('email', 'phone')) ? $name : 'email'; $value = $this->input->post('value', TRUE); $data = $this->db->select('uid,username,randcode')->where($name, $value)->limit(1)->get('member')->row_array(); if ($data) { $randcode = dr_randcode(); if ($name == 'email') { $this->load->helper('email'); if (!$this->sendmail($value, lang('m-014'), dr_lang('m-187', $data['username'], $randcode, $this->input->ip_address()))) { $this->member_msg(lang('m-189')); } set_cookie('find', $data['uid'], 300); $this->db->where('uid', $data['uid'])->update('member', array('randcode' => $randcode)); $this->member_msg(lang('m-093'), dr_member_url('login/find', array('step' => 2, 'uid' => $data['uid'])), 1); } else { $result = $this->member_model->sendsms($value, dr_lang('m-088', $randcode)); if ($result['status']) { // 发送成功 set_cookie('find', $data['uid'], 300); $this->db->where('uid', (int) $data['uid'])->update('member', array('randcode' => $randcode)); $this->member_msg(lang('m-093'), dr_member_url('login/find', array('step' => 2, 'uid' => $data['uid'])), 1); } else { // 发送失败 $this->member_msg($result['msg']); } } } else { $error = $name == 'phone' ? lang('m-182') : lang('m-185'); } } break; case 2: if (!$this->check_captcha('code2')) { $this->member_msg(lang('m-000')); } $uid = (int) $this->input->get('uid'); $code = (int) $this->input->post('code'); if (!$uid || !$code) { $this->member_msg(lang('m-001')); } $data = $this->db->where('uid', $uid)->where('randcode', $code)->select('salt,uid,username,email')->limit(1)->get('member')->row_array(); if (!$data) { $this->db->where('uid', $uid)->update('member', array('randcode' => '')); $this->member_msg(lang('m-202'), dr_member_url('login/find')); } $password1 = $this->input->post('password1'); $password2 = $this->input->post('password2'); if ($password1 != $password2) { $error = lang('m-019'); } elseif (!$password1) { $error = lang('m-018'); } else { // 修改密码 $this->db->where('uid', $data['uid'])->update('member', array('randcode' => 0, 'password' => md5(md5($password1) . $data['salt'] . md5($password1)))); if ($this->get_cache('MEMBER', 'setting', 'ucenter')) { uc_user_edit($data['username'], '', $password1, '', 1); } $this->member_msg(lang('m-052'), dr_url('login/index'), 1); } break; } } $this->template->assign(array('step' => $step, 'error' => $error, 'action' => 'find', 'mobile' => $this->get_cache('member', 'setting', 'ismobile'), 'meta_name' => lang('m-014'), 'result_error' => $error)); $this->template->display('find.html'); }
/** * 短信认证验证码发送 */ public function sendsms() { // 重复发送 if (get_cookie('send_sms')) { exit(dr_json(0, lang('m-091'))); } // 是否已经认证过 if ($this->member['ismobile'] && $this->member['phone']) { exit(dr_json(0, lang('m-092'))); } // 安全字符替换 $mobile = dr_safe_replace($this->input->get('phone')); if (strlen($mobile) != 11 || !is_numeric($mobile)) { exit(dr_json(0, lang('m-095'))); } // 号码是否重复 if ($this->db->where('uid<>', $this->uid)->where('phone', $mobile)->count_all_results('member')) { exit(dr_json(0, lang('m-089'))); } $code = dr_randcode(); $result = $this->member_model->sendsms($mobile, dr_lang('m-088', $code)); if ($result['status']) { // 发送成功 $this->db->where('uid', $this->uid)->update('member', array('randcode' => $code, 'phone' => $mobile)); set_cookie('send_sms', 1, 120); exit(dr_json(1, lang('m-093'))); } else { // 发送失败 exit(dr_json(0, $result['msg'])); } }