Exemplo n.º 1
0
function signUp()
{
    $user = isset($_SESSION['user']) ? $_SESSION['user'] : null;
    if ($user) {
        header('Location: /');
        exit;
    }
    $user_phone = isset($_POST['userphone']) ? $_POST['userphone'] : null;
    if ($user_phone) {
        $user_phone = substr($user_phone, 1);
    }
    $yzm = isset($_POST['yzm']) ? (int) $_POST['yzm'] : 0;
    $signintoken = isset($_POST['sigtoken']) ? $_POST['sigtoken'] : null;
    $errormsg = '';
    if ($user_phone && $signintoken && strlen($user_phone) == 11 && Func::checkmobile($user_phone)) {
        $syzm = isset($_SESSION['dxyzm']) ? (int) $_SESSION['dxyzm'] : 0;
        $signin_token = isset($_SESSION['signin_token']) ? $_SESSION['signin_token'] : null;
        if ($yzm && $yzm === $syzm && $signintoken === $signin_token) {
            $enterprise_name = isset($_COOKIE['enterprise_name']) ? $_COOKIE['enterprise_name'] : null;
            if ($enterprise_name && 'null' != $enterprise_name) {
                $data['enterprise_name'] = $enterprise_name;
            }
            $data['identity'] = $identity = isset($_COOKIE['identity']) ? $_COOKIE['identity'] : null;
            $legal_identitys = isset($_COOKIE['legal_identity']) ? $_COOKIE['legal_identity'] : null;
            if ($legal_identitys && 'null' != $legal_identitys) {
                $data['legal_identity'] = $legal_identitys;
            }
            $data['legal_name'] = $legal_name = isset($_COOKIE['legal_name']) ? $_COOKIE['legal_name'] : null;
            $data['type'] = $type = isset($_POST['type']) ? $_POST['type'] : null;
            if (1 == $type) {
                if (!$enterprise_name || !$identity || !$legal_identitys || !$legal_name) {
                    ABase::toJson(1, '注册信息不完整');
                }
            } else {
                if (!$identity || !$legal_name) {
                    ABase::toJson(1, '注册信息不完整');
                }
            }
            $data['email'] = isset($_COOKIE['email']) ? $_COOKIE['email'] : null;
            $data['username_phone'] = $user_phone;
            $userid = Users::signUp($data);
            if ($userid) {
                $rdata['user_id'] = $userid;
                $rdata['module_id'] = 2;
                $rdata['receiver_name'] = $legal_name;
                $rdata['receiver_phone'] = $user_phone;
                $rdata['receiver_province'] = isset($_COOKIE['province']) ? $_COOKIE['province'] : 0;
                $rdata['receiver_city'] = isset($_COOKIE['city']) ? $_COOKIE['city'] : 0;
                $rdata['receiver_county'] = isset($_COOKIE['county']) ? $_COOKIE['county'] : 0;
                $rdata['receiver_address'] = isset($_COOKIE['address']) ? $_COOKIE['address'] : null;
                $rdata['receiver_postcode'] = isset($_COOKIE['postcode']) ? $_COOKIE['postcode'] : null;
                $receiver_address_id = ReceiverAddress::add($rdata);
                $user = Users::getData($userid);
                $utype = isset($user['type']) ? (int) $user['type'] : 0;
                $user_code = isset($user['user_code']) ? $user['user_code'] : '';
                $legal_name = isset($user['legal_name']) ? $user['legal_name'] : '';
                $enterprise_name = isset($user['enterprise_name']) ? $user['enterprise_name'] : '';
                $status = isset($user['status']) ? (int) $user['status'] : 0;
                $_SESSION['user'] = $user_phone;
                $_SESSION['userid'] = $userid;
                $_SESSION['user_code'] = $user_code;
                $_SESSION['usertype'] = $utype;
                $_SESSION['name'] = $utype ? $enterprise_name : $legal_name;
                $_SESSION['userstatus'] = $status;
                if (isset($_SESSION['tmp_user'])) {
                    unset($_SESSION['tmp_user']);
                }
                if (isset($_SESSION['dxyzm'])) {
                    unset($_SESSION['dxyzm']);
                }
                if (isset($_SESSION['signin_token'])) {
                    unset($_SESSION['signin_token']);
                }
                if (isset($_SESSION['signin_num'])) {
                    unset($_SESSION['signin_num']);
                }
                if (isset($_SESSION['dxyzm_send_num'])) {
                    unset($_SESSION['dxyzm_send_num']);
                }
                if ($receiver_address_id) {
                    Users::update($userid, array('receiver_address_id' => $receiver_address_id));
                }
                ABase::toJson(0, 'ok');
            } else {
                ABase::toJson(1, '注册失败,请重试');
            }
        } else {
            ABase::toJson(1, '验证码错误');
        }
    } else {
        $type = isset($_GET['t']) ? (int) $_GET['t'] : 0;
        //0:个人,1:企业
        $step = isset($_GET['s']) ? (int) $_GET['s'] : 1;
        //下一步
        if ($step < 1) {
            $step = 1;
        }
        $tmp_user = isset($_SESSION['tmp_user']) ? $_SESSION['tmp_user'] : '';
        //保存在输入框的临时信息
        $tmp_get_yzm = isset($_SESSION['tmp_get_yzm']) ? (int) $_SESSION['tmp_get_yzm'] : 0;
        //重复点击获取验证码按钮刷新后的自动触发
        if (isset($_SESSION['tmp_get_yzm'])) {
            unset($_SESSION['tmp_get_yzm']);
        }
        $provinces = Countys::getCountys();
        $token = ABase::token();
        $signin_token = $_SESSION['signin_token'] = Func::getRandomCode(30);
        $user = isset($_SESSION['user']) ? $_SESSION['user'] : null;
        Templates::Assign('user', $user);
        Templates::Assign('tmp_user', $tmp_user);
        Templates::Assign('tmp_get_yzm', $tmp_get_yzm);
        Templates::Assign('provinces', $provinces);
        Templates::Assign('type', $type);
        Templates::Assign('step', $step);
        Templates::Assign('token', $token);
        Templates::Assign('signin_token', $signin_token);
        Templates::Assign('errormsg', $errormsg);
        Templates::Display('signup.html');
    }
}
Exemplo n.º 2
0
function dxyzm()
{
    $sessionid = session_id();
    $user_phone = isset($_POST['userphone']) ? $_POST['userphone'] : '';
    $sign = isset($_POST['sign']) ? $_POST['sign'] : 'in';
    $user_phone = substr($user_phone, 1);
    $token = isset($_POST['token']) ? $_POST['token'] : '';
    if (!$user_phone || strlen($user_phone) != 11 || !Func::checkmobile($user_phone)) {
        ABase::toJson(1, '请正确输入手机号码');
    }
    $_SESSION['tmp_user'] = $user_phone;
    if (!$sessionid || !$token || !ABase::token($token)) {
        $_SESSION['tmp_get_yzm'] = 1;
        ABase::toJson(-1, '请求异常或自动刷新');
    }
    $dxyzm_send_num = isset($_SESSION['dxyzm_send_num']) ? (int) $_SESSION['dxyzm_send_num'] : 0;
    if ($dxyzm_send_num > 10) {
        ABase::toJson(1, '您今日发送短信数过多');
    }
    $user = Users::check($user_phone);
    $userid = isset($user['id']) ? (int) $user['id'] : 0;
    $ustatus = isset($user['status']) ? (int) $user['status'] : 0;
    if ('in' === $sign) {
        if (!$userid) {
            ABase::toJson(1, '手机号码未注册');
        }
        if ($ustatus < 0) {
            ABase::toJson(1, '该账号被冻结,详情请致电本公司。');
        }
    } else {
        if ($userid) {
            ABase::toJson(1, '手机号码被占用');
        }
    }
    $_SESSION['dxyzm_send_num'] = $dxyzm_send_num + 1;
    $_SESSION['dxyzm'] = $vcode = rand(100000, 999999);
    $plaintext = $user_phone . '-1001-' . $vcode;
    if (!_DEVDEBUG) {
        $pcontent = ABase::RSASignature($plaintext, _USERMOBSEND);
    } else {
        $pcontent = "1,ok";
        //test
    }
    $pcontent = explode(',', $pcontent);
    $status = isset($pcontent[0]) ? (int) $pcontent[0] : 0;
    $msg = isset($pcontent[1]) ? $pcontent[1] : '';
    if (1 != $status) {
        ABase::toJson(1, $msg);
    } else {
        if (!_DEVDEBUG) {
            ABase::toJson(0, $msg);
        } else {
            ABase::toJson(0, $msg, array($vcode));
            //test
        }
    }
}