<?php require '../../lib/Config.php'; Config::init(); Util::setErrorCallback('Util::ClientErrorCallback'); $app = new ServerApp(); if ($app->checkRequestValid($_SERVER, $_POST) === false) { Util::error('request invalid'); } if (isset($_POST['account']) === false) { Util::error('`account` is required'); } if (isset($_POST['password']) === false) { Util::error('`password` is required'); } $account = $_POST['account']; $password = $_POST['password']; // check account if (preg_match('/^[a-zA-Z]\\w{5,19}$/', $account) !== 1 && preg_match('/^[0-9]{11,}$/', $account) !== 1) { Util::error('`account` is invalid'); } // check password if (preg_match('/^[0-9a-f]{40}$/', $password) !== 1) { Util::error('`password` is invalid'); } $account_service = $app->getAccountService(); $auth_service = $app->getAuthService(); $account_info = $account_service->getAccountInfo($account, $password); if ($account_info === false) { Util::error('`account` or `password` is invalid', ErrorCode::ACCOUNT_OR_PASSWORD_INVALID); }
require '../../lib/Config.php'; Config::init(); Util::setErrorCallback('Util::ClientErrorCallback'); if (isset($_POST['mobile_phone']) === false) { Util::error('`mobile_phone` is required'); } if (isset($_POST['captcha_text']) === false) { Util::error('`captcha_text` is required'); } $mobile_phone = $_POST['mobile_phone']; $captcha_text = $_POST['captcha_text']; // check mobile phone if (preg_match('/^[0-9]{11,}$/', $mobile_phone) !== 1) { Util::error('`mobile_phone` is invalid'); } $app = new ServerApp(); $auth_service = $app->getAuthService(); $mobile_service = $app->getMobileService(); $account_service = $app->getAccountService(); // check captcha text if ($auth_service->checkAndClearCaptchaText($captcha_text) === false) { Util::error('`captcha_text` is invalid', ErrorCode::CAPTCHA_TEXT_INVALID); } // check phone account $account_info = $account_service->getAccountInfoByPhone($mobile_phone); if ($account_info === false) { Util::error('`mobile_phone` is invalid', ErrorCode::NOT_BIND_MOBILE_PHONE); } $uid = $account_info['uid']; // send mobile message code $message_code = $auth_service->generateResetPasswordCode($uid);
<?php require '../../lib/Config.php'; Config::init(); Util::setErrorCallback('Util::ClientErrorCallback'); if (isset($_POST['mobile_phone']) === false) { Util::error('`mobile_phone` is required'); } if (isset($_POST['captcha_text']) === false) { Util::error('`captcha_text` is required'); } $mobile_phone = $_POST['mobile_phone']; $captcha_text = $_POST['captcha_text']; // check mobile phone if (preg_match('/^[0-9]{11,}$/', $mobile_phone) !== 1) { Util::error('`mobile_phone` is invalid'); } $app = new ServerApp(); $auth_service = $app->getAuthService(); $mobile_service = $app->getMobileService(); // check captcha text if ($auth_service->checkAndClearCaptchaText($captcha_text) === false) { Util::error('`captcha_text` is invalid', ErrorCode::CAPTCHA_TEXT_INVALID); } // send mobile message code $message_code = $auth_service->generateMessageCode($mobile_phone); $mobile_service->sendMessageCode($mobile_phone, $message_code); Util::response(array('result' => array('error_code' => 0)));
#!/usr/bin/env php <?php if (PHP_SAPI !== 'cli') { exit(1); } if ($argc <= 1) { echo 'usage: ' . basename($argv[0]) . " <account>\n"; exit(1); } $account = $argv[1]; require '../../lib/Config.php'; Config::init(); $app = new ServerApp(); $server_config = $app->getServerConfig(); require 'TestConfig.php'; $ret = Util::signedHttpRequest(TestConfig::$base_url, TestConfig::$secret_key, '/v2/login.php', array('account' => $account, 'password' => sha1('1')), 'post'); var_dump($ret); $ret = json_decode($ret, true); if ($ret === null) { exit(0); } var_dump(Util::signedHttpRequest(TestConfig::$base_url, TestConfig::$secret_key, '/v2/check_login.php', array('uid' => $ret['result']['uid'], 'token' => $ret['result']['token'])));
<?php require '../../lib/Config.php'; Config::init(); if (isset($_GET['uid']) === false) { Util::error('`uid` is required'); } if (isset($_GET['token']) === false) { Util::error('`token` is required'); } $uid = $_GET['uid']; $token = $_GET['token']; // check account if (preg_match('/^\\d{9,}$/', $uid) !== 1) { Util::error('`uid` is invalid'); } if (preg_match('/^[0-9a-f]{32}$/', $token) !== 1) { Util::error('`token` is invalid'); } $app = new ServerApp(); $auth_service = $app->getAuthService(); if ($auth_service->checkLoginToken($uid, $token) === false) { Util::error('`token` is invalid'); } Util::response(array('error_code' => 0));