Authored by hf

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

  1 +<?php
  2 +namespace LibModels\Web\Passport;
  3 +use Api\Sign;
  4 +use Api\Yohobuy;
  5 +class BackData extends \LibModels\Wap\Passport\BackData
  6 +{
  7 + /**
  8 + * 验证找回邮件code
  9 + *
  10 + * @param string $code
  11 + * @return array
  12 + */
  13 + public static function checkEmailCode($code)
  14 + {
  15 + $param = Yohobuy::param();
  16 + $param['method'] = 'app.register.checkCodeValid';
  17 + $param['code'] = $code;
  18 + $param['client_secret'] = Sign::getSign($param);
  19 + return Yohobuy::get(Yohobuy::API_URL, $param, 3600); // 缓存1小时
  20 + }
  21 +
  22 + /**
  23 + * 根据邮箱code修改密码
  24 + *
  25 + * @param string $code
  26 + * @param string $password
  27 + * @return array
  28 + */
  29 + public static function modifyPasswordByEmailCode($code, $password)
  30 + {
  31 + $param = Yohobuy::param();
  32 + $param['method'] = 'app.register.resetPwdByCode';
  33 + $param['code'] = $code;
  34 + $param['newPwd'] = $password;
  35 + $param['client_secret'] = Sign::getSign($param);
  36 + return Yohobuy::get(Yohobuy::API_URL, $param);
  37 + }
  38 +}
@@ -3,7 +3,7 @@ use Action\WebAction; @@ -3,7 +3,7 @@ use Action\WebAction;
3 use LibModels\Web\Passport\RegData; 3 use LibModels\Web\Passport\RegData;
4 use Passport\PassportModel; 4 use Passport\PassportModel;
5 use Plugin\Helpers; 5 use Plugin\Helpers;
6 -use LibModels\Wap\Passport\BackData; 6 +use LibModels\Web\Passport\BackData;
7 use Plugin\AuthCode; 7 use Plugin\AuthCode;
8 class BackController extends WebAction { 8 class BackController extends WebAction {
9 9
@@ -43,14 +43,14 @@ class BackController extends WebAction { @@ -43,14 +43,14 @@ class BackController extends WebAction {
43 if (Helpers::verifyEmail($phoneNum)) { 43 if (Helpers::verifyEmail($phoneNum)) {
44 $ret = PassportModel::getUserInfoByEmail($phoneNum); 44 $ret = PassportModel::getUserInfoByEmail($phoneNum);
45 if (empty($ret)) { 45 if (empty($ret)) {
46 - $data['message'] = '该账户不存在';  
47 - $data['code'] = 400; 46 + $data['message'] = '该邮件账户不存在';
  47 + $data['code'] = 401;
48 } 48 }
49 } else if (Helpers::verifyMobile($phoneNum)) { 49 } else if (Helpers::verifyMobile($phoneNum)) {
50 $ret = PassportModel::getUserInfoByMobile($area, $phoneNum); 50 $ret = PassportModel::getUserInfoByMobile($area, $phoneNum);
51 if (empty($ret)) { 51 if (empty($ret)) {
52 - $data['message'] = '该账户不存在';  
53 - $data['code'] = 400; 52 + $data['message'] = '该手机号不存在';
  53 + $data['code'] = 402;
54 } 54 }
55 } 55 }
56 } else { 56 } else {
@@ -135,7 +135,22 @@ class BackController extends WebAction { @@ -135,7 +135,22 @@ class BackController extends WebAction {
135 { 135 {
136 $code = $this->get('code'); 136 $code = $this->get('code');
137 $info = $this->checkCode($code); 137 $info = $this->checkCode($code);
138 - if (empty ( $info )) { 138 + $verifyState = false;//验证状态
  139 + $ret = array();
  140 + if (!empty ( $info )) {
  141 + $verifyState = true;
  142 + if(isset($info['uid'])) { //老版修改邮箱密码
  143 + $verifyState = false;//重新找回密码
  144 + }
  145 + } else {
  146 + $ret = BackData::checkEmailCode($code);
  147 + if(isset($ret['data']) && $ret['code'] == 200) {
  148 + $verifyState = true;
  149 + }
  150 + }
  151 + //验证失败
  152 + if(!$verifyState)
  153 + {
139 $this->redirect ('index'); 154 $this->redirect ('index');
140 } 155 }
141 $banner = PassportModel::getLeftBanner(PassportModel::BACK_LFFT_BANNER_CODE); 156 $banner = PassportModel::getLeftBanner(PassportModel::BACK_LFFT_BANNER_CODE);
@@ -160,7 +175,8 @@ class BackController extends WebAction { @@ -160,7 +175,8 @@ class BackController extends WebAction {
160 $code = $this->post('code'); 175 $code = $this->post('code');
161 $password = $this->post('pwd'); 176 $password = $this->post('pwd');
162 $info = $this->checkCode($code); 177 $info = $this->checkCode($code);
163 - if (Helpers::verifyPassword ($password) && ! empty ($info)) { 178 + if (Helpers::verifyPassword ($password)) {
  179 + if(!empty($info)) { //手机号找回
164 // 修改密码 180 // 修改密码
165 if (isset ( $info ['mobile'] )) { // 手机号修改密码 181 if (isset ( $info ['mobile'] )) { // 手机号修改密码
166 $mobile = $info ['mobile']; 182 $mobile = $info ['mobile'];
@@ -170,13 +186,18 @@ class BackController extends WebAction { @@ -170,13 +186,18 @@ class BackController extends WebAction {
170 if ($data ['code'] == 200) { 186 if ($data ['code'] == 200) {
171 $this->redirect ( 'resetSuccess' ); 187 $this->redirect ( 'resetSuccess' );
172 } 188 }
173 - } else if (isset ($info ['uid'])) { // 其他方式修改密码  
174 - $uid = $info ['uid']; 189 + } else if (isset ($info ['uid'])) { //其他方式修改密码,跳到找回密码首页
  190 + $this->redirect ( '/index' );
  191 + }
  192 + } else { //新版邮箱修改接口
  193 + $data = BackData::modifyPasswordByEmailCode($code, $password);
  194 + if ($data ['code'] == 200) {
175 $this->redirect ( 'resetSuccess' ); 195 $this->redirect ( 'resetSuccess' );
176 } 196 }
177 } 197 }
  198 + }
178 // 跳转错误页面 199 // 跳转错误页面
179 - $this->redirect('/error/index'); 200 + $this->redirect('/index');
180 } 201 }
181 202
182 /** 203 /**