Authored by hf

do reg and login page

存放生成的HTML文件等
\ No newline at end of file
... ...
... ... @@ -19,14 +19,16 @@ class LoginData
/**
* 登录
*
* @param string $area 地区编号
* @param string $profile 邮箱或手机号
* @param string $password 密码
* @return array
*/
public static function signin($profile, $password)
public static function signin($area, $profile, $password)
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.signin';
$param['area'] = $area;
$param['profile'] = $profile;
$param['password'] = $password;
... ...
... ... @@ -33,7 +33,7 @@ class Helpers
if (!isset($productData['product_skn'])) {
return false;
}
// 市场价和售价一样,则不显示市场价
if (intval($productData['market_price']) === intval($productData['sales_price'])) {
$productData['market_price'] = false;
... ... @@ -57,10 +57,10 @@ class Helpers
$result['tags']['yearEnd'] = isset($productData['year-end']) && $productData['year-end'] === 'Y'; // 年末
$result['tags']['isReNew'] = false; // 再到着
$result['tags']['isNewFestival'] = false; // 新品节
return $result;
}
/**
* 生成公开的TOKEN凭证
*
... ... @@ -69,9 +69,9 @@ class Helpers
*/
public static function makeToken($string)
{
return md5(md5($string.'#@!@#'));
return md5(md5($string . '#@!@#'));
}
/**
* 验证TOKEN凭证
*
... ... @@ -83,9 +83,131 @@ class Helpers
{
if ($token === self::makeToken($string)) {
return true;
} else {
}
else {
return false;
}
}
/**
* 验证手机是否合法
*
* @param int $mobile
* @return boolean
*/
public static function verifyMobile($mobile)
{
if (empty($mobile)) {
return false;
}
return (bool) preg_match('/^1[3|4|5|8|7][0-9]{9}$/', trim($mobile));
}
/**
* 验证密码是否合法
*
* @param int $password
* @return boolean
*/
public static function verifyPassword($password)
{
if (empty($password)) {
return false;
}
return (bool) preg_match('/^([a-zA-Z0-9\-\+_!@\#$%\^&\*\(\)\:\;\.=\[\]\\\',\?]){6,20}$/', trim($password));
}
}
\ No newline at end of file
/**
* 验证邮箱是否合法
*
* @param string $email
* @return boolean
*/
public static function verifyEmail($email)
{
if (empty($email)) {
return false;
}
return !!filter_var($email, FILTER_VALIDATE_EMAIL);
}
/**
* 验证国际手机号是否合法
*
* @param string $areaMobile
* @return boolean
*/
public static function verifyAreaMobile($areaMobile)
{
if (empty($areaMobile)) {
return false;
}
if (!strpos($areaMobile, '-')) {
return self::areaMobielVerify($areaMobile);
} else {
$mobileData = explode('-', $areaMobile);
if (count($mobileData) != 2) {
return false;
}
}
return self::areaMobielVerify($mobileData[1], $mobileData[0]);
}
/**
* 各国手机号规则
*/
private static function areaMobielVerify($mobile, $area = 86)
{
$verify = array(
86 => array(
'name' => '中国',
'match' => (bool) preg_match('/^1[3|4|5|8|7][0-9]{9}$/', trim($mobile)),
),
852 => array(
'name' => '中国香港',
'match' => (bool) preg_match('/^[9|6|5][0-9]{7}$/', trim($mobile)),
),
853 => array(
'name' => '中国澳门',
'match' => (bool) preg_match('/^[0-9]{8}$/', trim($mobile)),
),
886 => array(
'name' => '中国台湾',
'match' => (bool) preg_match('/^[0-9]{10}$/', trim($mobile)),
),
65 => array(
'name' => '新加坡',
'match' => (bool) preg_match('/^[9|8][0-9]{7}$/', trim($mobile)),
),
60 => array(
'name' => '马来西亚',
'match' => (bool) preg_match('/^1[1|2|3|4|6|7|9][0-9]{8}$/', trim($mobile)),
),
1 => array(
'name' => '加拿大&美国',
'match' => (bool) preg_match('/^[0-9]{10}$/', trim($mobile)),
),
82 => array(
'name' => '韩国',
'match' => (bool) preg_match('/^01[0-9]{9}$/', trim($mobile)),
),
44 => array(
'name' => '英国',
'match' => (bool) preg_match('/^7[7|8|9][0-9]{8}$/', trim($mobile)),
),
81 => array(
'name' => '日本',
'match' => (bool) preg_match('/^0[9|8|7][0-9]{9}$/', trim($mobile)),
),
61 => array(
'name' => '澳大利亚',
'match' => (bool) preg_match('/^[0-9]{11}$/', trim($mobile)),
),
);
if (isset($verify[$area])) {
return $verify[$area]['match'];
}
return false;
}
}
... ...
server
{
listen 80;
server_name wap.yohobuy.com;
#access_log /Data/logs/access.wap.yohobuy.com.log combined;
error_log /Data/logs/error.wap.yohobuy.com.log warn;
root /Data/PE/yohobuy/yohobuy/m.yohobuy.com/public;
location ~* \.html$ {
root /Data/PE/yohobuy/assets;
if (!-f $request_filename){
root /Data/PE/yohobuy/yohobuy/m.yohobuy.com/public;
rewrite ^/(.+)$ /index.php?$1& last;
}
expires 7d;
}
location / {
index index.php;
if (!-f $request_filename){
rewrite ^/(.+)$ /index.php?$1& last;
}
}
location ~* \.(ico|woff)$ {
expires 7d;
}
location = /crossdomain.xml {
expires 7d;
}
location ~ .*\.php?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 403 = http://wap.yohobuy.com;
error_page 404 = http://wap.yohobuy.com/error.html;
}
server
{
listen 80;
server_name static.wap.yohobuy.com;
#access_log /Data/logs/access.static.wap.yohobuy.com.log combined;
#error_log /Data/logs/error.static.wap.yohobuy.com.log warn;
root /Data/PE/yohobuy/static;
location / {
log_not_found off;
access_log off;
expires 30d;
}
location ~* \.(svg|eot|ttf|woff|otf)$ {
add_header Access-Control-Allow-Origin *;
expires 30d;
}
}
\ No newline at end of file
... ...
<?php
use Action\AbstractAction;
use Plugin\Partner\Factory;
use LibModels\Wap\Passport\LoginData;
use LibModels\Wap\Passport\RegData;
use Plugin\Helpers;
use Plugin\Partner\Factory;
/**
* 登录的控制器
*/
class LoginController extends AbstractAction
{
/**
* 登录页
*/
public function indexAction()
{
$this->setTitle('登录');
$data = array(
'backUrl' => 'm.yohobuy.com',
'loginIndex' => true,
'backUrl' => '/',
'showHeaderImg' => true,
'isPassportPage' => true,
'modulePath' => 'passport/login/login'
'registerUrl' => '/reg.html',
'interationalUrl' => '/login.html',
'phoneRetriveUrl' => '',
'emailRetriveUrl' => '',
);
$this->_view->assign('title', '登录');
$this->_view->display('index', $data);
}
/**
* 国际账号登录页
*/
public function interationalAction()
{
$data = array(
'backUrl' => 'm.yohobuy.com',
'headerText' => '登录',
'isPassportPage' => true,
'modulePath' => 'passport/login/interational',
'countrys' => array(
array(
'areaCode' => '+86',
'selected' => true,
'name' => '中国'
),
array(
'areaCode' => '+864',
'name' => '中国香港'
)
),
'countryCode' => '+86'
);
$this->setTitle('国际账号登录');
$data = array();
$data['loginInterational'] = true;
$data['backUrl'] = '/';
$data['headerText'] = '登录';
$data['isPassportPage'] = true;
$data['countryCode'] = '+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->assign('title', '国际账号登录');
$this->_view->display('interational', $data);
$data = array();
$area = array();
}
/**
* 登录操作
*
* @param string area 地区编号, 不需要+号
* @param string profile 账号(邮箱或手机号)
* @param string password 密码
* @return json
*/
public function authAction()
{
$data = array('code' => 400, 'message' => '账号或密码不正确', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
/* 判断参数是否传递 */
$area = $this->post('area', '86');
$profile = $this->post('profile');
$password = $this->post('password');
if (!is_numeric($area) || empty($profile) || empty($password)) {
break;
}
/* 判断参数是否有效 */
$verifyEmail = Helpers::verifyEmail($profile);
$verifyMobile = ($area === '86') ? Helpers::verifyMobile($profile)
: Helpers::verifyAreaMobile($profile);
if (!$verifyEmail && !$verifyMobile) {
break;
}
/* 调用登录接口进行登录 */
$data = LoginData::signin($area, $profile, $password);
} while (false);
$this->echoJson($data);
}
/**
* 支付宝账号登录:授权页面
... ...
... ... @@ -17,12 +17,15 @@ class RegController extends AbstractAction
$this->setTitle('注册');
$data = array();
$data['regIndex'] = true;
$data['backUrl'] = '/';
$data['headerText'] = '注册';
$data['isPassportPage'] = true;
$data['countrys'] = array();
// 获取地区数据列表
$area = RegData::getAreasData();
// 有数据
if (!empty($area['data'])) {
$build = array();
foreach ($area['data'] as $value) {
... ... @@ -32,7 +35,9 @@ class RegController extends AbstractAction
$build['name'] = $value['name'];
$data['countrys'][] = $build;
}
} else {
}
// 没数据
else {
$data['countrys'][0] = array();
$data['countrys'][0]['areaCode'] = '+86';
$data['countrys'][0]['selected'] = true;
... ... @@ -65,11 +70,13 @@ 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;
$this->_view->display('code', $data);
}
... ... @@ -83,14 +90,27 @@ class RegController extends AbstractAction
*/
public function passwordAction()
{
$data = array(
'backUrl' => 'm.yohobuy.com',
'headerText' => '注册',
'isPassportPage' => true,
'modulePath' => 'passport/register/password'
);
$token = $this->get('token');
$mobile = $this->get('mobile');
$area = $this->get('area', '86');
// 判断是否允许访问, 不允许则跳转到错误页面
if (!is_string($token) || !is_numeric($mobile) || !is_numeric($area)
|| !Helpers::verifyToken($mobile, $token)) {
$this->error();
}
$this->setTitle('注册-设置密码');
$data = array();
$data['regPwd'] = true;
$data['backUrl'] = '/';
$data['headerText'] = '注册';
$data['isPassportPage'] = true;
$data['areaCode'] = $area;
$data['phoneNum'] = $mobile;
$data['token'] = $token;
$this->_view->assign('title', '注册-密码');
$this->_view->display('password', $data);
}
... ... @@ -99,7 +119,6 @@ class RegController extends AbstractAction
*
* @param string area 地区编号,注意不需要+号
* @param string mobile 手机号
* @param string token 访问TOKEN凭证
* @return json
*/
public function verifymobileAction()
... ... @@ -112,16 +131,10 @@ class RegController extends AbstractAction
break;
}
$token = $this->post('token');
$mobile = $this->post('mobile');
$area = $this->post('area', '86');
/* 判断参数是否合法 */
if (!is_string($token) || !is_numeric($mobile) || !is_numeric($area)) {
break;
}
/* 判断是否允许访问 */
if (!Helpers::verifyToken($mobile, $token)) {
if (!is_numeric($mobile) || !is_numeric($area)) {
break;
}
... ... @@ -133,12 +146,13 @@ class RegController extends AbstractAction
/* 返回跳转到验证页面的链接*/
if ($data['code'] == 200) {
$token = Helpers::makeToken($mobile);
$data['data'] = '/passport/reg/code?token='.$token.'&mobile='.$mobile.'&area='.$area;
}
} while (false);
echo $this->echoJson($data);
$this->echoJson($data);
}
/**
... ... @@ -160,17 +174,11 @@ class RegController extends AbstractAction
break;
}
$token = $this->post('token');
$mobile = $this->post('mobile');
$area = $this->post('area');
$code = $this->post('code');
/* 判断参数是否合法 */
if (!is_string($token) || !is_numeric($mobile) || !is_numeric($area) || !isset($code)) {
break;
}
/* 判断是否允许访问 */
if (!Helpers::verifyToken($mobile, $token)) {
if (!is_numeric($mobile) || !is_numeric($area) || !isset($code)) {
break;
}
... ... @@ -182,12 +190,48 @@ class RegController extends AbstractAction
/* 返回跳转到设置密码的链接*/
if ($data['code'] == 200) {
$token = Helpers::makeToken($mobile);
$data['data'] = '/passport/reg/password?token='.$token.'&mobile='.$mobile.'&area='.$area;
}
} while (false);
echo $this->echoJson($data);
$this->echoJson($data);
}
/**
* 发送验证码
*
* @param string area 地区编号,注意不需要+号
* @param string mobile 手机号
* @return json
*/
public function sendcodeAction()
{
$data = array('code' => 400, 'message' => '参数不正确!', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
$mobile = $this->post('mobile');
$area = $this->post('area', '86');
/* 判断参数是否合法 */
if (!is_numeric($mobile) || !is_numeric($area)) {
break;
}
/* 向手机发送注册验证码 */
$data = RegData::sendCodeToMobile($area, $mobile);
if (!isset($data['code'])) {
break;
}
} while (false);
$this->echoJson($data);
}
/**
... ... @@ -201,7 +245,7 @@ class RegController extends AbstractAction
*/
public function setpasswordAction()
{
$data = array('code' => 400, 'message' => '参数不正确!', 'data' => '');
$data = array('code' => 400, 'message' => '密码格式不正确!', 'data' => '');
do {
/* 判断是不是AJAX请求 */
... ... @@ -229,14 +273,14 @@ class RegController extends AbstractAction
break;
}
/* 返回跳转到设置密码的链接*/
/* 返回跳转到来源页面 */
if ($data['code'] == 200) {
$data['data'] = '/passport/reg/password?token='.$token.'&mobile='.$mobile.'&area='.$area;
}
} while (false);
echo $this->echoJson($data);
$this->echoJson($data);
}
}
\ No newline at end of file
... ...
; default
; 默认页
routes.index.type = "rewrite"
routes.index.match = "/index.html$"
routes.index.route.module = Index
routes.index.route.controller = Index
routes.index.route.action = Index
; error
routes.notfound.type = "rewrite"
routes.notfound.match = "/error.html$"
routes.notfound.route.module = Index
routes.notfound.route.controller = Error
routes.notfound.route.action = Index
\ No newline at end of file
; 错误页
routes.error.type = "rewrite"
routes.error.match = "/error.html$"
routes.error.route.module = Index
routes.error.route.controller = Error
routes.error.route.action = Index
; 注册页
routes.reg.type = "rewrite"
routes.reg.match = "/reg.html$"
routes.reg.route.module = Passport
routes.reg.route.controller = Reg
routes.reg.route.action = Index
; 登录页
routes.login.type = "rewrite"
routes.login.match = "/signin.html$"
routes.login.route.module = Passport
routes.login.route.controller = Login
routes.login.route.action = Index
; 登录页(国际账号)
routes.interational.type = "rewrite"
routes.interational.match = "/login.html$"
routes.interational.route.module = Passport
routes.interational.route.controller = Login
routes.interational.route.action = Interational
... ...