public function update() { $user = new UserModel(); $data = array('id' => 6, 'username' => 'zhangsan', 'password' => '222222'); if (!$user->create($data)) { echo $user->getError(); exit; } else { $user->save(); print_r($user->find(6)); } }
public function doregister() { $verify = new \Think\Verify(); //验证码验证 if (!$verify->check($_POST['code'])) { $this->error('验证码错误', U('Register/register')); } else { $user = new UserModel('user'); if (!$user->create()) { $this->error($user->getError()); } if ($user->add() > 0) { $_SESSION['email'] = I('post.email'); $email = $_SESSION['email']; //获取当前用户ID $rs = $user->where(array('email' => $email))->find(); $id = $rs['id']; $_POST['uid'] = $id; //为用户创建好友表 $friend = D('Friend'); $friend->create(); $friend->add(); //初始化日志分类 $log = D('LogCate'); $log->create(); $log->add(); //初始化头像表 $head = D('HeadImg'); $head->create(); $head->add(); //初始化相册表 $album = D('Album'); $album->create(); $album->add(); $this->success('注册成功', U('Register/success_register')); } else { $this->error('注册失败'); } } }
/** * 注册处理 * * @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')); } }