public function enableAllGrants() { if (!$this->authorize) { $this->initAuthorizationServer(); } foreach ($this->grants as $type => $grantName) { $type = new $grantName(); $this->authorize->addGrantType($type); if ($type instanceof \League\OAuth2\Server\Grant\PasswordGrant) { $type->setVerifyCredentialsCallback(function ($username, $password) { //$user = \Users::findFirstByUsername($username); if (!isset($_POST['targetdb'])) { $user = \Users::findFirstByUsername($username); if ($user && $this->security->checkHash($password, $user->password)) { return $user->username; } } else { switch ($_POST['targetdb']) { case "NiuGame": $user = \NiuUsrInfo::findFirstById($username); $this->totp->setSecret($user->gasecret); $this->totp->setWindow(31); //31(sec) == (15s forward and backward) if ($user && $this->totp->validate($password)) { return $user->id; } break; } } return false; }); } } }
$inputs = $app->sfunc->getContentTypeFromPost(); //make sure what gifts are we going to receive by id if (!isset($inputs["targets"])) { $app->sfunc->badRequest400($app, "targetMissing"); } $targets = $app->sfunc->convertStringToIntArray($inputs["targets"]); try { // Check that an access token is present and is valid $app->oauth->resource->isValidRequest(); //get and check the user id by AccessToken $app->sfunc->isValidUUID($app, $uuid); $thisTime = "'" . $app->sfunc->getGMT() . "'"; // use ' to quote the time string $outputString = ""; $outputString2 = ""; $thsUser = NiuUsrInfo::findFirst("id = " . $uuid); foreach ($targets as $val) { //GiftBox::findFirst("id = " . $val . " AND targetid = " . $uuid. " AND expired_at > " . $thisTime); $gBoxEntry = GiftBox::findFirst(array("conditions" => "id = {$val} AND targetid = {$uuid} AND expired_at > {$thisTime}")); if (!$gBoxEntry) { $outputString2 = $outputString2 . "," . $val; continue; } $giftContent = $app->sfunc->convertStringToIntArray($gBoxEntry->json); //now we get int[,] //if giftContent[0] is not array //$giftContent[0] is the type based on public enum NiuPurchaseType, //$giftContent[1] is the index of the item, used in cashcard/ eq //$giftContent[2] is the amount in general, used in diamond/ cash //if giftContent[0] is array //$giftContent[0][$i] is the type based on public enum NiuPurchaseType,
<?php $app->get('/', function () use($app) { $app->response->setContentType('application/json', 'UTF-8'); /* if(!$app->oauthredis->exists(':AuthCode:51')) $app->oauthredis->save(':AuthCode:51', 'gsdfdsasdsdfewrewfddsfsd'); $data = $app->oauthredis->get(':AuthCode:51'); */ $apiserverTime = date("Y-m-d H:i:s"); $modelAtNiuServer = new NiuUsrInfo(); $modelAtOauthServer = new ChatLogs(); echo json_encode(array('status' => 200, 'NiuServer' => NiuUsrInfo::findFirst()->id, 'OauthServer' => ChatLogs::findFirst()->id, 'message' => 'welcome!歡迎!', 'apiserverTime' => $apiserverTime, 'dbServerTime' => $modelAtNiuServer->getServerTime(), 'authServerTime' => $modelAtOauthServer->getServerTime()), JSON_UNESCAPED_UNICODE); }); /* //stay for debug purpose $app->get('/backdoor/{uuid:[0-9]+}', function($uuid) use($app) { $user = NiuUsrInfo::findFirst("id = $uuid"); if(!$user) $app->sfunc->forbidden403($app); try { $app->totp->setSecret($user->gasecret); $totp = $app->totp->calculate(); // stay for debug echo ($totp); } catch (\Exception $e) { var_dump($e); $app->oauth->catcher($e); }