Exemplo n.º 1
0
Arquivo: Q.php Projeto: ph7pal/mei
 function _referer()
 {
     $currentUrl = Yii::app()->request->url;
     $arr = array('/site/', '/error/', '/attachments/');
     $set = true;
     if (Common::checkImg($currentUrl)) {
         $set = false;
     }
     if ($set) {
         foreach ($arr as $val) {
             if (!$set) {
                 break;
             }
             if (strpos($currentUrl, $val) !== false) {
                 $set = false;
                 break;
             }
         }
     }
     if ($set && Yii::app()->request->isAjaxRequest) {
         $set = false;
     }
     $referer = zmf::getCookie('refererUrl');
     if ($set) {
         zmf::setCookie('refererUrl', $currentUrl, 86400);
     }
     if ($referer != '') {
         $this->referer = $referer;
     }
 }
Exemplo n.º 2
0
 public function beforeSave()
 {
     $ip = Yii::app()->request->userHostAddress;
     $key = 'ipInfo-' . $ip;
     $ipData = zmf::getCookie($key);
     if (!$ipData) {
         $url = 'http://apis.baidu.com/apistore/iplookupservice/iplookup?ip=' . $ip;
         // 执行HTTP请求
         $header = array('apikey:e5882e7ac4b03c5d6f332b6de4469e81');
         $ch = curl_init();
         // 添加apikey到header
         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_URL, $url);
         $res = curl_exec($ch);
         $res = CJSON::decode($res, true);
         $retData = array();
         if ($res['errNum'] == 0) {
             $retData = $res['retData'];
         }
         $ipData = json_encode($retData);
         zmf::setCookie($key, $ipData, 2592000);
     }
     $this->ip = ip2long($ip);
     $this->ipInfo = $ipData;
     return true;
 }
Exemplo n.º 3
0
 public function init()
 {
     parent::init();
     $passwdErrorTimes = zmf::getCookie('checkWithCaptcha');
     $time = zmf::config('adminErrorTimes');
     if ($time > 0) {
         if ($passwdErrorTimes >= $time) {
             header('Content-Type: text/html; charset=utf-8');
             echo '您暂时已被禁止访问';
             Yii::app()->end();
         }
     }
     $uid = zmf::uid();
     if ($uid) {
         //            $randKey_cookie = zmf::getCookie('adminRandKey' . $uid);
         //            $randKey_cache = zmf::getFCache('adminRandKey' . $uid);
         //            if (!$randKey_cookie || ($randKey_cache != $randKey_cookie)) {
         //                Yii::app()->user->logout();
         //                $this->message(0, '登录已过期,请重新登录', Yii::app()->createUrl('admin/site/login'));
         //            }
         $this->userInfo = Users::getOne($uid);
         $this->uid = $uid;
     } else {
         $currentUrl = Yii::app()->request->url;
         if (strpos($currentUrl, '/site/') === false) {
             $this->message(0, '请先登录', Yii::app()->createUrl('/site/login'));
         }
     }
 }
Exemplo n.º 4
0
 public function actions()
 {
     $cookieInfo = zmf::getCookie('checkWithCaptcha');
     if ($cookieInfo == '1') {
         return array('captcha' => array('class' => 'CCaptchaAction', 'backColor' => 0xffffff, 'minLength' => '2', 'maxLength' => '3', 'height' => '30', 'width' => '60'), 'page' => array('class' => 'CViewAction'));
     }
 }
Exemplo n.º 5
0
 public function rules()
 {
     $rules = array(array('email, password', 'required'), array('rememberMe', 'boolean'), array('password', 'authenticate'));
     $cookieInfo = zmf::getCookie('checkWithCaptcha');
     if ($cookieInfo == '1') {
         $rules[] = array('verifyCode', 'captcha', 'allowEmpty' => !CCaptcha::checkRequirements());
     }
     return $rules;
 }
Exemplo n.º 6
0
 /**
  * 返回用户关注的地址
  * @param type $userInfo 用户信息
  * @param type $return 返回方式 a:数组;s:字符串
  * @return type
  */
 public static function getLikes($userInfo, $return = 'a')
 {
     $cache = zmf::getCookie('myLikeAreas');
     if (!$userInfo && !$cache) {
         return array();
     }
     if ($userInfo) {
         $extra = CJSON::decode($userInfo['extra'], true);
         $likes = $extra['likeAreas'];
     } else {
         $likes = $cache;
     }
     if ($return == 'a') {
         return explode(',', $likes);
     } else {
         return join(',', explode(',', $likes));
     }
 }
Exemplo n.º 7
0
 function actionLogin()
 {
     $this->layout = 'common';
     if (!Yii::app()->user->isGuest) {
         $this->message(0, '您已登录,请勿重复操作', Yii::app()->createUrl('admin/index/index'));
     }
     $model = new LoginForm();
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if (isset($_POST['LoginForm'])) {
         $model->attributes = $_POST['LoginForm'];
         if ($model->validate() && $model->login()) {
             $arr = array('latestLoginTime' => zmf::now());
             $uid = Yii::app()->user->id;
             if (!$this->checkPower('user', $uid, true)) {
                 Yii::app()->user->logout();
                 $model->addError('username', '您不是管理员');
             } else {
                 //User::model()->updateByPk($uid, $arr);
                 zmf::delCookie('checkWithCaptcha');
                 //只允许单点登录
                 $randKey = zmf::randMykeys(8);
                 zmf::setCookie('adminRandKey' . $uid, $randKey, 86400);
                 zmf::setFCache('adminRandKey' . $uid, $randKey, 86400);
                 //记录操作
                 //UserLog::add($uid, '登录后台'.Yii::app()->request->userHostAddress);
                 $uuid = zmf::uuid();
                 zmf::setCookie('userCheckedLogin' . $uid, $uuid, 86400);
                 $this->redirect(array('index/index'));
             }
         } else {
             $times = zmf::getCookie('checkWithCaptcha');
             zmf::setCookie('checkWithCaptcha', intval($times) + 1, 86400);
         }
     }
     $data = array('model' => $model);
     $this->render('login', $data);
 }
Exemplo n.º 8
0
    ?>
" value="<?php 
    echo zmf::getCookie('noLoginUsername');
    ?>
">
            </div>
            <p class="help-block">将显示为由谁评论</p>
        </div>
        <div class="col-xs-6 col-sm-6">
            <div class="input-group">
                <span class="input-group-addon">邮箱</span>
                <input type="text" class="form-control" placeholder="Email地址(选填)" id="<?php 
    echo 'email-' . $type . '-' . $keyid;
    ?>
" value="<?php 
    echo zmf::getCookie('noLoginEmail');
    ?>
">
            </div>
            <p class="help-block">Email不会被公布,仅用于接收评论的回复</p>
        </div>
    </div>
</div>
<?php 
}
?>
<div class="form-group toggle-area">
    <p>
        <?php 
echo CHtml::link('评论', 'javascript:;', array('class' => 'btn btn-success pull-right', 'action' => 'add-comment', 'action-data' => $keyid, 'action-type' => $type));
?>
Exemplo n.º 9
0
Arquivo: zmf.php Projeto: ph7pal/mei
 /**
  * 限制用户对某一操作的频率,如点赞,收藏,关注
  * 默认4次
  */
 public static function actionLimit($type, $keyid, $num = 4)
 {
     $cacheKey = 'actionLimit-' . $type . '-' . $keyid;
     $info = (int) zmf::getCookie($cacheKey);
     if ($info >= $num) {
         return true;
     } else {
         zmf::setCookie($cacheKey, $info + 1, 60);
         return false;
     }
 }
Exemplo n.º 10
0
Arquivo: login.php Projeto: ph7pal/mei
echo $form->error($model, 'email');
?>
    </div>
    <div class="form-group">
        <?php 
echo $form->labelEx($model, 'password');
?>
        <?php 
echo $form->passwordField($model, 'password', array('class' => 'form-control', 'placeholder' => '请输入密码'));
?>
 <?php 
echo $form->error($model, 'password');
?>
    </div>
    <?php 
$cookieInfo = zmf::getCookie('checkWithCaptcha');
if ($cookieInfo == '1') {
    ?>
    <div class="form-group">
        <label class="required"><?php 
    echo zmf::t('verifyCode');
    ?>
 <span class="required">*</span></label>
        <?php 
    echo $form->textField($model, 'verifyCode', array('class' => 'form-control verify-code'));
    ?>
        <?php 
    echo $form->error($model, 'verifyCode');
    ?>
        <?php 
    $this->widget('CCaptcha', array('showRefreshButton' => true, 'clickableImage' => true, 'buttonType' => 'link', 'buttonLabel' => zmf::t('change_verify'), 'imageOptions' => array('alt' => zmf::t('change_verify'), 'align' => 'absmiddle')));
Exemplo n.º 11
0
 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));
 }
Exemplo n.º 12
0
 public function actionCallback()
 {
     $cacheToken = zmf::getCookie('weibojs_' . $this->weiboService->client_id);
     //将token存入cookie,方便下次调用
     if (isset($_REQUEST['code']) && !$cacheToken) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = $this->WB_CALLBACK_URL;
         try {
             $token = $this->weiboService->getAccessToken('code', $keys);
             zmf::setCookie('weibojs_' . $this->weiboService->client_id, serialize($token), $this->cookieTime);
         } catch (OAuthException $e) {
             $this->message(0, '获取授权信息出错,请重试');
         }
     } elseif ($cacheToken) {
         $token = unserialize($cacheToken);
     }
     if (!$token || !$token['access_token']) {
         $this->message(0, '获取授权信息出错,请重试');
     }
     //根据ID获取用户等基本信息
     $c = new SaeTClientV2($this->WB_AKEY, $this->WB_SKEY, $token['access_token']);
     $uid_get = $c->get_uid();
     $sinauid = $uid_get['uid'];
     //新浪的用户ID
     $user_message = $c->show_user_by_id($sinauid);
     if (!$user_message) {
         $this->message(0, '获取用户信息出错,请重试');
     }
     //将用户数据存入cookie
     $data['access_token'] = $token['access_token'];
     $data['expires_in'] = zmf::now() + intval($token['expires_in']);
     $data['sinauid'] = $sinauid;
     $data['screen_name'] = $user_message['screen_name'];
     $data['name'] = $user_message['name'];
     $data['profile_url'] = 'http://weibo.com/' . $user_message['profile_url'];
     $data['avatarurl'] = $user_message['avatar_hd'];
     $infoArr = array('screen_name' => $user_message['screen_name'], 'avatarurl' => $user_message['avatarurl'], 'profile_url' => 'http://weibo.com/' . $user_message['profile_url']);
     $data['data'] = serialize($infoArr);
     $strdata = serialize($data);
     zmf::setCookie('userWeiboData', $strdata, $this->cookieTime);
     //获取用户之前的意图,是注册、登录还是绑定
     $action = zmf::getCookie('lastWeiboAction');
     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'));
     }
     $bindInfo = UserSina::model()->find('openid=:sinauid', array(':sinauid' => $data['sinauid']));
     if ($action == 'login') {
         //确实绑定过微博,则直接登录
         if ($bindInfo) {
             $this->loginWithWeibo($bindInfo, $data);
         } else {
             //没有绑定过就跳转到注册页面
             $this->redirect(array('site/reg', 'bind' => 'weibo'));
         }
     } elseif ($action == 'reg') {
         //绑定过微博就直接登录
         if ($bindInfo) {
             $this->loginWithWeibo($bindInfo, $data);
         } else {
             //没有绑定过就跳转到注册页面
             $this->redirect(array('site/reg', 'bind' => 'weibo'));
         }
     } elseif ($action == 'bind') {
         $uid = zmf::uid();
         if ($bindInfo) {
             throw new CHttpException(403, '该微博已经绑定其他账户');
         } else {
             $otherBind = UserSina::model()->findByPk($uid);
             if ($otherBind) {
                 throw new CHttpException(403, '您已经绑定过其他账户');
             }
             $data['uid'] = $uid;
             if (UserSina::addCookie($data)) {
                 //返回设置页面
                 $this->redirect(array('users/config'));
             } else {
                 throw new CHttpException(403, '写入数据时错误,请重试');
             }
         }
     }
 }
Exemplo n.º 13
0
 /**
  * 合并用户关注的地区
  */
 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;
     }
 }