Beispiel #1
0
function signup($req)
{
    $username = trim($req['username']);
    $email = trim($req['email']);
    $tel = trim($req['tel']);
    $password = $req['password'];
    $password2 = $req['password2'];
    $response['status'] = 0;
    if (empty($username)) {
        $response['msg'] = "用户名不能为空";
        echo json_encode($response);
        return;
    }
    if (strlen($username) < 2 || strlen($username) > 10) {
        $response['msg'] = "用户名长度需要在2到10位之间";
        echo json_encode($response);
        return;
    }
    if (UserService::verifyUsername($username)) {
        $response['msg'] = "用户名已存在";
        echo json_encode($response);
        return;
    }
    if (empty($email)) {
        $response['msg'] = "邮箱格式不正确";
        echo json_encode($response);
        return;
    }
    if (!UserHelper::emailFormatCheck($email)) {
        $response['msg'] = "邮箱格式不正确";
        echo json_encode($response);
        return;
    }
    if (UserService::verifyEmail($email)) {
        $response['msg'] = "邮箱已被注册";
        echo json_encode($response);
        return;
    }
    if (!empty($tel) && !UserHelper::telFormatCheck($tel)) {
        $response['msg'] = "手机号码格式不对";
        echo json_encode($response);
        return;
    }
    if (UserService::verifyTel($tel)) {
        $response['msg'] = "手机号码已被注册";
        echo json_encode($response);
        return;
    }
    if (empty($password) || empty($password2)) {
        $response['msg'] = "密码不能为空";
        echo json_encode($response);
        return;
    }
    if ($password != $password2) {
        $response['msg'] = "两次输入的密码不一致";
        echo json_encode($response);
        return;
    }
    $user['userid'] = SequenceHelper::getSequence(SEQ_USER);
    $user['username'] = $username;
    $user['email'] = $email;
    $user['tel'] = $tel;
    $user['password'] = $password;
    $user['cdate'] = time();
    $user['udate'] = time();
    $id = UserService::signup($user);
    if ($id <= 0) {
        $response['msg'] = "抱歉,系统错误注册失败";
        echo json_encode($response);
        return;
    }
    $response['status'] = 1;
    setSessionCookie($user);
    echo json_encode($response);
}
Beispiel #2
0
function addPage($req)
{
    $response['status'] = 0;
    $title = $req['title'];
    $imgurl = $req['imgurl'];
    $imgname = $req['imgname'];
    $showindex = $req['showindex'];
    $imgArr = array();
    if (!empty($imgname)) {
        $imgs = explode(";", $imgname);
        foreach ($imgs as $name) {
            if (empty($name)) {
                continue;
            }
            $imgArr[] = $name;
        }
    }
    if (!empty($imgurl)) {
        $urlArr = explode(";", $imgurl);
        foreach ($urlArr as $url) {
            if (empty($url)) {
                continue;
            }
            $newName = uniqid() . ".jpg";
            $tarFilePath = MIMGPATH . $newName;
            DownLoader::download($url, $tarFilePath);
            $imgArr[] = $newName;
        }
    }
    if (count($imgArr) == 0) {
        $response['msg'] = "图片不能为空";
        echo json_encode($response);
        return;
    }
    $page = [];
    $page['pageid'] = SequenceHelper::getSequence("SEQ_PAGE");
    $page['title'] = $title;
    $page['cover'] = $imgArr[0];
    $page['imgnum'] = count($imgArr);
    $page['status'] = 20;
    $page['cuserid'] = 6;
    $page['cusername'] = "******";
    $t = time() * 1000;
    $page['cdate'] = $t;
    $page['udate'] = $t;
    $page['showindex'] = $showindex;
    ReviewService::addPage($page, $imgArr);
    $response['status'] = 1;
    echo json_encode($response);
}