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)); } }
/** * 通过 email 激活用户账号. * * @access public * @return void * @author Liuping <*****@*****.**> */ public function activateAccountByEmail() { // info json_decode 后包含的项 // ['account' => $username, 'email' => $email, 'code' => $code, 'referer' => ''] $param = I('get.info', ''); if (empty($param)) { $this->error(L('CONTROLLER_MSG37'), U('Home/Index/index')); } // 解密 $param = rawurldecode($param); $param = base64_decode($param); $param = authcode($param, 'DECODE', C('AUTH_KEY')); $param = json_decode($param, TRUE); $referer = $param['referer']; // 先判断该验证码是否有效, 有效再继续做是否激活处理 $modelCaptcha = new UserCaptchaModel(); $res = $modelCaptcha->checkEmailCode($param['email'], $param['code']); if (FALSE === $res) { // 激活码无效 $this->error(L('CONTROLLER_MSG38'), U('Home/Index/index')); } // 激活码有效 $model = new UserModel(); // 查询用户信息, 此处未加 email 条件, 主要考虑在发送邮件时, 允许更改收件邮箱地址 $userinfo = $model->where('username=:username')->bind([':username' => $param['account']])->find(); if (NULL === $userinfo || FALSE === $userinfo) { $this->error(L('CONTROLLER_MSG37'), U('Home/Index/index')); } else { $flag = TRUE; // 认为是已激活状态 // 未激活该用户账号 if (2 != $userinfo['is_active']) { $model->is_active = 2; // 1:手机已激活 2: 手机和邮箱都已激活 $model->email = $param['email']; // 更新用户 email 为该可激活的邮箱 if (FALSE === $model->save()) { $flag = FALSE; } } if ($flag) { if ($this->isLogin()) { // 已登录状态清除 session $this->logout(); } // 没传 referer 时, 直接跳转到登录页面 if (empty($referer)) { $this->success(L('CONTROLLER_MSG41'), U('Home/User/login')); } else { $this->redirect($referer); } } else { $this->error(L('CONTROLLER_MSG47'), U('Home/Index/index')); } } }