/** * DIY用户账号信息修改提交处理. * * @access public * @return void * @author Liuping <*****@*****.**> */ public function accInfoAction() { $userId = intval(I('post.id', '')); if ($userId < 1) { $this->error('错误的参数'); } $_post = I('post.'); $where = "user_type=0 AND is_active>=2 AND id=:id"; // 只能是普通用户 $binds = [':id' => $userId]; $model = M('User'); $userInfo = $model->where($where)->bind($binds)->find(); // 检查该用户是否有效 if (NULL === $userInfo || FALSE === $userInfo) { $this->error('错误的参数'); } // 执行验证规则 $newSaveData = $model->validate($this->_userRules)->create($_post); if (!$newSaveData) { // 验证失败 $this->error($model->getError()); } // 检查用户邮箱和手机号是否已存在, 排除本身 $res = $this->checkExistEmail($userId, $_post['email']); if ($res) { $this->error('该邮箱已存在'); } $res = $this->checkExistTel($userId, $_post['telephone']); if ($res) { $this->error('该手机号已存在'); } // 有重置密码 if (isset($newSaveData['passwd'])) { $newSaveData['passwd'] = getMyMd5($newSaveData['passwd'], $userInfo['salt']); } // 都验证过了, 执行修改 $res = $model->where('id=:id')->bind(':id', $userId)->save($newSaveData); if (FALSE === $res) { $this->error('修改失败'); } else { $_mark = session('adminUser') . '在' . date('Y-m-d H:i:s') . ', 编辑了一个用户 : ' . $userInfo['username']; system_log($_mark, $model->getTableName(), $userId, 'e', $_post, $userInfo, 0); $this->success('修改成功'); } }
/** * 注册处理 * * @access public * @return void * @author Liuping <*****@*****.**> */ public function registerAction() { // 用于接收 post $postData = $result = array(); $postData['username'] = I('post.username', ''); $postData['passwd'] = I('post.password', ''); $postData['confirmPwd'] = I('post.reenter', ''); $postData['email'] = I('post.email', ''); $phone = I('post.mb', ''); $phoneCode = I('post.yz', ''); $prefix = I('post.mobilePrefix', ''); // 手机号连接上国家代码 $newphone = $this->processMobile($prefix, $phone); $modelUserCap = new UserCaptchaModel(); // 实例化 UserModel $modelUser = new UserModel(); $postData['region'] = $prefix; $postData['telephone'] = $phone; if (!$modelUserCap->checkPhoneCode($newphone, $phoneCode)) { $result['status'] = 0; $result['msg'] = L('CONTROLLER_MSG27'); } elseif ($modelUser->checkExistTel($prefix, $phone)) { $result['status'] = 0; $result['msg'] = L('CONTROLLER_MSG10'); } else { if ($modelUser->create($postData)) { // 验证表单数据成功 // 获取随机加密盐值 $salt = $this->getRandSalt(); // 用户注册时默认的配置项 $conf = C('DEFAULT_USER_REGISTER'); // 注册时默认的用户组 id $modelUser->gid = $conf['groupId']; $modelUser->passwd = getMyMd5($modelUser->passwd, $salt); $modelUser->region = $prefix; $modelUser->telephone = $phone; $modelUser->regip = get_client_ip(0, TRUE); $modelUser->regdate = time(); $modelUser->salt = $salt; $modelUser->user_type = $conf['userType']; $modelUser->is_active = $conf['isActive']; $res = $modelUser->add(); // 注册成功 if (FALSE !== $res) { $result['status'] = 1; $result['msg'] = L('CONTROLLER_MSG46'); $result['url'] = U('emailActive'); // 获取用户信息写入 session $info = $modelUser->find($res); $this->writeUserInfo($info); //写入推广信息 $popToken = cookie('popToken'); if (!empty($popToken)) { $uid = encrypt($popToken, "D", C('AUTH_KEY')); if (!empty($uid)) { $model = M('market_stats'); $data = ['uid' => $uid, 'type' => '1', 'fuid' => $info['id'], 'time' => time()]; $model->data($data)->add(); } } // 注册成功给用户发送激活邮件 // $this->sendActiveEmail($postData['username'], $postData['email']); } else { // 注册失败 $result['status'] = 0; $result['msg'] = L('CONTROLLER_MSG45'); } unset($postData); } else { // 验证表单失败 $result['status'] = 0; $result['msg'] = $modelUser->getError(); } } // ajax 请求输出 json if (IS_AJAX) { $this->ajaxReturn($result, 'json'); } elseif ($result['status']) { // 注册成功跳转到登录页面 // $this->success($result['msg'], $result['url']); $this->redirect('Home/User/emailActive'); } else { // 注册失败跳转到注册页面 $this->error($result['msg'], U('register')); } }
/** * 验证用户登录信息是否正确 * * @access public * @param string $userName * @param string $passwd 原密文 * @return mixed FALSE 表示验证失败, 成功返回用户信息一维数组 * @author Liuping <*****@*****.**> * @modify 增加中介信息(agent_pid, agent_name, agent_partid, allow_apply_num) */ public function checkLogin($userName, $passwd) { $field = 'a.*, b.fid AS agent_pid, b.name AS agent_name, b.partID AS agent_partid, b.num AS allow_apply_num'; $join = 'LEFT JOIN __USER_AGENT__ AS b ON a.id=b.uid'; $where = "(a.username=:username || a.email=:username || a.telephone=:username) AND is_active>=1"; $info = $this->alias('a')->field($field)->join($join)->where($where)->bind(':username', $userName)->find(); // 没有查到此用户 if (NULL === $info || FALSE === $info) { return FALSE; } // 查到此用户做继续做验证处理 // 加密后的密文 $encryptPwd = getMyMd5($passwd, $info['salt']); if (strcmp($info['passwd'], $encryptPwd) !== 0) { return FALSE; } return $info; }