Blame view

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

            // 发送邮箱验证码
            $result = BackData::sendCodeToEmail($email);
53 54 55 56
            if ($result['code'] === 200) {
                $result['data'] = Helpers::url('/passport/back/resendemail', array(
                    'email' => $email,
                ));
57
            }
58
        } while (false);
59 60

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

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

            // 发送邮箱验证码
77 78
            $return = BackData::sendCodeToEmail($email);
79
            if (!empty($return)) {
80 81
                $result = $return;
            }
82
        } while (false);
83 84

        $this->echoJson($result);
Rock Zhang authored
85 86
    }
87 88 89
    /**
     * 邮箱找回密码-成功
     */
xuqi authored
90 91
    public function successAction()
    {
92
        $email = $this->get('email', '');
93 94 95 96
        // 判断是否允许访问, 不允许则跳转到错误页面
        if (!Helpers::verifyEmail($email)) {
            $this->error();
        }
97
98
        // 获取到邮箱域名
99 100
        list($name, $domain) = explode('@', $email);
        $domain_name = 'http://' . (($domain == 'gmail.com') ? 'mail.google.com' : 'mail.' . $domain);
101
xuqi authored
102
        $data = array(
103
            'backUrl' => Helpers::url('/emailback.html'),
xuqi authored
104 105
            'headerText' => '找回密码',
            'isPassportPage' => true,
106
            'backEmailSuccess' => true,
107
            'goEmail' => $domain_name,
108 109 110
            'resendUrl' => Helpers::url('/passport/back/resendemail', array(
                'email' => $email,
            )),
xuqi authored
111 112
        );
113
        $this->setTitle('找回密码-通过邮箱');
xuqi authored
114 115 116
        $this->_view->display('email-success', $data);
    }
Rock Zhang authored
117 118 119 120 121 122 123
    /**
     * 根据邮箱修改密码
     * 
     * @return array 根据邮箱修改密码的结果
     */
    public function passwordByEmailAction()
    {
124
        if ($this->isAjax()) {
125 126
            $pwd = $this->post('password', '');
            $code = $this->post('code', '');
Rock Zhang authored
127
128
            $data = BackData::modifyPasswordByEmail($pwd, $code);
Rock Zhang authored
129
130 131
            $result = array('code' => 200, 'data' => Helpers::url('/signin.html') );
            if (strpos($data, 'history.back') !== false) {
132 133 134 135
                $result['code'] = 400;
                $result['message'] = '修改失败';
            }
136
            $this->echoJson($result); // 前端不需要判断结果
137
        }
Rock Zhang authored
138 139
    }
xuqi authored
140 141
    public function mobileAction()
    {
142
        $this->setTitle('找回密码-通过手机号');
143
xuqi authored
144
        $data = array(
145
            'backUrl' => Helpers::url('/signin.html'),
xuqi authored
146 147
            'headerText' => '找回密码',
            'isPassportPage' => true,
148
            'backMobile' => true,
149
            'countrys' => RegData::getAreasData(),
150
            'areaCode' => '+86'
xuqi authored
151 152
        );
hf authored
153
        // 生成HTML (phoneback.html)
154
        // $this->_view->html('phoneback');
155
xuqi authored
156 157 158
        $this->_view->display('mobile', $data);
    }
Rock Zhang authored
159 160 161
    /**
     * 发送手机验证码
     */
162
    public function sendcodeAction()
xuqi authored
163
    {
xuqi authored
164
        $result = array('code' => 400, 'message' => '密码只能使用数字、字母和半角标点符号,请重新输入', 'data' => '');
165
        do {
166
            /* 判断是不是AJAX请求 */
167
            if (!$this->isAjax()) {
168 169
                break;
            }
170 171
            $phoneNum = $this->post('phoneNum', '');
            $areaCode = $this->post('areaCode', 86);
Rock Zhang authored
172
173
            if (!Helpers::verifyMobile($phoneNum)) {
174 175 176
                break;
            }
Rock Zhang authored
177
            // 发送手机验证码
178
            $result = BackData::sendCodeToMobile($phoneNum, $areaCode);
179
            if (empty($result)) {
180 181
                break;
            }
Rock Zhang authored
182
183 184 185 186 187 188 189
            if ($result['code'] === 200) {
                $result['data'] = Helpers::url('/passport/back/mobilecode', array(
                    'phoneNum' => $phoneNum,
                    'areaCode' => $areaCode,
                ));
            }
        } while (false);
190 191

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

            // 校验手机验证码
229
            $result = BackData::validateMobileCode($phoneNum, $code, $areaCode);
230 231 232 233 234 235
            if ($result['code'] === 200) {
                $result['data'] = Helpers::url('/passport/back/backcode', array(
                    'phoneNum' => $phoneNum,
                    'token' => $result['data']['token'],
                    'areaCode' => $areaCode,
                ));
236
            }
Rock Zhang authored
237
238
            $this->echoJson($result);
Rock Zhang authored
239 240 241
        }
    }
242 243 244
    /**
     * 找回密码
     */
245
    public function backcodeAction()
xuqi authored
246
    {
247
        $phoneNum = $this->get('phoneNum', '');
248
        // 手机验证令牌
Rock Zhang authored
249
        $token = $this->get('token', '');
250
        $areaCode = $this->get('areaCode', 86);
251 252 253

        // 邮箱验证码
        $code = $this->get('code', '');
254 255 256 257 258

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

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

            // 根据手机验证码修改密码
289
            $result = BackData::modifyPasswordByMobile($phoneNum, $token, $newpwd, $areaCode);
290 291
            if ($result['code'] === 200) {
                $result['data'] = Helpers::url('/signin.html');
292
            }
Rock Zhang authored
293
294
            $this->echoJson($result);
Rock Zhang authored
295 296
        }
    }
297 298

}