Authored by Rock Zhang

完成找回密码功能

... ... @@ -13,7 +13,7 @@ use Api\Sign;
* @version 1.0 (2015-10-10)
* @author gtskk <rocky.zhang@yoho.cn>
*/
class ClassData
class BackData
{
/**
* 获取地区数据
... ... @@ -32,7 +32,25 @@ class ClassData
}
/**
* 通过手机号发送验证码找回密码
* 通过邮箱找回密码
*
* @param string $email 邮箱地址
* @return array 返回状态数据
*/
public static function sendCodeToEmail($email)
{
// 构建必传参数
$param = Yohobuy::param();
$param['email'] = $email;
$param['method'] = 'app.register.backpwdByEmail';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 通过手机找回密码
*
* @param string $mobile 手机号
* @param integer $area 地区码ID
... ... @@ -44,9 +62,55 @@ class ClassData
$param = Yohobuy::param();
$param['mobile'] = $mobile;
$param['area'] = $area;
$param['method'] = 'app.register.sendBackpwdCodeToMobile';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 校验密码修改手机验证码
*
* @param string $mobile 手机号
* @param string $code 验证码
* @param integer $area 地区码ID
* @return array 返回状态数据(token)
*/
public static function validateMobileCode($mobile, $code, $area = 86)
{
// 构建必传参数
$param = Yohobuy::param();
$param['mobile'] = $mobile;
$param['code'] = $code;
$param['area'] = $area;
$param['method'] = 'app.register.validBackpwdCode';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 根据手机验证码修改密码
*
* @param string $mobile 手机号
* @param string $token 验证手机验证码返回的token
* @param integer $area 地区码ID
* @return array 返回状态数据
*/
public static function modifyPasswordByMobile($mobile, $token, $newpwd, $area = 86)
{
// 构建必传参数
$param = Yohobuy::param();
$param['mobile'] = $mobile;
$param['token'] = $token;
$param['newpwd'] = $newpwd;
$param['area'] = $area;
$param['method'] = 'app.register.changepwdByMobileCode';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Passport\BackData;
/**
* 频道选择
*/
... ... @@ -23,6 +25,22 @@ class BackController extends AbstractAction
$this->_view->display('email', $data);
}
/**
* 发送邮箱验证码
*/
public function emailcodeSendAction()
{
if($this->isAjax())
{
$email = $this->get('email', '');
// 发送邮箱验证码
$result = BackData::sendCodeToEmail($email);
$this->echoJson($result);
}
}
public function successAction()
{
$data = array(
... ... @@ -38,24 +56,57 @@ class BackController extends AbstractAction
$this->_view->display('email-success', $data);
}
/**
* 根据邮箱修改密码
*
* @return array 根据邮箱修改密码的结果
*/
public function passwordByEmailAction()
{
// host是www.yohobuy.com ,只需要code,然后再输入新密码即可
$code = $this->get('code', '');
// 根据邮箱修改密码(接口待定)
// $result = BackData::validateMobileCode($mobile, $code, $area);
$this->echoJson($data);
}
public function mobileAction()
{
// 获取地区信息
$areas = array();
$areaDatas = $data = BackData::getAreasData();
if($areaDatas['code'] == 200)
{
$areas = $areaDatas['data'];
}
// 处理地区信息
foreach ($areas as &$val) {
$val['areaCode'] = $val['area'];
if($val['area'] == 86)
{
$val['selected'] = true;
}
unset($val['area']);
}
/*// 排序
uasort($areas, function($a, $b) {
if($a['id'] === $b['id'])
{
return 0;
}
return ($a['id'] < $b['id'] ? -1 : 1);
});*/
$data = array(
'backUrl' => 'm.yohobuy.com',
'headerText' => '找回密码',
'isPassportPage' => true,
'modulePath' => 'passport/back/mobile',
'countrys' => array(
array(
'areaCode' => '+86',
'selected' => true,
'name' => '中国'
),
array(
'areaCode' => '+864',
'name' => '中国香港'
)
),
'countrys' => $areas,
'countryCode' => '+86'
);
... ... @@ -63,23 +114,67 @@ class BackController extends AbstractAction
$this->_view->display('mobile', $data);
}
public function codeAction()
/**
* 发送手机验证码
*/
public function mobilecodeSendAction()
{
if($this->isAjax())
{
$mobile = $this->get('mobile', '');
$area = $this->get('area', 86);
// 发送手机验证码
$result = BackData::sendCodeToMobile($mobile, $area);
$this->echoJson($result);
}
}
public function mobilecodeAction()
{
$mobile = $this->get('mobile', '');
$area = $this->get('area', 86);
$data = array(
'backUrl' => 'm.yohobuy.com',
'headerText' => '找回密码',
'isPassportPage' => true,
'modulePath' => 'passport/back/code',
'areaCode' => '+86',
'phoneNum' => '15895869035'
'phoneNum' => $mobile
);
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('mobile-code', $data);
}
/**
* 校验手机验证码
*
* @return array 校验手机验证码的结果
*/
public function mobilecodeValidateAction()
{
if($this->isAjax())
{
$mobile = $this->get('mobile', '');
$code = $this->get('code', '');
$area = $this->get('area', 86);
// 校验手机验证码
$result = BackData::validateMobileCode($mobile, $code, $area);
$this->echoJson($data);
}
}
public function passwordAction()
{
$mobile = $this->get('mobile', '');
$token = $this->get('token', '');
$area = $this->get('area', 86);
$data = array(
'backUrl' => 'm.yohobuy.com',
'headerText' => '找回密码',
... ... @@ -99,4 +194,25 @@ class BackController extends AbstractAction
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('new-password', $data);
}
/**
* 根据手机验证码修改密码
*
* @return array 根据手机验证码修改密码的结果
*/
public function passwordByMobileAction()
{
if($this->isAjax())
{
$mobile = $this->get('mobile', '');
$token = $this->get('token', '');
$newpwd = $this->get('newpwd', 86);
$area = $this->get('area', 86);
// 根据手机验证码修改密码
$result = BackData::modifyPasswordByMobile($mobile, $token, $newpwd, $area);
$this->echoJson($data);
}
}
}
\ No newline at end of file
... ...