Back.php 5.86 KB
<?php

use Action\AbstractAction;
use LibModels\Wap\Passport\BackData;
use Hood\Core\Security\AuthCode;
/**
 * 频道选择
 */
class BackController extends AbstractAction
{
    public function indexAction()
    {
        echo '密码找回';
    }

    public function emailAction()
    {
        $data = array(
            'backUrl' => 'm.yohobuy.com',
            'headerText' => '找回密码',
            'isPassportPage' => true,
            'modulePath' => 'passport/back/email'
        );

        $this->_view->assign('title', 'YOHO!有货');
        $this->_view->display('email', $data);
    }

    /**
     * 发送邮箱验证码
     */
    public function sendemailAction()
    {
        if($this->isAjax())
        {
            $email = $this->get('email', '');

            // 发送邮箱验证码
            $result = BackData::sendCodeToEmail($email);
            $result['data'] = '/passport/back/success';

            $this->echoJson($result);
        }
    }

    public function successAction()
    {
        $data = array(
            'backUrl' => 'm.yohobuy.com',
            'headerText' => '找回密码',
            'isPassportPage' => true,
            'modulePath' => 'passport/back/email-success',
            'goEmail' => '',
            'resendUrl' => ''
        );

        $this->_view->assign('title', 'YOHO!有货');
        $this->_view->display('email-success', $data);
    }

    /**
     * 根据邮箱修改密码
     * 
     * @return array 根据邮箱修改密码的结果
     */
    public function passwordByEmailAction()
    {
        if($this->isAjax())
        {
            $pwd = $this->get('pwd', '');
            $code = $this->get('code', '');

            $data = BackData::modifyPasswordByEmail($pwd, $code);

            $this->returnJson(200, '成功', '');// 前端不需要判断结果
        }
    }


    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' => $areas,
            'countryCode' => '+86'
        );

        $this->_view->assign('title', 'YOHO!有货');
        $this->_view->display('mobile', $data);
    }

    /**
     * 发送手机验证码
     */
    public function mobilecodeSendAction()
    {
        if($this->isAjax())
        {
            $mobile = $this->get('mobile', '');
            $area = $this->get('area', 86);

            // 发送手机验证码
            $result = BackData::sendCodeToMobile($mobile, $area);

            $this->returnJson($result['code'], $result['message'], $result['data']);
        }
    }

    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' => $mobile
        );

        $this->_view->assign('title', 'YOHO!有货');
        $this->_view->display('mobile-code', $data);
    }

    /**
     * 校验手机验证码
     * 
     * @return array 校验手机验证码的结果(token)
     */
    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->returnJson($result['code'], $result['message'], $result['data']);
        }
    }

    public function passwordAction()
    {
        $mobile = $this->get('mobile', '');
        $token = $this->get('token', '');
        $area = $this->get('area', 86);
        
        $data = array(
            'backUrl' => 'm.yohobuy.com',
            'headerText' => '找回密码',
            'isPassportPage' => true,
            'modulePath' => 'passport/back/new-password',
            'pageHeader' => array(
                'navBack' => 'm.yohobuy.com',
                'navHome' => 'm.yohobuy.com',
                'navTitle' => '上衣'
            ),
            'pageFooter' => array(
                'loginUrl' => 'm.yohobuy.com/login.html',
                'signupUrl' => 'm.yohobuy.com/signup.html'
            )
        );

        $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->returnJson($result['code'], $result['message'], $result['data']);
        }
    }
}