Authored by uedxwg

Merge branch 'feature/wap4.3' of http://git.dev.yoho.cn/web/yohobuy into feature/wap4.3

... ... @@ -17,6 +17,7 @@ use Yaf\Dispatcher;
use Plugin\Cache;
use Plugin\Helpers;
use Hood\Session;
use LibModels\Wap\Passport\LoginData;
class AbstractAction extends Controller_Abstract
{
... ... @@ -317,6 +318,22 @@ class AbstractAction extends Controller_Abstract
}
}
/**
* 登录完成后置cookie-_UID,session
*/
protected function syncUserSession($uid)
{
$userInfo = LoginData::profile($uid);
$token = Helpers::makeToken($uid);
if (isset($userInfo['data']) && $userInfo['data']) {
$uidCookie = $userInfo['data']['profile_name'] . '::' . $userInfo['data']['uid'] . '::' . $userInfo['data']['vip_info']['title'] . '::' . $token;
$this->setCookie('_UID', $uidCookie);
}
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $uid);
$this->setCookie('_TOKEN', $token);
}
/**
* 获取当前登录的用户ID
*
... ...
... ... @@ -2,6 +2,7 @@
namespace LibModels\Wap\Cuxiao;
use Api\Sign;
use Api\Yohobuy;
/**
... ... @@ -127,4 +128,22 @@ class ActivityData
));
}
/**
* 发放优惠券
*
* @param int $uid 用户ID
* @param string $token 发券标记
* @return mixed
*/
public static function couponSend($uid, $token)
{
$param = Yohobuy::param();
$param['method'] = 'app.coupons.couponSend';
$param['uid'] = $uid;
$param['coupon_send_token'] = $token;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -803,70 +803,6 @@ class Helpers
}
/**
* 同步用户的会话
*
* 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION
*
* @param int $uid 用户ID
* @param string $refer 访问来源
* @param string $callback 回调方法名
* @return string
*/
public static function syncUserSession($uid, $refer = '', $callback = 'call')
{
$url = '';
switch (APPLICATION_ENV) {
case 'production':
$url = 'https://login.m.yohobuy.com'; //$url = 'http://mapi.yohobuy.com';
break;
case 'preview':
$url = 'https://login.m.yohobuy.com';
break;
case 'testing':
$url = 'http://m1.yohobuy.com';
break;
default:
$url = 'http://m1.yohobuy.com';
break;
}
$url .= '/Passport/session/index?callback=' . $callback . '&sign=' . md5(md5($uid . 'Js8Yn0!EwPM45-ws')) . '&uid=' . $uid . '&go=' . $refer;
return $url;
}
/**
* 退出清除用户的会话
*
* 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION
*
* @param int $token 用户ID
* @param string $refer 访问来源
* @param string $callback 回调方法名
* @return string
*/
public static function logoutSession($token, $refer = '', $callback = 'call')
{
$url = '';
switch (APPLICATION_ENV) {
case 'production':
$url = 'http://mapi.yohobuy.com';
break;
case 'preview':
$url = 'http://mapi.yohobuy.com';
break;
case 'testing':
$url = 'http://m1.yohobuy.com';
break;
default:
$url = 'http://m1.yohobuy.com';
break;
}
$url .= '/Passport/session/logout?callback=' . $callback . '&sign=' . md5(md5('Js8Yn0!EwPM45-ws')) . '&token=' . $token . '&go=' . $refer;
return $url;
}
/**
* 根据skc获取商品链接
* @param unknown $productSkc
* @return string
... ...
... ... @@ -98,14 +98,14 @@ function getCouponHandle(allCoupons) {
// 空数组表示没有优惠券
if ($.isArray(allCoupons)) {
$('.coupin-wrap').html($('#tmpl-no-coupon').html());
$('.coupon-wrap').html($('#tmpl-no-coupon').html());
fixedLayOut();
return;
}
// 把可用和不可用的优惠券分离出来
notAvailableCoupons = allCoupons['notAvailableCoupons'];
coupons = allCoupons['coupons'];
notAvailableCoupons = allCoupons.notAvailableCoupons;
coupons = allCoupons.coupons;
// 渲染可用的优惠券
$couponList.append(conponTmpl({
... ...
... ... @@ -162,7 +162,7 @@ function reMarginFooter(fixedElement) {
$op.prepend(
'<span>Hi,</span>' +
'<a class="user-name" href="http://m.yohobuy.com/home?tmp=' + Math.random() + '">' + user[0] + '</a>' +
'<a href="http://m.yohobuy.com/passport/signout/index?token=' + user[3] + '">退出</a>'
'<a href="http://m.yohobuy.com/passport/signout/index">退出</a>'
);
}
... ...
... ... @@ -216,7 +216,9 @@ $(document).on('touchstart', '.like-ico', function() {
});
// 增加亲密度请求
$('.add-intimacy').on('click', function() {
$('.add-intimacy').on('touchstart', function() {
event.stopPropagation();
$.ajax({
type: 'GET',
url: '/guang/starclass/sign',
... ...
... ... @@ -10,11 +10,31 @@ var $ = require('jquery'),
var bannerSwiper;
// 获取url中的参数
function getUrlParam(name) {
// 构造一个含有目标参数的正则表达式对象
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
// 匹配目标参数
var r = window.location.search.substr(1).match(reg);
// 返回参数值
if (r != null) {
return r[2];
}
return null;
}
$receive.on('click', function() {
var $curDom = $(this);
$.ajax({
url: '/coupon/receiveCoupon',
data: {
couponID: $curDom.parents('.coupon-floor').attr('coupon-id')
},
dataType: 'json',
success: function(data) {
var msg = data.msg,
... ... @@ -40,12 +60,7 @@ $receive.on('click', function() {
}
});
});
//获取url中的参数
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return unescape(r[2]); return null; //返回参数值
}
$('.coupon-floor a').on('click', function() {
if ($(this).attr('href').length <= 0) {
return false;
... ...
... ... @@ -85,6 +85,9 @@
<a href="{{#if isLimit}}javascript:void(0);{{else}}/cart/index/selectCoupon{{/if}}">
<span class="title">优惠券</span>
{{# coupon}}
<span class="coupon-count">
{{count}}张可用
</span>
{{#if couponName}}
<span class="used coupon-use" data-name="{{couponName}}">
{{couponName}}
... ... @@ -168,4 +171,4 @@
</div>
{{/ orderEnsure}}
</div>
{{> layout/footer}}
\ No newline at end of file
{{> layout/footer}}
... ...
... ... @@ -4,7 +4,7 @@
<input type="text" name="couponCode" value="" placeholder="输入优惠券码">
<button type="submit" class="submit">确定</button>
</form>
<div class="coupin-wrap">
<div class="coupon-wrap">
<div id="coupon-list" class="coupon-list"></div>
<div class="not-avaliable-coupon-line hide">不可使用的优惠券</div>
<div id="coupon-list-not" class="coupon-list"></div>
... ...
{{>layout/header}}
<div class="coupon-area">
{{# content}}
{{#if isSingleImage}}
<a href="{{url}}"><img src="{{src}}" class="just-img" /></a>
{{/if}}
{{#if isCarouselBanner}}
{{> home/banner_top}}
{{/if}}
{{#if isCoupon}}
<div class="coupon-floor">
{{#if showFloorTitle}}
<div class="floor-title">
{{floorTitle}}
</div>
{{/if}}
<div class="floor-main" style="background-image: url({{image.src}});">
<a href="{{image.url}}" class="main-left"></a>
{{#if isGet}}
<div class="main-right-receive">
<span class="on-receive"></span>
</div>
<a href="{{image.url}}" class="main-right-use" style="display: none">
<span class="received"></span>
</a>
{{# content}}
{{#if isSingleImage}}
<a href="{{url}}"><img src="{{src}}" class="just-img" /></a>
{{/if}}
{{#if isGeted}}
<a href="{{image.url}}" class="main-right-use">
<span class="received"></span>
</a>
{{#if isCarouselBanner}}
{{> home/banner_top}}
{{/if}}
{{#if isZero}}
<a href="{{image.url}}" class="main-right-go">
<span class="zero"></span>
</a>
{{#if isCoupon}}
<div class="coupon-floor" coupon-id="{{couponID}}">
{{#if showFloorTitle}}
<div class="floor-title">
{{floorTitle}}
</div>
{{/if}}
<div class="floor-main" style="background-image: url({{image.src}});">
<a href="{{image.url}}" class="main-left"></a>
{{#if isGet}}
<div class="main-right-receive">
<span class="on-receive"></span>
</div>
<a href="{{image.url}}" class="main-right-use" style="display: none">
<span class="received"></span>
</a>
{{/if}}
{{#if isGeted}}
<a href="{{image.url}}" class="main-right-use">
<span class="received"></span>
</a>
{{/if}}
{{#if isZero}}
<a href="{{image.url}}" class="main-right-go">
<span class="zero"></span>
</a>
{{/if}}
</div>
</div>
{{/if}}
</div>
</div>
{{/if}}
{{/ content}}
{{/ content}}
</div>
<div class="floor-mask"></div>
<div class="floor-message">
... ...
... ... @@ -2,4 +2,4 @@
{{#each headTab}}
<li {{#if cur}} class="cur" {{/if}}><a href="{{ url }}">{{ name }}</a></li>
{{/each}}
</ul>
</ul>
\ No newline at end of file
... ...
... ... @@ -7,6 +7,7 @@
* Time: 16:31
*/
use Action\AbstractAction;
use Coupon\CouponModel;
use LibModels\Wap\Coupon\CouponData;
use Plugin\DataProcess\CouponFloorProcess;
use Plugin\Helpers;
... ... @@ -93,4 +94,19 @@ class CouponController extends AbstractAction
return (null !== $this->get('app_version'));
}
}
\ No newline at end of file
/**
* 获取优惠券
*/
public function couponSendAction()
{
$callback = $this->get('callback');
$token = $this->get('token', '');
$uid = $this->getUid(true);
$app = $this->get('app', array());
$result = CouponModel::couponSend($uid, $token, $app);
$this->helpJsonCallbackResult($callback, $result['code'], $result['message'], $result['data']);
}
}
... ...
<?php
namespace Coupon;
use Api\Sign;
use Api\Yohobuy;
use LibModels\Wap\Cuxiao\ActivityData;
use Plugin\Helpers;
/**
* 发券相关的数据处理模型
*
* @name CouponModel
* @package Models/Coupon
* @copyright yoho.inc
* @version 1.0 (2016-04-19 13:52:44)
* @author Gtskk<2330416537@qq.com>
*/
class CouponModel
{
/**
* 发放优惠券返回的接口数据处理
*
* @param int $uid 用户ID
* @param string $token 发券标记
* @param array $app url中传递的app有关的参数
* @return mixed
*/
public static function couponSend($uid, $token, $app)
{
$result = array('code' => 403, 'message' => '参数错误', 'data' => '');
do {
// APP时用参数中的ID
if (self::checkApp($app)) {
$uid = isset($app['uid']) ? $app['uid'] : 0;
}
// 用户ID或者发券标记为空时
if (empty($uid) || empty($token)) {
break;
}
$couponResult = ActivityData::couponSend($uid, $token);
// 接口返回错误时
if (empty($couponResult)) {
$result['code'] = 404;
$result['message'] = '出错啦~';
break;
}
$result = $couponResult;
} while (false);
return $result;
}
/**
* 校验是否为app
*
* @param array $app url中传递的app有关的参数
* @return bool
*/
private static function checkApp($app)
{
$isApp = false;
// APP时用参数中的ID
if (!empty($app) && isset($app['client_secret'])) {
$params = $app;
unset($params['client_secret']);
$params['private_key'] = Yohobuy::$privateKeyList[$params['client_type']];
$isApp = ($app['client_secret'] === Sign::getSign($params));
}
return $isApp;
}
}
... ...
... ... @@ -31,11 +31,11 @@ class StarClassModel
* @param $uid
* @return array
*/
public static function getStarClass($uid, $appVersion)
public static function getStarClass($uid)
{
$result = array();
//头部导航
$result['headTab'] = self::getHeadTab('index', $appVersion);
$result['headTab'] = self::getHeadTab('index');
//组装调资源位URL(获取星潮教室首页数据)
$res['starClassIndex'] = StarClassData::getResourceDataUrl(self::CODE_FLOOR_STARCLASS_INDEX);
... ... @@ -82,7 +82,7 @@ class StarClassModel
'week' => array(
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fn', 'Sat'
),
'homeSign' => true
'homeSign' => true,
)
);
}
... ... @@ -100,11 +100,11 @@ class StarClassModel
* 星专题
* @return array
*/
public static function getspecial($appVersion)
public static function getspecial()
{
$result = array();
//头部导航
$result['headTab'] = self::getHeadTab('special', $appVersion);
$result['headTab'] = self::getHeadTab('special');
//组装资源位获取星潮教室首页数据URL
$data = StarClassData::getResourceData(self::CODE_FLOOR_STARCLASS_SPECIAL);
... ... @@ -139,11 +139,11 @@ class StarClassModel
/**
* 星搭配页面
*/
public static function getCollocation($appVersion)
public static function getCollocation()
{
$result = array();
//头部导航
$result['headTab'] = self::getHeadTab('collocation', $appVersion);
$result['headTab'] = self::getHeadTab('collocation');
return $result;
}
... ... @@ -235,6 +235,7 @@ class StarClassModel
$result['signDay'] .= !empty($value['createTime']) ? date('d', $value['createTime']) . ',' : '';
$result['todayIntimacy'] = $value['addNum'];
}
$result['topUrl'] = Helpers::url('/guang/starclass/top');
$result['intimacyNum'] = isset($data['data']['addNum']) ? $data['data']['addNum'] : '0';
foreach ($data['data']['rankList'] as $key => $value) {
//排名数据按数组顺序排列
... ... @@ -257,20 +258,20 @@ class StarClassModel
/**
* 获取headTab
*/
public static function getHeadTab($tab, $appVersion)
public static function getHeadTab($tab)
{
$result = array(
array(
'name' => '全部',
'url' => Helpers::url('/guang/starclass/index', $appVersion),
'url' => Helpers::url('/guang/starclass/index'),
),
array(
'name' => '星专题',
'url' => Helpers::url('/guang/starclass/special', $appVersion)
'url' => Helpers::url('/guang/starclass/special')
),
array(
'name' => '星搭配',
'url' => Helpers::url('/guang/starclass/collocation', $appVersion)
'url' => Helpers::url('/guang/starclass/collocation')
),
// array(
// 'name' => '星鲜事',
... ...
... ... @@ -546,7 +546,10 @@ class CartModel
isset($orderInfo['msg']) && $result['msg'] = $orderInfo['msg'];
// 优惠券数据
$coupons = array('couponName' => '');
$coupons = array(
'couponName' => '',
'count' => self::getValidCouponCount($uid)
);
if (isset($orderCompute['coupon_amount']) && (!empty($orderCompute['coupon_amount']) || ($orderCompute['coupon_amount'] === 0 && $orderCompute['shipping_cost'] === 0))) {
$coupons['couponName'] = $orderInfo['couponName'];
}
... ... @@ -558,6 +561,24 @@ class CartModel
}
/**
* 购物车结算--获取可用的优惠券数目
*
* @param int $uid 用户ID
* @return int 可用优惠券的数目
*/
private static function getValidCouponCount($uid)
{
$count = 0;
$validCount = CartData::getValidCouponCount($uid);
if (isset($validCount['data']['count'])) {
$count = intval($validCount['data']['count']);
}
return $count;
}
/**
* 购物车结算--支付方式和配送方式选择以及是否使用YOHO币接口返回的数据处理
*
* @param int $uid 用户ID
... ... @@ -630,15 +651,9 @@ class CartModel
}
// 不可用的优惠券
$notValidCoupons = self::procCouponsData($coupons['data']['unusable_coupons']);
if (!empty($notValidCoupons)) {
$result['notAvailableCoupons'] = $notValidCoupons;
}
$result['notAvailableCoupons'] = self::procCouponsData($coupons['data']['unusable_coupons']);
// 可用优惠券
$validCoupons = self::procCouponsData($coupons['data']['usable_coupons']);
if (!empty($validCoupons)) {
$result['coupons'] = $validCoupons;
}
$result['coupons'] = self::procCouponsData($coupons['data']['usable_coupons']);
} while (false);
return $result;
... ...
... ... @@ -11,8 +11,8 @@ use Plugin\Helpers;
*/
class StarClassController extends AbstractAction
{
//定义是否APP变量
protected $_isApp = false;
private $_isApp = false;
/**
* 星潮教室首页
... ... @@ -21,16 +21,30 @@ class StarClassController extends AbstractAction
{
//获取uid
$uid = $this->getLoggedUid();
$appVersion = array();
if (!$this->_isApp) {
//设置头部公共导航
$this->setNavHeader('星潮教室', true, false);
if ($uid) {
$this->setCookie('uid', $uid);
}else{
$this->setCookie('uid', '', time() - 3600);
}
}else{
$appVersion = array('app_version'=>1);
$this->setCookie('isApp',true);
if ($uid) {
$this->setCookie('uid', $uid);
}else{
$this->setCookie('uid', '', time() - 3600);
}
}
//设置头部公共导航
$isApp = $this->getCookie('isApp', false);
if (!$isApp) {
$this->setNavHeader('星潮教室', true, false);
}
$this->setTitle('星潮教室');
//调用模型获得星潮教室首页数据
$data = StarClassModel::getStarClass($uid, $appVersion);
$data = StarClassModel::getStarClass($uid);
//渲染模板
$this->_view->display('index', array(
'trendClassHome' => $data,
... ... @@ -46,18 +60,16 @@ class StarClassController extends AbstractAction
public function specialAction()
{
//获取uid
$uid = $this->getLoggedUid();
$appVersion = array();
if (!$this->_isApp) {
$isApp = $this->getCookie('isApp', false);
if (!$isApp) {
//设置头部公共导航
$this->setNavHeader('星潮教室', true, false);
}else{
$appVersion = array('app_version'=>1);
}
$this->setTitle('星潮教室');
//调用模型获得星专题数据
$data = StarClassModel::getspecial($appVersion);
$data = StarClassModel::getspecial();
//渲染模板
$this->_view->display('subject', array(
... ... @@ -73,18 +85,16 @@ class StarClassController extends AbstractAction
public function collocationAction()
{
//获取uid
$uid = $this->getLoggedUid();
$appVersion = array();
if (!$this->_isApp) {
$isApp = $this->getCookie('isApp', false);
if (!$isApp) {
//设置头部公共导航
$this->setNavHeader('星潮教室', true, false);
}else{
$appVersion = array('app_version'=>1);
}
$this->setTitle('星潮教室');
//调用模板获得星搭配数据
$data = StarClassModel::getCollocation($appVersion);
$data = StarClassModel::getCollocation();
//渲染模板
$this->_view->display('collocation', array(
... ... @@ -104,8 +114,8 @@ class StarClassController extends AbstractAction
}
//获得必要参数
$page = $this->get('page',1);
$uid = $this->getLoggedUid();
$isApp = $this->_isApp;
$isApp = $this->getCookie('isApp', false);
$uid = $this->getCookie('uid', false);
//调取模型获得星搭配文章
$data = StarClassModel::ajaxCollocation($page, $uid, $isApp, $limit = 20);
... ... @@ -125,23 +135,20 @@ class StarClassController extends AbstractAction
public function topAction()
{
//获取uid
$uid = $this->getLoggedUid();
$appVersion = array();
//设置头部公共导航(此处返回键调转星潮教室首页)
if (!$this->_isApp) {
$isApp = $this->getCookie('isApp', false);
$uid = $this->getCookie('uid', false);
if (!$isApp) {
//设置头部公共导航(此处返回键调转星潮教室首页)
$url = Helpers::url('/guang/starclass/index');
//设置头部公共导航
$this->setNavHeader('星潮粉丝榜', $url, false);
}else{
$appVersion = array('app_version'=>1);
$url = Helpers::url('/guang/starclass/index', $appVersion);
}
$this->setTitle('星潮粉丝榜');
//根据客户端类型,进行未登录跳转
if (!$uid) {
$refer = Helpers::url('/guang/starclass/top');
if (!$this->_isApp) {
if (!$isApp) {
$this->go(Helpers::url('/signin.html', array('refer' => $refer)));
} else {
$referEncode = strtr($refer, array('/' => '\\/'));
... ... @@ -171,10 +178,12 @@ class StarClassController extends AbstractAction
}
//根据客户端类型,进行未登录跳转
$uid = $this->getLoggedUid();
$isApp = $this->getCookie('isApp', false);
$uid = $this->getCookie('uid', false);
if (!$uid) {
$refer = Helpers::url('/guang/starclass/index');
if (!$this->_isApp) {
if (!$isApp) {
$this->echoJson(array('code'=>201,'data'=>Helpers::url('/signin.html', array('refer' => $refer))));
} else {
$referEncode = strtr($refer, array('/' => '\\/'));
... ... @@ -189,24 +198,6 @@ class StarClassController extends AbstractAction
$this->echoJson($res);
}
/**
* 星鲜事-点赞
*/
public function setPraiseAction()
{
if(!$this->isAjax()){
return;
}
//获得客户端ID(点赞不需要登录)
$udid = $this->getUdid();
//获得文章ID
$articleId = $this->post('articleId');
//调取接口点赞
$result = StarClassData::setPraise($articleId, $udid);
$this->echoJson($result);
}
/**
* 星搭配-文章分享
... ... @@ -219,10 +210,11 @@ class StarClassController extends AbstractAction
$result = array();
//根据客户端类型,进行未登录跳转
$uid = $this->getLoggedUid();
$isApp = $this->getCookie('isApp', false);
$uid = $this->getCookie('uid', false);
if (!$uid) {
$refer = Helpers::url('/guang/starclass/collocation');
if (!$this->_isApp) {
if (!$isApp) {
$this->echoJson(array('code'=>201,'data'=>Helpers::url('/signin.html', array('refer' => $refer))));
} else {
$referEncode = strtr($refer, array('/' => '\\/'));
... ... @@ -247,10 +239,11 @@ class StarClassController extends AbstractAction
}
//根据客户端类型,进行未登录跳转
$uid = $this->getLoggedUid();
$uid = $this->getCookie('uid', false);
$isApp = $this->getCookie('isApp', false);
if (!$uid) {
$refer = Helpers::url('/guang/starclass/collocation');;
if (!$this->_isApp) {
if (!$isApp) {
$this->echoJson(array('code'=>201,'data'=>Helpers::url('/signin.html', array('refer' => $refer))));
} else {
$referEncode = strtr($refer, array('/' => '\\/'));
... ... @@ -277,6 +270,25 @@ class StarClassController extends AbstractAction
}
/**
* 星鲜事-点赞
*/
public function setPraiseAction()
{
if(!$this->isAjax()){
return;
}
//获得客户端ID(点赞不需要登录)
$udid = $this->getUdid();
//获得文章ID
$articleId = $this->post('articleId');
//调取接口点赞
$result = StarClassData::setPraise($articleId, $udid);
$this->echoJson($result);
}
/**
* 检测登录状态
*
* @return int
... ... @@ -289,7 +301,7 @@ class StarClassController extends AbstractAction
if ($this->_isApp) {
$uid = $this->get('uid');
} else {
$uid = $this->getUid();
$uid = $this->getUid(true);
}
return $uid;
... ...
... ... @@ -254,11 +254,7 @@ class BindController extends AbstractAction
$refer = empty($refer) ? rawurldecode(Helpers::url('', array(), 'default')) : rawurldecode($refer);
if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid'])) {
$token = Helpers::makeToken($res['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $res['data']['uid']);
$this->setCookie('_TOKEN', $token);
$refer = Helpers::syncUserSession($res['data']['uid'], $refer);
$this->syncUserSession($res['data']['uid']);
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
}
else {
... ... @@ -305,13 +301,9 @@ class BindController extends AbstractAction
}
if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid'])) {
$token = Helpers::makeToken($res['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $res['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->syncUserSession($res['data']['uid']);
$successUrl = Helpers::url('/passport/bind/success', array('sourceType' => $sourceType));
$refer = Helpers::syncUserSession($res['data']['uid'], $successUrl);
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $successUrl));
}
else {
$data = array('code' => $res['code'], 'message' => $res['message'], 'data' => '');
... ...
... ... @@ -17,9 +17,9 @@ class LoginController extends AbstractAction
*/
public function indexAction()
{
// 设置登录有效时间30分钟, 防机器刷
$this->setSession('_LOGIN_EXPIRE', time() + 1800);
// 设置登录有效时间30分钟, 防机器刷,cache不稳定,改为cookie
$this->setCookie('LE' . md5('_LOGIN_EXPIRE'), time() + 1800);
// $this->setSession('_LOGIN_EXPIRE', time() + 1800);
// 清除客户端
$this->setCookie('_UID', '');
$this->setCookie('_TOKEN', '');
... ... @@ -54,8 +54,9 @@ class LoginController extends AbstractAction
*/
public function internationalAction()
{
// 设置登录有效时间30分钟, 防机器刷
$this->setSession('_LOGIN_EXPIRE', time() + 1800);
// 设置登录有效时间30分钟, 防机器刷,cache不稳定,改为cookie
$this->setCookie('LE' . md5('_LOGIN_EXPIRE'), time() + 1800);
// $this->setSession('_LOGIN_EXPIRE', time() + 1800);
$refer = $this->get('refer');
if (!empty($refer)) {
... ... @@ -83,18 +84,13 @@ class LoginController extends AbstractAction
// 清除服务端会话
$this->setSession('_TOKEN', '');
$this->setSession('_LOGIN_UID', '');
// 清除客户端
$this->setCookie('_UID', '');
$this->setCookie('_TOKEN', '');
$this->setCookie('_SPK', '');
$refer = $this->server('HTTP_REFERER', SITE_MAIN);
$token = $this->get('token');
if (!empty($token)) {
$this->go(Helpers::logoutSession($token, $refer));
}
$this->go($refer);
}
... ... @@ -132,8 +128,10 @@ class LoginController extends AbstractAction
}
/* 设置登录有效时间30分钟, 防机器刷 */
$expire = $this->getSession('_LOGIN_EXPIRE');
$expire = $this->getCookie('LE' . md5('_LOGIN_EXPIRE'));
// $expire = $this->getSession('_LOGIN_EXPIRE');
if (empty($expire) || $expire < time()) {
$data = array('code' => 400, 'message' => '页面停留时间过长,请刷新页面', 'data' => '');
break;
}
... ... @@ -148,17 +146,15 @@ class LoginController extends AbstractAction
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN . '/?go=1';
} else {
}
else {
$refer = rawurldecode($refer);
}
$data['data']['session'] = Helpers::syncUserSession($data['data']['uid']);
$this->syncUserSession($data['data']['uid']);
$data['data']['session'] = $refer;
$data['data']['href'] = $refer;
$token = Helpers::makeToken($data['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $data['data']['uid']);
} while (false);
}
while (false);
$this->echoJson($data);
}
... ... @@ -214,25 +210,21 @@ class LoginController extends AbstractAction
//判定是否需要绑定手机号
if (isset($result['data']['is_bind']) && $result['data']['is_bind'] == 'N') {
$this->go(Helpers::url('/passport/bind/index', array('openId' => $userId, 'sourceType' => 'alipay')));//'nickname' => $realName
$this->go(Helpers::url('/passport/bind/index', array('openId' => $userId, 'sourceType' => 'alipay'))); //'nickname' => $realName
}
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN . '/?go=1';
} else {
}
else {
$refer = rawurldecode($refer);
}
if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $result['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
} else {
$this->go($refer);
$this->syncUserSession($result['data']['uid']);
}
$this->go($refer);
}
/**
... ... @@ -252,25 +244,21 @@ class LoginController extends AbstractAction
//判定是否需要绑定手机号
if (isset($result['data']['is_bind']) && $result['data']['is_bind'] == 'N') {
$this->go(Helpers::url('/passport/bind/index', array('openId' => $access['openid'], 'sourceType' => 'qq')));//'nickname' => $partnerInfo['nickname']
$this->go(Helpers::url('/passport/bind/index', array('openId' => $access['openid'], 'sourceType' => 'qq'))); //'nickname' => $partnerInfo['nickname']
}
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN . '/?go=1';
} else {
}
else {
$refer = rawurldecode($refer);
}
if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $result['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
} else {
$this->go($refer);
$this->syncUserSession($result['data']['uid']);
}
$this->go($refer);
}
/**
... ... @@ -290,25 +278,45 @@ class LoginController extends AbstractAction
}
//判定是否需要绑定手机号
if (isset($result['data']['is_bind']) && $result['data']['is_bind'] == 'N') {
$this->go(Helpers::url('/passport/bind/index', array('openId' => $access['uid'], 'sourceType' => 'sina')));//'nickname' => $partnerInfo['screen_name']
$this->go(Helpers::url('/passport/bind/index', array('openId' => $access['uid'], 'sourceType' => 'sina'))); //'nickname' => $partnerInfo['screen_name']
}
$refer = $this->getCookie('refer');
if (empty($refer)) {
$refer = SITE_MAIN . '/?go=1';
} else {
}
else {
$refer = rawurldecode($refer);
}
if (isset($result['code']) && $result['code'] == 200 && !empty($result['data']['uid'])) {
$token = Helpers::makeToken($result['data']['uid']);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $result['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
} else {
$this->go($refer);
$this->syncUserSession($result['data']['uid']);
}
$this->go($refer);
}
/**
* jsonp获取用户uid
*/
public function userAction()
{
$result = array('code' => 403, 'message' => '未登录', 'data' => '');
do {
$callback = $this->get('callback');
$uid = $this->getUid(true);
if (!empty($uid)) {
$result = array(
'code' => 200,
'message' => '已登录',
'data' => $uid
);
}
}
while (false);
$this->helpJsonCallbackResult($callback, $result['code'], $result['message'], $result['data']);
}
}
... ...
... ... @@ -294,13 +294,9 @@ class RegController extends AbstractAction
} else {
$refer = rawurldecode($refer);
}
$data['data']['session'] = Helpers::syncUserSession($data['data']['uid']);
$this->syncUserSession($data['data']['uid']);
$data['data']['session'] = $refer;
$data['data']['href'] = $refer;
$token = Helpers::makeToken($data['data']['uid']);
$this->setCookie('_TOKEN', $token);
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $data['data']['uid']);
} while (false);
$this->echoJson($data);
... ...