Blame view

yohobuy/m.yohobuy.com/application/modules/Passport/controllers/Back.php 7.92 KB
hf authored
1
<?php
Rock Zhang authored
2
xuqi authored
3
use Action\AbstractAction;
Rock Zhang authored
4
use LibModels\Wap\Passport\BackData;
5
use LibModels\Wap\Passport\RegData;
6
use Plugin\Helpers;
7
xuqi authored
8 9
/**
 * 频道选择
hf authored
10
 */
xuqi authored
11 12 13 14 15
class BackController extends AbstractAction
{

    public function emailAction()
    {
16 17
        $this->setTitle('找回密码-通过邮箱');
        
xuqi authored
18
        $data = array(
19
            'backUrl' => '/signin.html',
xuqi authored
20 21
            'headerText' => '找回密码',
            'isPassportPage' => true,
22
            'backEmail' => true
xuqi authored
23 24
        );
25 26
        // 生成HTML (emailback.html)
        $this->_view->html('emailback');
xuqi authored
27 28 29
        $this->_view->display('email', $data);
    }
Rock Zhang authored
30 31 32
    /**
     * 发送邮箱验证码
     */
33
    public function sendemailAction()
Rock Zhang authored
34
    {
35 36
        $result = array('code' => 400, 'message' => '邮箱格式不正确,请重新输入', 'data' => '');
        do
Rock Zhang authored
37
        {
38 39 40 41 42 43
            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) 
            {
                break;
            }
44
            $email = $this->post('email', '');
45 46 47 48 49
            // 判断邮箱是否有效
            if(!Helpers::verifyEmail($email))
            {
                break;
            }
50 51 52 53 54 55 56 57 58

            // 发送邮箱验证码
            $result = BackData::sendCodeToEmail($email);
            if($result['code'] === 200)
            {
                $result['data'] = '/passport/back/success?email='.$email;
            }

        }
59 60 61
        while (false);

        $this->echoJson($result);
62 63 64 65 66 67 68
    }

    /**
     * 重新发送邮箱验证码
     */
    public function resendemailAction()
    {
69 70
        $result = array('code' => 400, 'message' => '重发邮件失败');
        do
71
        {
72 73 74 75 76
            if(!$this->isAjax())
            {
                break;
            }
Rock Zhang authored
77 78 79
            $email = $this->get('email', '');

            // 发送邮箱验证码
80 81 82 83 84 85
            $return = BackData::sendCodeToEmail($email);

            if(!empty($return))
            {
                $result = $return;
            }
Rock Zhang authored
86 87

        }
88 89 90
        while(false);

        $this->echoJson($result);
Rock Zhang authored
91 92
    }
xuqi authored
93 94
    public function successAction()
    {
95
        $email = $this->get('email', '');
96 97 98 99 100
        // 判断是否允许访问, 不允许则跳转到错误页面
        if (!Helpers::verifyEmail($email)) {
            $this->error();
        }
        
101
        // 获取到邮箱域名
102 103
        list($name, $domain) = explode('@', $email);
        $domain_name = 'http://' . (($domain == 'gmail.com') ? 'mail.google.com' : 'mail.' . $domain);
104
xuqi authored
105
        $data = array(
106
            'backUrl' => '/emailback.html',
xuqi authored
107 108
            'headerText' => '找回密码',
            'isPassportPage' => true,
109
            'backEmailSuccess' => true,
110 111
            'goEmail' => $domain_name,
            'resendUrl' => '/passport/back/resendemail?email='.$email
xuqi authored
112 113
        );
114
        $this->setTitle('找回密码-通过邮箱');
xuqi authored
115 116 117
        $this->_view->display('email-success', $data);
    }
Rock Zhang authored
118 119 120 121 122 123 124
    /**
     * 根据邮箱修改密码
     * 
     * @return array 根据邮箱修改密码的结果
     */
    public function passwordByEmailAction()
    {
125 126
        if($this->isAjax())
        {
127 128
            $pwd = $this->post('password', '');
            $code = $this->post('code', '');
Rock Zhang authored
129
130
            $data = BackData::modifyPasswordByEmail($pwd, $code);
Rock Zhang authored
131
132 133 134 135 136 137 138 139
            $result = array('code'=>200);
            if(strpos($data, 'history.back') !== false)
            {
                $result['code'] = 400;
                $result['message'] = '修改失败';
            }

            $this->echoJson($result);// 前端不需要判断结果
140
        }
Rock Zhang authored
141 142 143
    }

xuqi authored
144 145
    public function mobileAction()
    {
146 147
        $this->setTitle('找回密码-通过手机号');
        
xuqi authored
148
        $data = array(
149
            'backUrl' => '/signin.html',
xuqi authored
150 151
            'headerText' => '找回密码',
            'isPassportPage' => true,
152
            'backMobile' => true,
153
            'countrys' => RegData::getAreasData(),
154
            'areaCode' => '+86'
xuqi authored
155 156
        );
hf authored
157
        // 生成HTML (phoneback.html)
158
        // $this->_view->html('phoneback');
159
        
xuqi authored
160 161 162
        $this->_view->display('mobile', $data);
    }
Rock Zhang authored
163 164 165
    /**
     * 发送手机验证码
     */
166
    public function sendcodeAction()
xuqi authored
167
    {
168 169
        $result = array('code' => 400, 'message' => '手机号码格式不正确,请重新输入', 'data' => '');
        do
Rock Zhang authored
170
        {
171 172 173 174 175
            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) 
            {
                break;
            }
176 177
            $phoneNum = $this->post('phoneNum', '');
            $areaCode = $this->post('areaCode', 86);
Rock Zhang authored
178
179 180 181 182 183
            if(!Helpers::verifyMobile($phoneNum))
            {
                break;
            }
Rock Zhang authored
184
            // 发送手机验证码
185 186 187 188 189 190 191
            $result = BackData::sendCodeToMobile($phoneNum, $areaCode);
            if(empty($result))
            {
                break;
            }
            
            if($result['code'] === 200)
192 193 194
            {
                $result['data'] = '/passport/back/mobilecode?phoneNum='.$phoneNum.'&areaCode='.$areaCode;
            }
Rock Zhang authored
195 196

        }
197 198 199
        while (false);

        $this->echoJson($result);
Rock Zhang authored
200 201
    }
202 203 204
    /**
     * 校验验证码页面
     */
Rock Zhang authored
205 206
    public function mobilecodeAction()
    {
207 208 209
        $phoneNum = $this->get('phoneNum', '');
        $areaCode = $this->get('areaCode', 86);
        $areaCode = '+'.$areaCode;
Rock Zhang authored
210
xuqi authored
211
        $data = array(
212
            'backUrl' => '/phoneback.html',
xuqi authored
213 214
            'headerText' => '找回密码',
            'isPassportPage' => true,
215 216 217
            'backCode' => true,
            'areaCode' => $areaCode,
            'phoneNum' => $phoneNum
xuqi authored
218 219
        );
220
        $this->setTitle('找回密码-通过手机号');
xuqi authored
221 222 223
        $this->_view->display('mobile-code', $data);
    }
Rock Zhang authored
224 225 226
    /**
     * 校验手机验证码
     * 
227
     * @return array 校验手机验证码的结果(token)
Rock Zhang authored
228
     */
229
    public function verifycodeAction()
Rock Zhang authored
230 231 232
    {
        if($this->isAjax())
        {
233
            $phoneNum = $this->post('phoneNum', '');
234
            $code = $this->post('code', '');
235
            $areaCode = $this->post('areaCode', 86);
Rock Zhang authored
236 237

            // 校验手机验证码
238 239 240
            $result = BackData::validateMobileCode($phoneNum, $code, $areaCode);
            if($result['code'] === 200)
            {
241
                $result['data'] = '/passport/back/password?phoneNum='.$phoneNum.'&token='.$result['data']['token'].'&areaCode='.$areaCode;
242
            }
Rock Zhang authored
243
244
            $this->echoJson($result);
Rock Zhang authored
245 246 247
        }
    }
xuqi authored
248 249
    public function passwordAction()
    {
250
        $phoneNum = $this->get('phoneNum', '');
251
        // 手机验证令牌
Rock Zhang authored
252
        $token = $this->get('token', '');
253
        $areaCode = $this->get('areaCode', 86);
254 255 256

        // 邮箱验证码
        $code = $this->get('code', '');
257 258 259 260 261

        // 判断是否允许访问, 不允许则跳转到错误页面
        if ((!$token || !Helpers::verifyMobile($phoneNum)) && !$code) {
            $this->error();
        }
Rock Zhang authored
262
        
xuqi authored
263
        $data = array(
hf authored
264
            'backUrl' => '/signin.html',
xuqi authored
265 266
            'headerText' => '找回密码',
            'isPassportPage' => true,
267
            'backNewPwd' => true,
268
            'phoneNum' => $phoneNum,
269
            'token' => $token,
270
            'areaCode' => $areaCode,
271
            'code' => $code
xuqi authored
272
        );
hf authored
273
274
        $this->setTitle('找回密码-输入新密码');
xuqi authored
275 276
        $this->_view->display('new-password', $data);
    }
Rock Zhang authored
277 278 279 280 281 282 283 284 285 286

    /**
     * 根据手机验证码修改密码
     * 
     * @return array 根据手机验证码修改密码的结果
     */
    public function passwordByMobileAction()
    {
        if($this->isAjax())
        {
287
            $phoneNum = $this->post('phoneNum', '');
288 289
            $token = $this->post('token', '');
            $newpwd = $this->post('password', '');
290
            $areaCode = $this->post('areaCode', 86);
Rock Zhang authored
291 292

            // 根据手机验证码修改密码
293 294 295 296 297
            $result = BackData::modifyPasswordByMobile($phoneNum, $token, $newpwd, $areaCode);
            if($result['code'] === 200)
            {
                $result['data'] = '/';
            }
Rock Zhang authored
298
299
            $this->echoJson($result);
Rock Zhang authored
300 301
        }
    }
xuqi authored
302
}