Authored by hf

do add page cache and data cache master slave mode

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>国际账号登录</title>
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta http-equiv="cleartype" content="on">
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta content="telephone=no" name="format-detection" />
<meta content="email=no" name="format-detection" />
<script type="text/javascript">
(function (doc, win) {
var docEl = doc.documentElement;
(function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) {
return;
}
docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
}());
})(document, window);
</script>
<link rel="stylesheet" href="http://172.16.6.248:8088/css/index.css">
</head>
<body class=passport-body>
<div class="login-interational-page passport-page yoho-page">
<div class="header">
<a class="go-back" href=/>
<img src="http://static.dev.yohobuy.com/img/passport/go-back.png">
</a>
<p class="title">登录</p>
</div> <div class="content">
<div class="select-container row">
<span class="select-title">国家和地区</span>
<select id="country-select" class="country-select select in-android-uc">
<option value=+61 >澳大利亚</option>
<option value=+82 >韩国</option>
<option value=+1 >加拿大</option>
<option value=+60 >马来西亚</option>
<option value=+1 >美国</option>
<option value=+81 >日本</option>
<option value=+65 >新加坡</option>
<option value=+44 >英国</option>
<option value=+86 selected>中国</option>
<option value=+853 >中国澳门</option>
<option value=+886 >中国台湾</option>
<option value=+852 >中国香港</option>
</select>
<div class="arrow-right"></div>
</div> <div class="input-container phone-container row has-clear">
<span id="area-code" class="area-code">+86</span>
<input id="phone-num" class="input phone-num" type="text" placeholder="手机号" value=>
</div>
<div class="input-container row has-eye">
<input id="pwd" class="pwd input" type="password" placeholder="密码">
</div>
<span id="btn-login" class="btn btn-login disble row">登录</span>
</div>
</div>
<script src="http://172.16.6.248:8000/static/js/sea.js?nowrap"></script>
<script>
seajs.config({
base: 'http://172.16.6.248:8000'
});
</script>
<script>
seajs.use('js/passport/login/interational');
</script>
<script>
seajs.use('js/homePage/girls');
</script></body>
</html>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>注册</title>
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta http-equiv="cleartype" content="on">
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta content="telephone=no" name="format-detection" />
<meta content="email=no" name="format-detection" />
<script type="text/javascript">
(function (doc, win) {
var docEl = doc.documentElement;
(function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) {
return;
}
docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
}());
})(document, window);
</script>
<link rel="stylesheet" href="http://172.16.6.248:8088/css/index.css">
</head>
<body class=passport-body>
<div class="reg-page passport-page yoho-page">
<div class="header">
<a class="go-back" href=/>
<img src="http://static.dev.yohobuy.com/img/passport/go-back.png">
</a>
<p class="title">注册</p>
</div> <div class="content">
<div class="select-container row">
<span class="select-title">国家和地区</span>
<select id="country-select" class="country-select select in-android-uc">
<option value=+61 >澳大利亚</option>
<option value=+82 >韩国</option>
<option value=+1 >加拿大</option>
<option value=+60 >马来西亚</option>
<option value=+1 >美国</option>
<option value=+81 >日本</option>
<option value=+65 >新加坡</option>
<option value=+44 >英国</option>
<option value=+86 selected>中国</option>
<option value=+853 >中国澳门</option>
<option value=+886 >中国台湾</option>
<option value=+852 >中国香港</option>
</select>
<div class="arrow-right"></div>
</div> <div class="input-container phone-container row has-clear">
<span id="area-code" class="area-code">+86</span>
<input id="phone-num" class="input phone-num" type="text" placeholder="手机号">
</div>
<span id="btn-next" class="btn btn-next disable row">下一步</span>
<p class="register-tip">YOHO!Family账号可登录YOHO!有货、YOHO!Boys、YOHO!Girls及SHOW</p>
</div>
</div>
<script src="http://172.16.6.248:8000/static/js/sea.js?nowrap"></script>
<script>
seajs.config({
base: 'http://172.16.6.248:8000'
});
</script>
<script>
seajs.use('js/passport/register/register');
</script>
<script>
seajs.use('js/homePage/girls');
</script></body>
</html>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta http-equiv="cleartype" content="on">
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta content="telephone=no" name="format-detection" />
<meta content="email=no" name="format-detection" />
<script type="text/javascript">
(function (doc, win) {
var docEl = doc.documentElement;
(function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) {
return;
}
docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
}());
})(document, window);
</script>
<link rel="stylesheet" href="http://172.16.6.248:8088/css/index.css">
</head>
<body class=passport-body>
<div class="login-page passport-page yoho-page">
<div class="header">
<a class="go-back" href=/>
<img src="http://static.dev.yohobuy.com/img/passport/go-back.png">
</a>
<img class="img-header" src="http://static.dev.yohobuy.com/img/passport/yoho-family.png">
</div> <div class="content">
<div class="acc-container input-container row has-clear">
<div class="yoho-logo"></div>
<input id="account" class="input account" type="text" placeholder="手机号/邮箱" autocomplete="off" value=>
</div>
<div class="input-container row has-eye">
<input id="pwd" class="pwd input" type="password" placeholder="密码">
</div>
<span id="btn-login" class="btn btn-login disable">登录</span>
<p class="op-container">
<a class="go-register" href=/reg.html>免费注册</a>
<span id="forget-pwd" class="forget-pwd">忘记密码</span>
</p>
<div class="third-party-login">
<span>其他登录方式</span>
<div class="tp-link">
<a class="alipay" href=></a>
<a class="weibo" href=></a>
<a class="qq" href=></a>
</div>
</div>
<a class="interational" href=/login.html>Interational Customer</a>
<div class="login-tip">
<div class="info-icon"></div>
Yoho!Family账号可登录YOHO!有货
</div>
<div id="retrive-pwd-mask" class="mask"></div>
<ul id="retrive-pwd-ways" class="retrive-pwd-ways">
<li>
<a href=/phoneback.html>通过手机找回密码</a>
</li>
<li>
<a href=/emailback.html>通过邮箱找回密码</a>
</li>
<li id="cancel-retrive">
取消
</li>
</ul>
</div>
</div>
<script src="http://172.16.6.248:8000/static/js/sea.js?nowrap"></script>
<script>
seajs.config({
base: 'http://172.16.6.248:8000'
});
</script>
<script>
seajs.use('js/passport/login/login');
</script>
</body>
</html>
\ No newline at end of file
... ...
framework @ 75bbc3b0
Subproject commit 119c247f5cf929aa1e059e40609bb16dd6b58f05
Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
... ...
... ... @@ -14,8 +14,7 @@ namespace Action;
use Yaf\Controller_Abstract;
use Yaf\Dispatcher;
use Hood\Cache;
use LibModels\Wap\Home\SideData;
use Plugin\Cache;
class AbstractAction extends Controller_Abstract
{
... ... @@ -33,6 +32,20 @@ class AbstractAction extends Controller_Abstract
public function init()
{
$this->_request = $this->getRequest();
// 设置环境变量
switch (APPLICATION_ENV) {
case 'production':
$this->_view->assign('rlsEnv', true);
break;
case 'testing':
$this->_view->assign('testEnv', true);
break;
case 'develop':
default:
$this->_view->assign('devEnv', true);
break;
}
}
/**
... ... @@ -60,25 +73,6 @@ class AbstractAction extends Controller_Abstract
}
/**
* 使用Memcache缓存
*
* @param string $node
* @param string $childNode
* @return object
*/
protected function memcache($node = null, $childNode = 'hosts')
{
// WINDOWS
if (PATH_SEPARATOR === '\\') {
return Cache::memcache($node, $childNode);
}
// LINUX
else {
return Cache::memcached($node, $childNode);
}
}
/**
* 关闭模板自动渲染
*
* @return void
... ... @@ -138,7 +132,7 @@ class AbstractAction extends Controller_Abstract
{
headers_sent() || header('Location: /error.html');
exit;
exit();
}
/**
... ... @@ -152,7 +146,7 @@ class AbstractAction extends Controller_Abstract
*/
protected function setCookie($name, $value, $expire = 0, $path = '/',$domain = 'yohobuy.com')
{
setcookie('alipay_redirect', $value, $expire, $path, $domain);
setcookie($name, $value, $expire, $path, $domain);
}
/**
... ... @@ -166,17 +160,34 @@ class AbstractAction extends Controller_Abstract
{
return $this->request->getCookie($name, $default);
}
/**
* 返回顶部软件下载有关数据
* @return array 下载有关数据
* 设置缓存
*
* @param string $key 键名
* @param mixed $value 需要缓存的数据
* @param int $expire 缓存有效期(单位秒, 0表示永久)
* @return void
*/
protected function getHeaderDownload()
protected function setCache($key, $value, $expire)
{
return array(
'img' => 'http://img11.static.yhbimg.com/adpic/2015/02/28/18/01d83bfad41c8fca8fd1ad334216d7d733.jpg?imageView/2/w/640/h/480',
'url' => 'http://www.baidu.com'
);
Cache::set($key, $value, $expire);
}
/**
* 获取缓存
*
* @param string $key 键名
* @param bool $isMaster 控制是到主服务器取,还是到从服务器取缓存
* @return mixed
*/
protected function getCache($key, $isMaster = true)
{
if ($isMaster) {
return Cache::get($key, 'master');
} else {
return Cache::get($key, 'slave');
}
}
/*
... ... @@ -334,6 +345,19 @@ class AbstractAction extends Controller_Abstract
)
),
));
}
/**
* 返回顶部软件下载有关数据
* @return array 下载有关数据
*/
protected function getHeaderDownload()
{
return array(
'img' => 'http://img11.static.yhbimg.com/adpic/2015/02/28/18/01d83bfad41c8fca8fd1ad334216d7d733.jpg?imageView/2/w/640/h/480',
'url' => 'http://www.baidu.com'
);
}
}
... ...
... ... @@ -20,15 +20,94 @@ class RegData
/**
* 获取地区数据
*
* 备注:
* 考虑到该接口数据很少发生变化,改成静态配置,不调用接口.
* 以后有需要,可以打开注释,改成调用接口.
*
* @return array 地区数据
*/
public static function getAreasData()
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.getArea';
$param['client_secret'] = Sign::getSign($param);
// $param = Yohobuy::param();
// $param['method'] = 'app.passport.getArea';
// $param['client_secret'] = Sign::getSign($param);
// $data = Yohobuy::get(Yohobuy::API_URL, $param);
// $result = array();
// if (!empty($data['data'])) {
// $build = array();
// foreach ($data['data'] as $value) {
// $build = array();
// $build['areaCode'] = '+' . $value['area'];
// $build['selected'] = ($value['area'] === '86');
// $build['name'] = $value['name'];
// $result[] = $build;
// }
// $data = array();
// }
// return $result;
return Yohobuy::get(Yohobuy::API_URL, $param);
return array(
0 => array(
'areaCode' => '+61',
'selected' => false,
'name' => '澳大利亚',
),
1 => array(
'areaCode' => '+82',
'selected' => false,
'name' => '韩国',
),
2 => array(
'areaCode' => '+1',
'selected' => false,
'name' => '加拿大',
),
3 => array(
'areaCode' => '+60',
'selected' => false,
'name' => '马来西亚',
),
4 => array(
'areaCode' => '+1',
'selected' => false,
'name' => '美国',
),
5 => array(
'areaCode' => '+81',
'selected' => false,
'name' => '日本',
),
6 => array(
'areaCode' => '+65',
'selected' => false,
'name' => '新加坡',
),
7 => array(
'areaCode' => '+44',
'selected' => false,
'name' => '英国',
),
8 => array(
'areaCode' => '+86',
'selected' => true,
'name' => '中国',
),
9 => array(
'areaCode' => '+853',
'selected' => false,
'name' => '中国澳门',
),
10 => array(
'areaCode' => '+886',
'selected' => false,
'name' => '中国台湾',
),
11 => array(
'areaCode' => '+852',
'selected' => false,
'name' => '中国香港',
),
);
}
/**
... ... @@ -48,7 +127,7 @@ class RegData
return Yohobuy::post(Yohobuy::API_URL, $param);
}
/**
* 验证手机注册的识别码
*
... ... @@ -68,7 +147,7 @@ class RegData
return Yohobuy::post(Yohobuy::API_URL, $param);
}
/**
* 通过手机注册
*
... ...
<?php
namespace Plugin;
use Hood\Cache as HoodCache;
/**
* 数据缓存的操作类
*
* @name Cache
* @package
* @package Plugin
* @copyright yoho.inc
* @version 1.0 (2015-10-10 11:23:47)
* @author fei.hong <fei.hong@yoho.cn>
*/
class Cache
{
/**
* 设置缓存
*
* 备注:
* 采用主从分布式缓存
* master 代表主缓存服务器
* slave 代表从缓存服务器
*
* 作用:
* 在后端的服务异常挂掉了并且主服务器缓存(master)的数据时间到期后,
* 能获取从服务器缓存(slave)的数据,不影响前端页面的正常访问.
*
* @param string $key 键名
* @param mixed $value 需要缓存的数据
* @param int $expire 缓存有效期(单位秒, 0表示永久)
* @return void
*/
public static function set($key, $value, $expire = 3600)
{
// WINDOWS
if (PATH_SEPARATOR === '\\') {
HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 0);
}
// LINUX
else {
HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 0);
}
}
/**
* 获取缓存
*
* @param string $key 键名
* @param string $node master代表主服务器, slave代表从服务器
* @return mixed
*/
public static function get($key, $node = 'master')
{
$result = array();
// WINDOWS
if (PATH_SEPARATOR === '\\') {
$result = HoodCache::Memcache($node)->get(self::makeKey($key, $node));
}
// LINUX
else {
$result = HoodCache::Memcached($node)->set(self::makeKey($key, $node));
}
return $result;
}
/**
* 清除缓存
*
* @param string $key 键名
* @return void
*/
public static function delete($key)
{
// WINDOWS
if (PATH_SEPARATOR === '\\') {
HoodCache::Memcache('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave'));
}
// LINUX
else {
HoodCache::Memcached('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcached('slave')->delete(self::makeKey($key, 'slave'));
}
}
/**
* 生成键名
*
* @param string $key 键名
* @param string $prefix 前缀标识
* @return string
*/
public static function makeKey($key, $prefix)
{
return md5($prefix . '_' . $key);
}
}
... ...
... ... @@ -9,32 +9,35 @@
* @version 1.0 (2015-9-15 14:14:02)
* @author fei.hong <fei.hong@yoho.cn>
*/
namespace Plugin;
use Yaf\View_Interface;
use Yaf\Dispatcher;
use Yaf\Application;
use Plugin\LightnCandy;
class TemplateLayout implements View_Interface
{
/* 属性 */
/* 模板变量 */
protected $_tpl_vars;
/* 模板目录 */
protected $_tpl_dir;
/* HTML路径 */
protected $_html_path;
/**
* 传递给视图变量
*
* @param mixed $name
* @param mixed $value
* @return void
*/
public function assign($name, $value = null)
{
$this->_tpl_vars[$name] = $value;
}
/**
* 清除一个视图变量
*
... ... @@ -43,14 +46,32 @@ class TemplateLayout implements View_Interface
*/
public function clear($name = null)
{
// 清空指定的变更值
if (isset($this->_tpl_vars[$name])) {
unset($this->_tpl_vars[$name]);
} else {
}
// 清空整个变量值
else {
$this->_tpl_vars = array();
}
}
/**
* 设置生成HTML及存放路径
*
* 如"xxx"则生成"xxx.html"文件, 如"path/xxx"则生成"path/xxx.html"
*
* @param string $htmlPath 生成的Html名字或路径
* @return void
*/
public function html($htmlPath)
{
if (is_string($htmlPath)) {
$this->_html_path = $htmlPath;
}
}
/**
* 渲染视图模板,并直接输出到客户端
*
* @param string $tpl
... ... @@ -70,8 +91,18 @@ class TemplateLayout implements View_Interface
*/
public function render($tpl, $tpl_vars = array())
{
$request = Dispatcher::getInstance()->getRequest();
$config = Application::app()->getConfig()->get('application');
$useHtml = isset($this->_html_path) && isset($config->assets->path);
// 有生成过HTML的,则先尝试获取HTML内容. 有则返回内容,不渲染模板
if ($useHtml) {
$result = $this->getHtml($config->assets->path, $this->_html_path);
if (!empty($result)) {
return $result;
}
}
$request = Dispatcher::getInstance()->getRequest();
$tplExt = $config->template->ext;
$viewPath = $config->template->path;
$viewName = $viewPath . '/' . strtolower($request->module) . '/' . strtolower($request->controller) . '/' . $tpl . $tplExt;
... ... @@ -79,7 +110,7 @@ class TemplateLayout implements View_Interface
if (!file_exists($viewName)) {
return '';
}
// 合并通过assign传递的参数
if (is_array($this->_tpl_vars)) {
$tpl_vars = array_merge($this->_tpl_vars, $tpl_vars);
... ... @@ -93,12 +124,12 @@ class TemplateLayout implements View_Interface
$compilePath = $config->template->compile;
// 模板编译成PHP文件所存放的文件路径
$compilePhp = $compilePath . '/' . $makeKey . '.php';
// 已渲染过该模板,则直接引PHP文件
if (is_readable($compilePhp)) {
LightnCandy::getContext();
$renderer = include($compilePhp);
}
}
// 第一次渲染该模板的流程:取得模板内容 => 预编译成PHP函数 => 写入服务器生成PHP文件
else {
$template = file_get_contents($viewName, false, null);
... ... @@ -114,18 +145,78 @@ class TemplateLayout implements View_Interface
// 将编译过的函数写入PHP文件
file_put_contents($compilePhp, $phpStr);
}
// 装载内容,调用PHP函数
try {
$result = $renderer($tpl_vars);
} catch (Exception $e) {
}
catch (Exception $e) {
$result = '';
}
// 保存成指定名字的html文件
if ($useHtml && !empty($result)) {
$this->toHtml($config->assets->path, $this->_html_path, $result);
}
$config = null;
$request = null;
$tpl_vars = null;
return $result;
}
/**
* 生成HTML
*
* @param string $assetsPath 存放静态页面的目录
* @param string $htmlPath 指定的html文件路径
* @param string $result 需要存的内容
* @return void
*/
public function toHtml($assetsPath, $htmlPath, $result)
{
$htmlName = $assetsPath . '/' . ltrim($htmlPath, '/') . '.html';
// 判断是否存在目录
if (strstr($htmlPath, '/')) {
$this->makedir(dirname($htmlName));
}
// 写入html文件
file_put_contents($htmlName, $result);
}
/**
* 获取HTML
*
* @param string $assetsPath 存放静态页面的目录
* @param string $htmlPath 指定的html文件路径
* @return string
*/
public function getHtml($assetsPath, $htmlPath)
{
$result = '';
$htmlName = $assetsPath . '/' . ltrim($htmlPath, '/') . '.html';
// 判断文件是否已存在, 存在则不重复生成
if (file_exists($htmlName)) {
$result = file_get_contents($htmlName, false, null);
}
return $result;
}
/**
* 递归创建目录
*
* @param string $path 文件路径
* @return boolean (false:失败,true:成功)
*/
protected function makeDir($path)
{
return is_dir($path) || ($this->makeDir(dirname($path)) && @mkdir($path, 0755));
}
/**
* 设置视图模板目录
*
* @param string $path
... ... @@ -134,10 +225,12 @@ class TemplateLayout implements View_Interface
public function setScriptPath($path)
{
$result = false;
if (is_dir($path)) {
$this->_tpl_dir = $path;
$result = true;
}
return $result;
}
... ...
... ... @@ -18,7 +18,7 @@
"dependencies": {
"yoho.zepto": "1.1.60",
"yoho.jquery": "1.8.3",
"yoho.lazyload": "1.1.0",
"yoho.lazyload":"1.1.0",
"mlellipsis": "0.0.6",
"yoho.iswiper": "3.0.1"
},
... ...
... ... @@ -22,8 +22,13 @@ class ErrorController extends AbstractAction
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
// @todo debug
echo $exception->getMessage();
//$this->_view->render('error');
// // 生成HTML (error.html)
// $this->_view->html('error');
// // 渲染模板
// $this->_view->display('error');
}
}
... ...
... ... @@ -11,24 +11,28 @@ use Plugin\Partner\Factory;
*/
class LoginController extends AbstractAction
{
/**
* 登录页
*/
public function indexAction()
{
$this->setTitle('登录');
$data = array(
'loginIndex' => true,
'backUrl' => '/',
'showHeaderImg' => true,
'isPassportPage' => true,
'registerUrl' => '/reg.html',
'interationalUrl' => '/login.html',
'phoneRetriveUrl' => '',
'emailRetriveUrl' => '',
'loginIndex' => true, // 模板中使用JS的标识
'backUrl' => '/', // 返回的URL链接
'showHeaderImg' => true, // 控制显示头部图片
'isPassportPage' => true, // 模板中模块标识
'registerUrl' => '/reg.html', // 注册的URL链接
'interationalUrl' => '/login.html', // 国际号登录的URL链接
'phoneRetriveUrl' => '/phoneback.html', // 通过手机号找回密码的URL链接
'emailRetriveUrl' => '/emailback.html', // 通过邮箱找回密码的URL链接
);
// 生成HTML(signin.html)
$this->_view->html('signin');
// 渲染模板
$this->_view->display('index', $data);
}
... ... @@ -38,41 +42,21 @@ class LoginController extends AbstractAction
public function interationalAction()
{
$this->setTitle('国际账号登录');
$data = array();
$data['loginInterational'] = true;
$data['backUrl'] = '/';
$data['headerText'] = '登录';
$data['isPassportPage'] = true;
$data['areaCode'] = '+86';
// 获取地区数据列表
$area = RegData::getAreasData();
// 有数据
if (!empty($area['data'])) {
$build = array();
foreach ($area['data'] as $value) {
$build = array();
$build['areaCode'] = '+' . $value['area'];
$build['selected'] = $value['area'] === '86';
$build['name'] = $value['name'];
$data['countrys'][] = $build;
}
}
// 没数据
else {
$data['countrys'][0] = array();
$data['countrys'][0]['areaCode'] = '+86';
$data['countrys'][0]['selected'] = true;
$data['countrys'][0]['name'] = '中国';
}
$this->_view->display('interational', $data);
$data = array();
$area = array();
$data['loginInterational'] = true; // 模板中使用JS的标识
$data['backUrl'] = '/'; // 返回的URL链接
$data['headerText'] = '登录'; // 头部信息
$data['isPassportPage'] = true; // 模板中模块标识
$data['areaCode'] = '+86'; // 默认区号
$data['countrys'] = RegData::getAreasData(); // 地区信息列表
//
// 生成HTML(login.html)
$this->_view->html('login');
// 渲染模板
$this->_view->display('interational', $data);
}
/**
* 登录操作
*
... ... @@ -84,13 +68,13 @@ class LoginController extends AbstractAction
public function authAction()
{
$data = array('code' => 400, 'message' => '账号或密码不正确', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
/* 判断参数是否传递 */
$area = $this->post('areaCode', '86');
$profile = $this->post('account');
... ... @@ -98,23 +82,22 @@ class LoginController extends AbstractAction
if (!is_numeric($area) || empty($profile) || empty($password)) {
break;
}
/* 判断参数是否有效 */
$verifyEmail = Helpers::verifyEmail($profile);
$verifyMobile = ($area === '86') ? Helpers::verifyMobile($profile)
: Helpers::verifyAreaMobile($profile);
$verifyMobile = ($area === '86') ? Helpers::verifyMobile($profile) : Helpers::verifyAreaMobile($profile);
if (!$verifyEmail && !$verifyMobile) {
break;
}
/* 调用登录接口进行登录 */
$data = LoginData::signin($area, $profile, $password);
if ($data['code'] == 200) {
$data['data'] = '/'; // @todo
}
} while (false);
}
while (false);
$this->echoJson($data);
}
... ... @@ -124,8 +107,7 @@ class LoginController extends AbstractAction
public function alipayAction()
{
$redirect = $this->_request->getServer('HTTP_REFERER', '');
if($redirect != '')
{
if ($redirect != '') {
$this->setCookie('alipay_redirect', $redirect);
}
Factory::create('alipay')->getAuthorizeUrl();
... ... @@ -133,15 +115,13 @@ class LoginController extends AbstractAction
exit();
}
/**
* QQ账号登录:授权页面
*/
public function qqAction()
{
$redirect = $this->_request->getServer('HTTP_REFERER', '');
if($redirect != '')
{
if ($redirect != '') {
$this->setCookie('qq_redirect', $redirect);
}
Factory::create('qqconnect')->getAuthorizeUrl();
... ... @@ -149,15 +129,13 @@ class LoginController extends AbstractAction
exit();
}
/**
* 新浪微博账号登录:授权页面
*/
public function sinaAction()
{
$redirect = $this->_request->getServer('HTTP_REFERER', '');
if($redirect != '')
{
if ($redirect != '') {
$this->setCookie('sina_redirect', $redirect);
}
header('Location:' . Factory::create('sinaweibo')->getAuthorizeUrl());
... ... @@ -174,19 +152,16 @@ class LoginController extends AbstractAction
$alipay = Factory::create('alipay');
$access = $alipay->getAccessToken();
if (!isset($_GET['real_name']))
{
if (!isset($_GET['real_name'])) {
/* 获取支付宝用户的详细信息 */
$userInfo = $alipay->getUserInfo($access);
if ($userInfo && $userInfo['is_success'] === 'T' && isset($userInfo['response']['user_info']['user_name']))
{
if ($userInfo && $userInfo['is_success'] === 'T' && isset($userInfo['response']['user_info']['user_name'])) {
$nickname = $userInfo['response']['user_info']['user_name'];
$alipayEmail = $userInfo['response']['user_info']['email'];
}
var_dump($userInfo);
}
else
{
else {
$nickname = $_GET['real_name'];
$alipayEmail = isset($_GET['email']) ? $_GET['email'] : '';
}
... ... @@ -194,8 +169,7 @@ class LoginController extends AbstractAction
$result = LoginData::signinByOpenID($nickname, $access['user_id'], 'qq');
if($result['code'] == 200)
{
if ($result['code'] == 200) {
$redirect = $this->_request->getCookie('alipay_redirect');
$redirect && $this->redirect($redirect);
}
... ... @@ -213,12 +187,10 @@ class LoginController extends AbstractAction
/* 获取QQ腾讯用户的详细信息 */
$partnerInfo = $qqconnect->getUserInfo($access);
if ($partnerInfo && is_array($partnerInfo))
{
if ($partnerInfo && is_array($partnerInfo)) {
$result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['openid'], 'qq');
if($result['code'] == 200)
{
if ($result['code'] == 200) {
$redirect = $this->_request->getCookie('qq_redirect');
$redirect && $this->redirect($redirect);
}
... ... @@ -237,17 +209,16 @@ class LoginController extends AbstractAction
/* 获取QQ腾讯用户的详细信息 */
$partnerInfo = $sina->getUserInfo($access);
if ($partnerInfo && is_array($partnerInfo))
{
if ($partnerInfo && is_array($partnerInfo)) {
$result = LoginData::signinByOpenID($partnerInfo['screen_name'], $access['uid'], 'sina');
if($result['code'] == 200)
{
if ($result['code'] == 200) {
$redirect = $this->_request->getCookie('sina_redirect');
$redirect && $this->redirect($redirect);
}
}
}
$this->redirect('/');
$this->redirect('/');
}
}
\ No newline at end of file
}
... ...
... ... @@ -16,38 +16,18 @@ class RegController extends AbstractAction
{
$this->setTitle('注册');
$data = array();
$data['regIndex'] = true;
$data['backUrl'] = '/';
$data['headerText'] = '注册';
$data['isPassportPage'] = true;
$data['countrys'] = array();
$data['areaCode'] = '+86';
// 获取地区数据列表
$area = RegData::getAreasData();
// 有数据
if (!empty($area['data'])) {
$build = array();
foreach ($area['data'] as $value) {
$build = array();
$build['areaCode'] = '+' . $value['area'];
$build['selected'] = $value['area'] === '86';
$build['name'] = $value['name'];
$data['countrys'][] = $build;
}
}
// 没数据
else {
$data['countrys'][0] = array();
$data['countrys'][0]['areaCode'] = '+86';
$data['countrys'][0]['selected'] = true;
$data['countrys'][0]['name'] = '中国';
}
$data = array();
$data['regIndex'] = true; // 模板中使用JS的标识
$data['backUrl'] = '/'; // 返回的URL链接
$data['headerText'] = '注册'; // 头部信息
$data['isPassportPage'] = true; // 模板中模块标识
$data['areaCode'] = '+86'; // 默认的区号
$data['countrys'] = RegData::getAreasData(); // 地区信息列表
// 生成HTML(reg.html)
$this->_view->html('reg');
// 渲染模板
$this->_view->display('index', $data);
$data = array();
$area = array();
}
/**
... ... @@ -70,15 +50,16 @@ class RegController extends AbstractAction
$this->setTitle('注册-验证码');
$data = array();
$data['regCode'] = true;
$data['backUrl'] = '/';
$data['headerText'] = '注册';
$data['isPassportPage'] = true;
$data['areaCode'] = '+' . $area;
$data['phoneNum'] = $mobile;
$data['token'] = $token;
$data = array(
'regCode' => true, // 模板中使用JS的标识
'backUrl' => '/', // 返回的URL链接
'headerText' => '注册', // 头部信息
'isPassportPage' => true, // 模板中模块标识
'areaCode' => '+' . $area, // 地区编号
'phoneNum' => $mobile, // 手机号
'token' => $token, // 访问令牌
);
$this->_view->display('code', $data);
}
... ... @@ -103,14 +84,15 @@ class RegController extends AbstractAction
$this->setTitle('注册-设置密码');
$data = array();
$data['regPwd'] = true;
$data['backUrl'] = '/';
$data['headerText'] = '注册';
$data['isPassportPage'] = true;
$data['areaCode'] = $area;
$data['phoneNum'] = $mobile;
$data['token'] = $token;
$data = array(
'regPwd' => true, // 模板中使用JS的标识
'backUrl' => '/', // 返回的URL链接
'headerText' => '注册', // 头部信息
'isPassportPage' => true, // 模板中模块标识
'areaCode' => $area, // 地区编号
'phoneNum' => $mobile, // 手机号
'token' => $token, // 访问令牌
);
$this->_view->display('password', $data);
}
... ... @@ -209,7 +191,7 @@ class RegController extends AbstractAction
*/
public function sendcodeAction()
{
$data = array('code' => 400, 'message' => '参数不正确!', 'data' => '');
$data = array('code' => 400, 'message' => '发送验证码失败', 'data' => '');
do {
/* 判断是不是AJAX请求 */
... ...
... ... @@ -44,4 +44,7 @@ application.dispatcher.catchException = True
application.template.compile = ROOT_PATH "/compile/m.yohobuy.com"
application.template.path = ROOT_PATH "/template/m.yohobuy.com/actions"
application.template.partials = ROOT_PATH "/template/m.yohobuy.com/partials"
application.template.ext = ".phtml"
\ No newline at end of file
application.template.ext = ".phtml"
;静态HTML页面的存放目录, 该目录需要有读写权限
application.assets.path = ROOT_PATH "/assets"
\ No newline at end of file
... ...
... ... @@ -44,4 +44,7 @@ application.dispatcher.catchException = False
application.template.compile = ROOT_PATH "/compile/m.yohobuy.com"
application.template.path = ROOT_PATH "/template/m.yohobuy.com/actions"
application.template.partials = ROOT_PATH "/template/m.yohobuy.com/partials"
application.template.ext = ".phtml"
\ No newline at end of file
application.template.ext = ".phtml"
;静态HTML页面的存放目录, 该目录需要有读写权限
application.assets.path = ROOT_PATH "/assets"
\ No newline at end of file
... ...
... ... @@ -44,4 +44,7 @@ application.dispatcher.catchException = True
application.template.compile = ROOT_PATH "/compile/m.yohobuy.com"
application.template.path = ROOT_PATH "/template/m.yohobuy.com/actions"
application.template.partials = ROOT_PATH "/template/m.yohobuy.com/partials"
application.template.ext = ".phtml"
\ No newline at end of file
application.template.ext = ".phtml"
;静态HTML页面的存放目录, 该目录需要有读写权限
application.assets.path = ROOT_PATH "/assets"
\ No newline at end of file
... ...
[common]
servers.host = 127.0.0.1:11211:90
[memcached:common]
servers.hosts = 127.0.0.1:11212:90,127.0.0.1:11213:10
[memcached]
master.hosts = 127.0.0.1:11212,127.0.0.1:11213
slave.hosts = 127.0.0.1:11212,127.0.0.1:11213
[redis]
servers.hosts = 192.168.1.168:6379
\ No newline at end of file
... ...
... ... @@ -33,4 +33,19 @@ routes.interational.route.module = Passport
routes.interational.route.controller = Login
routes.interational.route.action = Interational
; 找回密码(手机号)
routes.phoneback.type = "rewrite"
routes.phoneback.match = "/phoneback.html$"
routes.phoneback.route.module = Passport
routes.phoneback.route.controller = Back
routes.phoneback.route.action = Mobile
; 找回密码(邮箱)
routes.emailback.type = "rewrite"
routes.emailback.match = "/emailback.html$"
routes.emailback.route.module = Passport
routes.emailback.route.controller = Back
routes.emailback.route.action = Email
... ...