public function actionIndex() { $action = tools::val('action', 't'); //操作类型,是登录、注册还是绑定 if (!in_array($action, array('login', 'reg', 'bind'))) { throw new CHttpException(403, '缺少参数'); } if (in_array($action, array('login', 'reg')) && zmf::uid()) { $this->message(0, '您已登录,请勿该操作', $this->referer); } elseif ($action == 'bind' && !zmf::uid()) { $this->redirect(array('site/login')); } zmf::setCookie('lastWeiboAction', $action, $this->cookieTime); $code_url = $this->weiboService->getAuthorizeURL($this->WB_CALLBACK_URL); $this->redirect($code_url); }
public function checkApp() { $code = tools::val('appcode', 1); $time = tools::val('time', 1); $version = tools::val('version', 1); $platform = strtolower(tools::val('platform', 1)); if (!$code || !$time || !$platform || !$version) { self::output(self::getErrorInfo('notInService'), 403); } if ($platform == 'ios') { $_code = $this->iosKey; $this->appPlatform = 'ios'; } else { $_code = $this->androidKey; $this->appPlatform = 'android'; } $this->appCode = $_code; $this->version = $version; if (md5($time . $_code) != $code) { self::output(self::getErrorInfo('dataIncorrect'), 403); } }
public function actionUpdate($type) { if (!in_array($type, array('info', 'passwd', 'tags'))) { $this->message(0, '您的操作有误'); } if (isset($_POST) and !empty($_POST)) { $model = new Users(); if ($type == 'info') { $intoData['truename'] = zmf::filterInput($_POST['truename'], 't', 1); if (!$intoData['truename']) { $this->message(0, '用户名不能为空'); } //如果用户修改了用户名,则判断是否被使用 if ($intoData['truename'] != $this->userInfo['truename']) { $info = Users::getInfoByName($intoData['truename']); if ($info) { $this->message(0, '该用户名已被使用'); } } $intoData['sex'] = tools::val('sex'); $intoData['areaid'] = tools::val('areaid'); $intoData['content'] = zmf::filterInput($_POST['desc'], 't', 1); } elseif ($type == 'passwd') { $old = zmf::filterInput($_POST['old_password'], 't', 1); $info = Users::model()->findByPk($this->uid); if (!$old) { $this->message(0, '请输入原始密码'); } elseif (md5($old) != $info['password']) { $this->message(0, '原始密码不正确'); } if (!$_POST['password']) { $this->message(0, '请输入密码'); } elseif (strlen($_POST['password']) < 5) { $this->message(0, '新密码过短,请重新输入'); } $intoData['password'] = md5($_POST['password']); } elseif ($type == 'tags') { //相关标签 $tags = $_POST['tagnames']; $tags = !empty($tags) ? array_unique(array_filter($tags)) : array(); $tagids = array(); if (!empty($tags)) { foreach ($tags as $str) { $_tmp = explode('-', $str); if ($_tmp[1] > 0) { //添加对应关系 if (Tags::addRelation($_tmp[1], $this->uid, 'user')) { $tagids[] = $_tmp[1]; } } else { //查找是否有对应话题 $_tagid = Tags::findAndAdd($_tmp[0], 'user', $this->uid); if ($_tagid) { $tagids[] = $_tagid; } } } $tagids = !empty($tagids) ? array_unique(array_filter($tagids)) : array(); } $tagStr = join(',', $tagids); $intoData['tagids'] = $tagStr; } zmf::delFCache("userInfo-{$this->uid}"); if ($model->updateByPk($this->uid, $intoData)) { $this->message(1, '修改成功', Yii::app()->createUrl('users/config')); } else { $this->message(1, '修改成功', Yii::app()->createUrl('users/config')); } } $suggestTags = array(); if ($type == 'tags') { //推荐的标签 $suggestTags = Tags::getTops('posts'); } $data = array('info' => $this->userInfo, 'type' => $type, 'suggestTags' => $suggestTags); $this->render('update', $data); }
public function actionUpdate($type) { if (!in_array($type, array('info', 'passwd'))) { $this->message(0, '您的操作有误'); } if (isset($_POST) and !empty($_POST)) { $model = new Users(); if ($type == 'info') { $intoData['username'] = zmf::filterInput($_POST['username'], 't', 1); if (!$intoData['username']) { $this->message(0, '用户名不能为空'); } //如果用户修改了用户名,则判断是否被使用 if ($intoData['username'] != $this->userInfo['username']) { $info = Users::getInfoByName($intoData['username']); if ($info) { $this->message(0, '该用户名已被使用'); } } $intoData['sex'] = tools::val('sex'); $desc = zmf::filterInput($_POST['desc'], 't', 1); $desc = zmf::subStr($desc, 32, 0, ''); } elseif ($type == 'passwd') { $old = zmf::filterInput($_POST['old_password'], 't', 1); $info = Users::model()->findByPk($this->uid); if (!$old) { $this->message(0, '请输入原始密码'); } elseif (md5($old) != $info['password']) { $this->message(0, '原始密码不正确'); } if (!$_POST['password']) { $this->message(0, '请输入密码'); } elseif (strlen($_POST['password']) < 5) { $this->message(0, '新密码过短,请重新输入'); } $intoData['password'] = md5($_POST['password']); } if ($model->updateByPk($this->uid, $intoData)) { if ($type == 'info' && $desc) { UserInfo::addAttr($this->uid, 'info', 'desc', $desc); } $this->message(1, '修改成功', Yii::app()->createUrl('users/config')); } else { if ($type == 'info' && $desc) { UserInfo::addAttr($this->uid, 'info', 'desc', $desc); } $this->message(1, '修改成功', Yii::app()->createUrl('users/config')); } } $data = array('info' => $this->userInfo, 'type' => $type); $this->render('update', $data); }
public function actionLogin($from = '') { if (!Yii::app()->user->isGuest) { $this->message(0, '您已登录,请勿重复操作'); } if (!$from) { $from = 'login'; } $bind = tools::val('bind', 't'); $model = new LoginForm(); //登录 $modelUser = new Users(); //注册 if ($bind == 'weibo') { $strdata = zmf::getCookie('userWeiboData'); //取出cookie中用户的微博信息 if ($strdata) { $data = unserialize($strdata); $modelUser->truename = $data['screen_name']; } } elseif ($bind == 'qq') { $strdata = zmf::getCookie('userQQData'); //取出cookie中用户的微博信息 if ($strdata) { $data = unserialize($strdata); $modelUser->truename = $data['nickname']; } } elseif ($bind == 'weixin') { $strdata = zmf::getCookie('userWeixinData'); //取出cookie中用户的微博信息 if ($strdata) { $data = unserialize($strdata); $modelUser->truename = $data['nickname']; } } if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['ajax']) && $_POST['ajax'] === 'users-addUser-form') { echo CActiveForm::validate($modelUser); Yii::app()->end(); } //登录 if (isset($_POST['LoginForm'])) { $from = 'login'; $model->attributes = $_POST['LoginForm']; if ($model->validate()) { $hasBind = false; //判断是否绑定过微博 if ($bind == 'weibo') { $strdata = zmf::getCookie('userWeiboData'); //取出cookie中用户的微博信息 if (!$strdata) { $model->addError('email', '未能获取微博绑定信息,请重试'); } else { $binddata = unserialize($strdata); } //根据当前用户名获取他是否已经绑定过 $email = $_POST['LoginForm']['email']; $validator = new CEmailValidator(); if ($validator->validateValue($email)) { $user = Users::model()->find('email=:email', array(':email' => $email)); } else { $user = Users::model()->find('truename=:truename', array(':truename' => $email)); } if ($user) { $bindInfo = UserSina::model()->findByPk($user['id']); if ($bindInfo) { $hasBind = true; } $binddata['uid'] = $user['id']; } } elseif ($bind == 'qq') { $strdata = zmf::getCookie('userQQData'); //取出cookie中用户的微博信息 if (!$strdata) { $model->addError('email', '未能获取微博绑定信息,请重试'); } else { $binddata = unserialize($strdata); } //根据当前用户名获取他是否已经绑定过 $email = $_POST['LoginForm']['email']; $validator = new CEmailValidator(); if ($validator->validateValue($email)) { $user = Users::model()->find('email=:email', array(':email' => $email)); } else { $user = Users::model()->find('truename=:truename', array(':truename' => $email)); } if ($user) { $bindInfo = UserQq::model()->findByPk($user['id']); if ($bindInfo) { $hasBind = true; } $binddata['uid'] = $user['id']; } } elseif ($bind == 'weixin') { $strdata = zmf::getCookie('userWeixinData'); //取出cookie中用户的微博信息 if (!$strdata) { $model->addError('email', '未能获取微信绑定信息,请重试'); } else { $binddata = unserialize($strdata); } //根据当前用户名获取他是否已经绑定过 $email = $_POST['LoginForm']['email']; $validator = new CEmailValidator(); if ($validator->validateValue($email)) { $user = Users::model()->find('email=:email', array(':email' => $email)); } else { $user = Users::model()->find('truename=:truename', array(':truename' => $email)); } if ($user) { $bindInfo = UserWeixin::model()->findByPk($user['id']); if ($bindInfo) { $hasBind = true; } $binddata['uid'] = $user['id']; } } if ($hasBind) { $model->addError('email', '该账号已绑定其他账号'); } elseif ($model->login()) { $arr = array('last_login_ip' => ip2long(Yii::app()->request->userHostAddress), 'last_login_time' => time()); Users::model()->updateByPk(Yii::app()->user->id, $arr); Users::model()->updateCounters(array('login_count' => 1), ':id=id', array(':id' => Yii::app()->user->id)); if ($this->referer == '') { $this->referer = array('users/index', 'id' => Yii::app()->user->id); } zmf::delCookie('checkWithCaptcha'); //微博绑定已有账号 if ($bind == 'weibo') { UserSina::addCookie($binddata); } elseif ($bind == 'qq') { UserQq::addCookie($binddata); } elseif ($bind == 'weixin') { UserWeixin::addCookie($binddata); } $this->redirect($this->referer); } } else { zmf::setCookie('checkWithCaptcha', 1, 86400); } } elseif (isset($_POST['Users'])) { $from = 'reg'; //注册 if (UserAction::checkRegTimes()) { $this->message(0, '您今天的注册次数已用完'); } $email = zmf::filterInput($_POST['Users']['email'], 't', 1); $truename = zmf::filterInput($_POST['Users']['truename'], 't', 1); $inputData = array('truename' => $truename, 'password' => $_POST['Users']['password'] != '' ? md5($_POST['Users']['password']) : '', 'email' => $email, 'cTime' => time(), 'register_time' => time(), 'last_login_time' => time(), 'groupid' => zmf::config('userDefaultGroup'), 'register_ip' => ip2long(Yii::app()->request->userHostAddress), 'last_login_ip' => ip2long(Yii::app()->request->userHostAddress)); $modelUser->attributes = $inputData; if ($modelUser->validate()) { if ($modelUser->save()) { $_model = new LoginForm(); $_model->email = $email; $_model->password = $_POST['Users']['password']; $_model->login(); if ($bind == 'weibo') { $strdata = zmf::getCookie('userWeiboData'); //取出cookie中用户的微博信息 if ($strdata) { $binddata = unserialize($strdata); $binddata['uid'] = Yii::app()->user->id; UserSina::addCookie($binddata); } } elseif ($bind == 'qq') { $strdata = zmf::getCookie('userQQData'); //取出cookie中用户的微博信息 if ($strdata) { $binddata = unserialize($strdata); $binddata['uid'] = Yii::app()->user->id; UserQq::addCookie($binddata); } } elseif ($bind == 'weixin') { $strdata = zmf::getCookie('userWeixinData'); //取出cookie中用户的微信信息 if ($strdata) { $binddata = unserialize($strdata); $binddata['uid'] = Yii::app()->user->id; UserWeixin::addCookie($binddata); } } //登录成功后跳转到修改个人资料页面 $this->redirect(array('users/update', 'type' => 'info')); } } } if ($bind) { $this->loginTitle = '绑定已有账户'; $this->regTitle = '完善资料'; } else { $this->loginTitle = '登录'; $this->regTitle = '注册'; } if ($from == 'login') { $this->pageTitle = $this->loginTitle . ' - ' . zmf::config('sitename'); } else { $this->pageTitle = $this->regTitle . ' - ' . zmf::config('sitename'); } //登录页面的幻灯片 $flashArr = Ads::getAllByPo('twindex', 'flash', '', 5); if (!empty($flashArr)) { foreach ($flashArr as $k => $val) { $_imgurl = zmf::uploadDirs($val['cTime'], 'site', $val['classify'], 600) . $val['filePath']; $flashArr[$k]['imgurl'] = $_imgurl; } } $this->render('login', array('model' => $model, 'modelUser' => $modelUser, 'from' => $from, 'flashs' => $flashArr)); }
public static function floatNavUrl($title, $areaid, $htmlOptions = array()) { $c = Yii::app()->getController()->id; $a = Yii::app()->getController()->getAction()->id; if (in_array($c, array('posts'))) { return CHtml::link($title, $areaid ? array('posts/story', 'areaid' => $areaid) : 'javascript:;', $htmlOptions); } elseif (in_array($c, array('question'))) { return CHtml::link($title, $areaid ? array('question/index', 'areaid' => $areaid) : 'javascript:;', $htmlOptions); } elseif (in_array($c, array('position', 'poipost'))) { return CHtml::link($title, $areaid ? array('position/index', 'areaid' => $areaid) : 'javascript:;', $htmlOptions); } elseif (in_array($c, array('travel'))) { return CHtml::link($title, $areaid ? array('travel/index', 'areaid' => $areaid) : 'javascript:;', $htmlOptions); } elseif (in_array($c, array('yueban'))) { return CHtml::link($title, $areaid ? array('yueban/index', 'areaid' => $areaid, 'year' => tools::val('year'), 'month' => tools::val('month'), 'day' => tools::val('day')) : 'javascript:;', $htmlOptions); } elseif (in_array($c, array('goods'))) { return CHtml::link($title, $areaid ? array('goods/index', 'areaid' => $areaid) : 'javascript:;', $htmlOptions); } else { return CHtml::link($title, $areaid ? array('index/show', 'areaid' => $areaid) : 'javascript:;', $htmlOptions); } }
public function actionMedia() { $id = tools::val('id'); if (!$id || !is_numeric($id)) { throw new CHttpException(404, 'The requested page does not exist.'); } $userInfo = Users::getUserInfo($id); if (!$userInfo || $userInfo['status'] != Posts::STATUS_PASSED) { throw new CHttpException(404, '您所查看的页面不存在或已删除'); } $criteria = new CDbCriteria(); $criteria->order = 'hits DESC'; // $criteria->select='id,truename,`desc`,avatar,posts,hits'; $criteria->condition = "uid='{$id}' AND status=" . Posts::STATUS_PASSED; $count = Naodong::model()->count($criteria); $pager = new CPagination($count); $pager->pageSize = $this->pageSize; $pager->applyLimit($criteria); $posts = Naodong::model()->findAll($criteria); $posts = self::foreachNaodong($posts); Posts::updateCount($id, 'Users'); $this->pageTitle = $userInfo['truename'] . ' - ' . zmf::config('sitename'); $this->mobileTitle = $userInfo['truename']; $this->pageDescription = $userInfo['desc'] != '' ? $userInfo['desc'] : zmf::config('siteDesc'); $this->render('media', array('pages' => $pager, 'posts' => $posts, 'userInfo' => $userInfo)); }
/** * 合并用户关注的地区 */ public function actionMergecookie() { $type = tools::val('type', 't', 1); if (!in_array($type, array('add', 'del'))) { $this->jsonOutPut(0, '不允许的类型'); } $uid = zmf::uid(); switch ($type) { case 'add': $this->checkLogin(); $cache = zmf::getCookie('myLikeAreas'); if ($cache) { //取出只存在于cookie的地区id $items = AreaLikes::model()->findAll(array('select' => 'logid', 'condition' => "uid={$uid} AND logid NOT IN({$cache})")); $ids = array_keys(CHtml::listData($items, 'logid', '')); if (!empty($ids)) { $extraInfo = Users::getExtra($this->userInfo); if ($extraInfo['likeAreas']) { $arr = explode(',', $extraInfo['likeAreas']); } foreach ($ids as $id) { $attr = array('uid' => $uid, 'logid' => $id); $model = new AreaLikes(); $model->attributes = $attr; if ($model->save()) { $arr[] = $id; } } $arr = array_unique(array_filter($arr)); $extraInfo['likeAreas'] = join(',', $arr); Users::updateExtra($uid, $extraInfo); } } zmf::delCookie('myLikeAreas'); $this->jsonOutPut(1, '合并成功'); break; case 'del': zmf::delCookie('myLikeAreas'); $this->jsonOutPut(1, '删除成功'); break; } }