$DevAAC->flashNow('password_class', 'has-error'); $DevAAC->flashNow('danger', 'Password must have 6-20 characters.'); $error = true; } // VALIDATE EMAIL ONLY IF THE ACCOUNT DOES NOT EXIST if (!filter_var($req->post('email'), FILTER_VALIDATE_EMAIL)) { $DevAAC->flashNow('email_class', 'has-error'); $DevAAC->flashNow('danger', 'Enter valid email address'); $error = true; } // IF VALIDATION ERROR, EXIT if ($error) { goto render; } // IF ACCOUNT DOES NOT EXIST, CREATE IT NOW $account = DevAAC\Models\Account::create(array('name' => $req->post('account-name'), 'password' => $req->post('password'), 'email' => $req->post('email'), 'creation' => time())); createcharacter: $player = new DevAAC\Models\Player(); $player->account()->associate($account); $player->name = $name; $player->vocation = $req->post('vocation'); $player->sex = $req->post('sex'); $player->town_id = 1; $player->level = 8; $player->push(); // SAVE PLAYER AND ASSOCIATED OBJECTS (ACCOUNT IN THIS CASE) $DevAAC->flashNow('success', 'Player ' . ucwords(strtolower($req->post('character-name'))) . ' has been created!'); } render: $DevAAC->render('simple.php', $data); })->via('GET', 'POST');
* nickname="createAccount", * @SWG\Parameter( name="account", * description="Account object", * paramType="body", * required=true, * type="Account"), * @SWG\ResponseMessage(code=400, message="Input parameter error") * ) * ) * ) */ $DevAAC->post(ROUTES_API_PREFIX . '/accounts', function () use($DevAAC) { $req = $DevAAC->request; if (!filter_var($req->getAPIParam('name'), FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^[a-zA-Z0-9]{2,12}\$/")))) { throw new InputErrorException('Account name must have 2-12 characters.', 400); } if (!filter_var($req->getAPIParam('password'), FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^(.{2,20}|.{40})\$/")))) { throw new InputErrorException('Password must have 2-20 characters or be an SHA-1 hash (40 hexadecimal characters).', 400); } if (!filter_var($req->getAPIParam('email'), FILTER_VALIDATE_EMAIL) or !getmxrr(explode('@', $req->getAPIParam('email'))[1], $trash_)) { throw new InputErrorException('Email address is not valid.', 400); } $account = Account::where('name', $req->getAPIParam('name'))->first(); if ($account) { throw new InputErrorException('Account with this name already exists.', 400); } $account = DevAAC\Models\Account::create(array('name' => $req->getAPIParam('name'), 'password' => $req->getAPIParam('password'), 'email' => $req->getAPIParam('email'), 'creation' => new \DateTime())); $account->save(); $DevAAC->response->setBody($account->toJson(JSON_PRETTY_PRINT)); $DevAAC->response->headers->set('Content-Type', 'application/json'); });