/** * 用户主页 */ public function home() { $this->checkLogin(); $model = new UserModel(); if (IS_POST) { $avatar = I('avatar'); $nickname = I('nickname'); $password = I('password'); if (!$model->create()) { $this->error($model->getError()); } $data = ['avatar' => $avatar, 'nickname' => $nickname]; if (!empty($password)) { $data['password'] = $password; } if ($model->where(array('userId' => $this->user['userId']))->save() === false) { $this->error('编辑失败'); } $this->success('编辑成功'); } else { $user = $model->find($this->user['userId']); $this->assign('user', $user); $this->display(); } }
/** * 删除用户 * @param $id */ public function delete($id) { try { $model = new UserModel(); if ($model->delete($id) === false) { throw new Exception('删除失败'); } $this->redirect('index'); } catch (Exception $e) { $this->error($e->getMessage()); } }
public function login($username = '', $password = '', $verify = '', $ajax = true) { layout(false); if (IS_POST) { if (C('VERIFY') && $verify != session(C('VERIFY_CODE'))) { // 验证码不对 if ($ajax) { $this->ajaxReturn(['status' => -1, 'msg' => '验证码错误']); } $this->error('验证码错误'); } $userInfo = UserModel::instance()->findByName($username); if (!$userInfo) { $this->assign("error", "用户不存在"); } else { if ($userInfo && $userInfo['password'] == processPwd($password)) { // 登陆成功 session(C('LOGIN_SESSION'), $userInfo); $this->redirect('index/index'); } else { $this->assign("error", "密码错误"); } } $this->assign("username", $username); $this->assign("password", $password); } if (I("error")) { $this->assign("error", "抱歉,您的账号已被禁用~"); } $this->display(); }
public function set_password() { if (IS_POST) { $userModel = new UserModel(); if (!$userModel->verifyCode($this->user['mobile'], I('post.sms_code'))) { $this->error($userModel->getError()); } $userMoneyModel = new UserMoneyModel(); if (!$userMoneyModel->setPassword($this->user['uid'], I('post.password', 'intval'))) { $this->error($userMoneyModel->getError()); } $this->success('设置成功', I('to_url') ?: 'index'); } else { $this->display(); } }
public function editShop($id, $data) { PlatformShopModel::instance()->where(['uid' => $id])->setField("name", $data['shopName']); UserModel::instance()->where(['id' => $id])->setField("tel", $data['tel']); if ($data['password'] != '') { UserModel::instance()->where(['id' => $id])->setField("tel", $data['password']); } }
public function _initialize() { if (!UserModel::instance()->isLogin()) { // 判断用户是否登录 $this->redirect("user/login"); } else { $this->user = UserModel::instance(); $this->user->setUser(session(C("LOGIN_SESSION"))); if ($this->user->getId() == 1) { // 管理员 layout(false); $list = PlatformShopModel::instance()->getList(); $this->assign("list", $list); } else { // 店铺用户 if ($this->user->getShopStatus() == 0) { $this->redirect("user/login", ['error' => 1]); } } } }
public function edit($id) { $user = UserModel::instance()->findByProperties("id", $id); $shop = UserModel::instance()->findByProperties("uid", $id, "platform_shop"); $shop[0]['shopName'] = $shop[0]['name']; unset($shop[0]['name']); unset($shop[0]['id']); $data = array_merge($user[0], $shop[0]); if ($_POST) { PlatformShopModel::instance()->editShop($id, $_POST); $this->_success("编辑成功", "/admin/index/index/"); } $this->assign('data', $data); $this->display(); }
public function logout() { $userModel = new UserModel(); $userModel->logout(); redirect('/public/login?redirect=/'); }
public function user_agreement_job_service() { if (IS_POST) { if (empty(I('post.sms_code', ''))) { $this->_error('填写验证码'); } if (I('post.agree') != 'on') { $this->_error('请选择同意协议'); } $userModel = new UserModel(); if (!$userModel->verifyCode($this->user->self('mobile'), I('post.sms_code'))) { $this->_error($userModel->getError()); } M('job_user')->add(['uid' => $this->user->self('uid'), 'is_agree_contract' => 1], null, true); $this->_success($userModel->getError()); } else { return $this->display(); } }