/** * 检查 学生的 准考证(exam_ticket)/邮箱(email) 和 登录密码是否正确 * @param string $keyword * @param string $password * @return boolean|array */ public function is_valid_student($keyword, $password = null) { $items = array('uid', 'email', 'first_name', 'last_name', 'exam_ticket', 'grade_id', 'sex', 'picture', 'school_id', 'password'); $this->db->select($items); if (is_email($keyword)) { //验证 邮箱 $query = $this->db->get_where(self::$_table_name, array('email' => $keyword), 1); } else { if (is_idcard($keyword)) { //验证 邮箱 $query = $this->db->get_where(self::$_table_name, array('idcard' => $keyword), 1); } else { if (is_numeric($keyword)) { //验证 准考证 $query = $this->db->get_where(self::$_table_name, array('exam_ticket' => $keyword), 1); } else { return false; } } } $row = $query->row_array(); if (!count($row)) { return false; } if (is_null($password)) { return $row; } if ($row['password'] != my_md5($password)) { return false; } unset($row['password']); return $row; }
public static function studentAjaxLogin($param, $bPasswordEnc = false, $bValidateOnly = false) { $resp = new AjaxResponse(); $param = Func::param_copy($param, 'ticket', 'password'); if (empty($param['ticket']) || empty($param['password'])) { $resp->alert('帐号或密码不能为空!'); return $resp; } $where = array(); $bind = array(); if (is_email($param['ticket'])) { $where[] = 'email = ?'; $bind[] = $param['ticket']; } else { if (is_idcard($param['ticket'])) { $where[] = 'idcard = ?'; $bind[] = $param['ticket']; } else { //message('请输入合法的登陆帐号'); $where[] = 'exam_ticket = ? OR external_account = ?'; $bind[] = $param['ticket']; $bind[] = $param['ticket']; } } $where[] = 'password = ?'; if ($bPasswordEnc) { $bind[] = $param['password']; } else { $bind[] = my_md5($param['password']); } $sql_where = implode(') AND (', $where); $sql = <<<EOT SELECT uid, email, first_name, last_name, idcard, exam_ticket, CONCAT(last_name, first_name) AS fullname, external_account, maprule, grade_id, sex, birthday, picture, mobile, is_check, last_login, last_ip, email_validate, status, is_delete, addtime, account, account_status FROM rd_student WHERE ({$sql_where}) EOT; $user = Fn::db()->fetchRow($sql, $bind); if ($user) { $uid = $user['uid']; if (trim($user['picture'])) { $user['avatar_url'] = __IMG_ROOT_URL__ . $user['picture']; } else { $user['avatar_url'] = __IMG_ROOT_URL__ . 'zeming/exam/head.gif'; } $resp->exdata = $user; if (!$bValidateOnly) { $sess = Fn::sess(); if ($sess->userdata('uid') == $uid) { // 当前登录用户已经是请求登录用户,不需要再登录了 $resp->refresh(); } else { $data = array(); $data['last_login'] = time(); $data['last_ip'] = Func::get_client_ip(); Fn::db()->update('rd_student', $data, 'uid = ' . $uid); $sess->set_userdata(array('uid' => $uid, 'uinfo' => $user)); $sql = "SELECT * FROM rd_student_ranking WHERE uid = {$uid}"; $score_ranks = Fn::db()->fetchRow($sql); if (!$score_ranks && $user['grade_id'] == 6) { // 在basic页面会自动判断是否填写完全学生成绩并进行提示跳转 $resp->redirect(site_url('student/profile/basic')); } else { $resp->refresh(); } } } } else { $resp->alert('帐号或密码不正确!'); } return $resp; }
/** * 学生登录检查 */ public function check_login() { // 获取当前 $current_exam = $this->exam_model->get_cookie_current_exam(true); $exam_ticket = trim($this->input->post('exam_ticket')); $password = $this->input->post('password'); if (!strlen($exam_ticket)) { output_json(CODE_ERROR, '请输入登陆帐号.'); } if (!is_email($exam_ticket) && !is_idcard($exam_ticket) && !is_numeric($exam_ticket)) { output_json(CODE_ERROR, '请输入合法的登陆帐号.'); } if (!strlen($password)) { output_json(CODE_ERROR, '登陆密码不能为空.'); } // 检查帐号密码是否正确 $this->load->model('exam/student_model'); $student = $this->student_model->is_valid_student($exam_ticket, $password); if (!$student) { output_json(CODE_ERROR, '登陆帐号或密码不正确,请检查.'); } // 检查学生是否在当前考场中 $this->load->model('exam/exam_place_model'); $exam_place_model = $this->exam_place_model; $place_id = $current_exam['place_id']; $user_id = $student['uid']; if (!$exam_place_model->check_exam_place_student($place_id, $user_id)) { output_json(CODE_ERROR, '很抱歉,您不在本场考试中,有问题请联系监考老师.'); } // 设置考生考卷信息 $place_id = $current_exam['place_id']; $uid = $student['uid']; $this->load->model('exam/exam_test_paper_model'); $this->load->model('exam/exam_place_model'); $test_paper_model = $this->exam_test_paper_model; // 设定考生考卷 /** * 需要事先判断 本场考试 是否已经分配考生试卷 */ $test_papers = $test_paper_model->get_stduent_test_paper($place_id, $uid, 'etp_flag,etp_id', null); $place_subjects = $this->exam_place_model->get_exam_place_subject($place_id); if (count($test_papers) != count($place_subjects)) { $insert_ids = $test_paper_model->set_student_test_paper($place_id, $uid); // 设置考试记录 if ($insert_ids === false) { message('抱歉,该场考试有科目未分配试卷.', 'exam/index/login'); } if (count($insert_ids)) { $this->session->set_userdata(array('etp_id' => implode(',', $insert_ids))); } } else { $insert_ids1 = array(); foreach ($test_papers as $item) { $etp_flag = $item['etp_flag']; if ($etp_flag < 0) { message('抱歉,您在该场考试中有作弊行为,本次考试无效.', 'exam/index/login'); } elseif ($etp_flag > 0) { message('抱歉,您已经交卷了.', 'exam/index/login'); } $insert_ids1[] = $item['etp_id']; } $this->session->set_userdata(array('etp_id' => implode(',', $insert_ids1))); } // 添加考场在考人员统计 // 检查考生是否已经登录过 $this->load->model('exam/student_log_stat_model'); try { $this->student_log_stat_model->set_exam_place_member($current_exam['exam_id'], $current_exam['place_id'], $user_id); } catch (Exception $e) { output_json(CODE_ERROR, $e->getMessage()); } // ==================登录成功操作======================== // 考生登录成功,将考生信息保存在session $student['exam_uid'] = $student['uid']; // 补齐当前考生的 学校 & 年级信息 $this->load->model('exam/school_model'); $school = $this->school_model->get_school_by_id($student['school_id']); $student['school_name'] = count($school) ? $school['school_name'] : '--'; // 获取年级信息 $grade_id = $student['grade_id']; $grades = C('grades'); $student['grade_name'] = isset($grades[$grade_id]) ? $grades[$grade_id] : '--'; // 设置考生的会话 $this->student_model->set_exam_student_session($student); // 判断该考生是否有离开考试界面嫌疑 $this->load->model('exam/student_log_stat_model', 'log_stat_model'); // 如果考试未开始,将考生的活跃时间清零, 如果考生已经在某个当前考场中,移除 if (strtotime($current_exam['start_time']) >= time()) { $this->log_stat_model->remove_student_last_active_time($current_exam['exam_id'], $current_exam['place_id'], $uid); $this->log_stat_model->remove_exam_place_member($current_exam['exam_id'], $current_exam['place_id'], $uid); } if ($this->log_stat_model->has_beyond_active_time($current_exam['exam_id'], $current_exam['place_id'], $uid)) { // 机考日志 exam_log(EXAM_LOG_RELOGIN_AFTER_LEAVE_TEST_PAGE); $this->log_stat_model->set_exam_place_student_active_status($current_exam['exam_id'], $current_exam['place_id'], $uid); } else { // 机考日志 exam_log(EXAM_LOG_LOGIN, array('ip' => $this->input->ip_address())); } output_json(CODE_SUCCESS); }
/** * 学生登录检查 */ public function check_login() { //获取当前 $current_exam = $this->exam_model->get_session_current_exam(true); $exam_ticket = trim($this->input->post('exam_ticket')); $password = $this->input->post('password'); if (!strlen($exam_ticket)) { output_json(CODE_ERROR, '请输入正确的准考证号.'); } if (!is_email($exam_ticket) && !is_idcard($exam_ticket) && !is_numeric($exam_ticket)) { output_json(CODE_ERROR, '请输入合法的登陆帐号.'); } if (!strlen($password)) { output_json(CODE_ERROR, '密码不能为空.'); } //检查帐号密码是否正确 $this->load->model('demo/student_model'); $student = $this->student_model->is_valid_student($exam_ticket, $password); if (!$student) { output_json(CODE_ERROR, '登陆帐号或密码不正确,请检查.'); } $place_id = $current_exam['place_id']; $user_id = $student['uid']; //设置考生考卷信息 $place_id = $current_exam['place_id']; $uid = $student['uid']; $this->load->model('demo/exam_test_paper_model'); $test_paper_model = $this->exam_test_paper_model; //设定考生考卷 /** * 需要事先判断 本场考试 是否已经分配考生试卷 */ $test_papers = $test_paper_model->get_stduent_test_paper($place_id, $uid, 'etp_flag,etp_id', null); if (!count($test_papers)) { $insert_ids = $test_paper_model->set_student_test_paper($place_id, $uid); //设置考试记录 if ($insert_ids === false) { output_json(CODE_ERROR, '抱歉,该学科未分配样卷.', array(), 'demo/index/login'); } if (count($insert_ids)) { $this->session->set_userdata(array('etp_id' => implode(',', $insert_ids))); } } else { $etp_flag = $test_papers[0]['etp_flag']; if ($etp_flag < 0) { output_json(CODE_ERROR, '很遗憾,您在本场考试中有作弊行为,无法继续考试.', array(), 'demo/index/login'); } elseif ($etp_flag > 0) { //用于生成测评报告标识 $all_userdata = $this->session->all_userdata(); $report_mark = $all_userdata['exam_pid'] . '_' . $all_userdata['subject_id'] . '_' . $uid . '_' . $all_userdata['exam_id']; $this->session->set_userdata('report_mark', $report_mark); output_json(CODE_SUCCESS, '抱歉,您已经交卷了, 将为您跳转到您的测评报告.', array(), 'setTimeout(function () {window.location.href="' . site_url('demo/test/report/?act=get') . '";}, 3000);'); //message('抱歉,您已经交卷了, 将为您跳转到您的测评报告.', 'demo/test/report?act=get'); } } //添加考场在考人员统计 //检查考生是否已经登录过 $this->load->model('demo/student_log_stat_model'); try { $this->student_log_stat_model->set_exam_place_member($current_exam['exam_id'], $current_exam['place_id'], $user_id); } catch (Exception $e) { output_json(CODE_ERROR, $e->getMessage()); } //==================登录成功操作======================== //考生登录成功,将考生信息保存在session $student['demo_exam_uid'] = $student['uid']; //补齐当前考生的 学校 & 年级信息 $this->load->model('demo/school_model'); $school = $this->school_model->get_school_by_id($student['school_id']); $student['school_name'] = count($school) ? $school['school_name'] : '--'; //获取年级信息 $grade_id = $student['grade_id']; $grades = C('grades'); $student['grade_name'] = isset($grades[$grade_id]) ? $grades[$grade_id] : '--'; //设置考生的会话 $this->student_model->set_exam_student_session($student); //判断该考生是否有离开考试界面嫌疑 $this->load->model('demo/student_log_stat_model', 'log_stat_model'); if ($this->log_stat_model->has_beyond_active_time($current_exam['exam_id'], $current_exam['place_id'], $uid)) { //机考日志 demo_exam_log(EXAM_LOG_RELOGIN_AFTER_LEAVE_TEST_PAGE); $this->log_stat_model->set_exam_place_student_active_status($current_exam['exam_id'], $current_exam['place_id'], $uid); } else { //机考日志 demo_exam_log(EXAM_LOG_LOGIN, array('ip' => $this->input->ip_address())); } output_json(CODE_SUCCESS); }
public function basic_save() { $uid = $this->_uinfo['uid']; $action = $this->input->post('action'); if ($uid) { $old = StudentModel::get_student($uid); if (empty($old)) { StudentModel::studentAjaxLogout(); message('信息不存在', 'student/index/login'); } } $message = array(); $student_fullname = trim($this->input->post('full_name')); $len = mb_strlen($student_fullname, 'utf-8'); $student['last_name'] = mb_substr($student_fullname, 0, 1, 'utf-8'); $student['first_name'] = mb_substr($student_fullname, 1, $len - 1, 'utf-8'); $student['sex'] = intval($this->input->post('sex')) == 1 ? 1 : 2; $student['birthday'] = strtotime($this->input->post('birthday')); $student['idcard'] = trim($this->input->post('idcard')); $student['external_account'] = trim($this->input->post('student_ticket')); $student['email'] = trim($this->input->post('email')); $student['grade_id'] = intval($this->input->post('grade_id')); $student['school_id'] = intval($this->input->post('school_id')); $student['school_name'] = trim($this->input->post('school_name')); $student['mobile'] = trim($this->input->post('mobile')); if (empty($student['email']) or !is_email($student['email'])) { $message[] = '请正确填写Email地址'; } if (!$uid) { $password = trim($this->input->post('password')); $password_confirm = trim($this->input->post('password_confirm')); if ($action == 'add') { if (is_string($passwd_msg = is_password($password))) { $message[] = $passwd_msg; } else { $student['password'] = $password; } } elseif (strlen($password) > 0) { $student['password'] = $password; } if (isset($student['password']) && $password !== $password_confirm) { $message[] = '两次密码输入不一致!'; } } if (empty($student['first_name']) || empty($student['last_name'])) { $message[] = '请填写姓名'; } if (empty($student['birthday'])) { $message[] = '请填写出生日期'; } if (empty($student['idcard']) || !is_idcard($student['idcard'])) { message('请正确填写身份证号码!'); } if ($student['grade_id'] < 1 or $student['grade_id'] > 12) { $message[] = '请选择就读年级'; } if (empty($student['school_id'])) { $message[] = '请选择就读学校'; } if (strlen($student['mobile']) > 0 && !is_phone($student['mobile'])) { $message[] = '请正确填写手机号码'; } // 检查email是否已注册 $tmp_student = $this->db->select('uid, email_validate')->get_where('student', array('email' => $student['email']))->row_array(); if ($tmp_student && $tmp_student['uid'] != $uid) { $message[] = '该Email地址已被注册!'; } //检查身份证否已注册 $student_idcard = $this->db->select('uid')->get_where('student', array('idcard' => $student['idcard']))->row_array(); if ($student_idcard && $student_idcard['uid'] != $uid) { $message[] = '该身份证号码已被注册'; } if ($_FILES['picture']['name']) { if ($uid) { $config['upload_path'] = _UPLOAD_ROOT_PATH_ . 'uploads/student/' . date('Ym') . '/'; } else { $config['upload_path'] = _UPLOAD_ROOT_PATH_ . 'uploads/student/temp/' . date('Ym') . '/'; } $config['allowed_types'] = 'gif|jpg'; $config['max_size'] = '1024'; $config['max_width'] = '2000'; $config['max_height'] = '2000'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); if ($this->upload->do_upload('picture')) { $student['picture'] = $this->upload->data('file_relative_path'); } else { $msg = array("头像图片限制:", "1、图片大小小于 1M", "2、尺寸不超过2000 x 2000像素", "3、图片格式为 jpg 或 gif"); $message[] = $this->upload->display_errors() . '<hr/><font style="font-weight:bold;font-size:12px;">' . implode('</br>', $msg) . '</font><hr/>'; } } if ($message) { if (!empty($student['picture'])) { @unlink(_UPLOAD_ROOT_PATH_ . $student['picture']); } message(implode('<br/>', $message)); } /*************** COPY FROM base_save() START ***********************/ if ($uid) { $student2 = array(); $student2['grade_id'] = intval($this->input->post('grade_id')); //$student2['address'] = trim($this->input->post('address')); $student2['zipcode'] = trim($this->input->post('zipcode')); $sbinfo = array(); $sbinfo['sb_addr_provid'] = intval($this->input->post('sb_addr_provid')); $sbinfo['sb_addr_cityid'] = intval($this->input->post('sb_addr_cityid')); $sbinfo['sb_addr_areaid'] = intval($this->input->post('sb_addr_areaid')); $sbinfo['sb_addr_desc'] = trim($this->input->post('sb_addr_desc')); // 培训机构、培训课程、授课教师 $sbcinfo = array(); $sbcinfo['no_tiid'] = intval($this->input->post('no_tiid')); $sbcinfo['sbc_tiid'] = intval($this->input->post('sbc_tiid')); $sbcinfo['ti_name'] = trim($this->input->post('ti_name')); $sbcinfo['sbc_corsid'] = intval($this->input->post('sbc_corsid')); $sbcinfo['cors_cmid'] = intval($this->input->post('cors_cmid')); $sbcinfo['cors_name'] = trim($this->input->post('cors_name')); $sbcinfo['sbc_teachers'] = trim($this->input->post('sbc_teachers')); $sbs_stunumtype = $this->input->post('sbs_stunumtype'); if (!is_array($sbs_stunumtype)) { $sbs_stunumtype = array(); } $sbclassid_classid = $this->input->post('sbclassid_classid'); if (!is_array($sbclassid_classid)) { $sbclassid_classid = array(); } /*if (empty($student2['address'])) { $message[] = '请填写家庭地址'; }*/ if (empty($student2['zipcode'])) { $message[] = '请填写邮编'; } if ($sbinfo['sb_addr_provid'] == 0) { $message[] = '请填写家庭所在省市'; } if ($sbinfo['sb_addr_desc'] == '') { $message[] = '请填写家庭住址'; } if (empty($sbcinfo['no_tiid'])) { if ($sbcinfo['ti_name'] == '') { $message[] = '请填写培训机构'; } if ($sbcinfo['cors_name'] == '') { $message[] = '请填写培训课程'; } if ($sbcinfo['sbc_teachers'] == '') { $message[] = '请填写授课教师'; } } if (empty($sbs_stunumtype)) { $message[] = '请选择可接受授课模式'; } if (empty($sbclassid_classid)) { $message[] = '请选择希望辅导难度'; } if ($message) { message(implode('<br/>', $message)); } } /*************** COPY FROM base() END ******************************/ if ($uid) { // 在用户修改信息时才发,注册不发邮件 if (empty($tmp_student) || !$tmp_student['email_validate']) { $student['email_validate'] = 0; // 发送邮件 $email_tpl = C('email_template/register'); $mail = array('student' => $student, 'hash' => email_hash('encode', $uid)); send_email($email_tpl['subject'], $this->load->view($email_tpl['tpl'], $mail, TRUE), $student['email']); } } if ($uid) { unset($student['password']); if (isset($student['external_account'])) { unset($student['external_account']); } // 已注册,更新数据库 if (isset($student['school_name'])) { unset($student['school_name']); } unset($student['uid']); Fn::db()->update('rd_student', $student, 'uid = ' . $uid); if (!empty($student['picture']) && $old['picture']) { @unlink(_UPLOAD_ROOT_PATH_ . $old['picture']); } StudentModel::studentUpdateSession(); /****************** COPY FROM base_save() START ****************/ unset($student2['grade_id']); // 已注册,更新数据库 $db = Fn::db(); $bOk = false; try { if ($db->beginTransaction()) { $db->update('rd_student', $student2, "uid = {$uid}"); $db->delete('t_student_base', "sb_uid = {$uid}"); $sbinfo['sb_uid'] = $uid; $db->insert('t_student_base', $sbinfo); $db->delete('t_student_base_classid', "sbclassid_uid = {$uid}"); foreach ($sbclassid_classid as $v) { $db->insert('t_student_base_classid', array('sbclassid_uid' => $uid, 'sbclassid_classid' => $v)); } $db->delete('t_student_base_stunumtype', "sbs_uid = {$uid}"); foreach ($sbs_stunumtype as $v) { $db->insert('t_student_base_stunumtype', array('sbs_uid' => $uid, 'sbs_stunumtype' => $v)); } $db->delete('t_student_base_course', 'sbc_uid = ' . $uid); if (empty($sbcinfo['no_tiid'])) { $now_time = time(); if (!$sbcinfo['sbc_tiid']) { $row = array('ti_name' => $sbcinfo['ti_name'], 'ti_typeid' => 1, 'ti_flag' => $now_time, 'ti_priid' => 0, 'ti_provid' => $sbinfo['sb_addr_provid'], 'ti_cityid' => $sbinfo['sb_addr_cityid'], 'ti_areaid' => $sbinfo['sb_addr_areaid'], 'ti_addtime' => date('Y-m-d H:i:s', $now_time), 'ti_adduid' => 1); $db->insert('t_training_institution', $row); $ti_id = $db->lastInsertId('t_training_institution', 'ti_id'); $sbcinfo['sbc_tiid'] = $ti_id; } if (!$sbcinfo['sbc_corsid']) { if ($sbcinfo['cors_cmid'] != 1) { $sbcinfo['cors_cmid'] = 2; } $row = array('cors_name' => $sbcinfo['cors_name'], 'cors_cmid' => $sbcinfo['cors_cmid'], 'cors_flag' => $now_time, 'cors_tiid' => $sbcinfo['sbc_tiid'], 'cors_stunumtype' => $sbcinfo['cors_cmid'], 'cors_addtime' => date('Y-m-d H:i:s', $now_time), 'cors_adduid' => 1, 'cors_lastmodify' => date('Y-m-d H:i:s', $now_time)); $db->insert('t_course', $row); $cors_id = $db->lastInsertId('t_course', 'cors_id'); $sbcinfo['sbc_corsid'] = $cors_id; } $db->insert('t_student_base_course', array('sbc_uid' => $uid, 'sbc_idx' => 0, 'sbc_tiid' => $sbcinfo['sbc_tiid'], 'sbc_corsid' => $sbcinfo['sbc_corsid'], 'sbc_teachers' => $sbcinfo['sbc_teachers'])); } $bOk = $db->commit(); if (!$bOk) { $err = $db->errorInfo()[2]; $db->rollBack(); message('学习概况保存失败(' . $err . ')'); } } if (!$bOk) { message('学习概况保存失败(执行事务处理失败)'); } } catch (Exception $e) { message('学习概况保存失败(' . $e->getMessage() . ')'); } /*************** COPY FROM base_save() END ********************/ } else { isset($student['password']) && ($student['password'] = my_md5($student['password'])); if (!isset($student['picture'])) { $student['picture'] = ''; } $old = $this->session->userdata('student'); if ($old) { if (empty($student['password'])) { $student['password'] = $old['password']; } if (!empty($old['picture'])) { if (empty($student['picture'])) { $student['picture'] = $old['picture']; } else { @unlink(_UPLOAD_ROOT_PATH_ . $old['picture']); } } } // 未注册,更新session $this->session->set_userdata(array('student' => $student)); } if (!$uid && C('register_simple')) { $this->session->set_userdata('complete', 1); redirect('student/profile/submit_simple'); } else { if ($uid or $this->session->userdata('complete')) { message('基本信息和学习概况修改成功', 'student/profile/preview', 'success'); } else { redirect('student/profile/preview'); //redirect('student/profile/base'); } } }