Пример #1
0
 }
 // VALIDATE VOCATION
 if (!in_array($req->post('vocation'), array(1, 2, 3, 4))) {
     $DevAAC->flashNow('vocation_class', 'has-error');
     $error = true;
 }
 // VALIDATE SEX
 if (!in_array($req->post('sex'), array(0, 1))) {
     $DevAAC->flashNow('sex_class', 'has-error');
     $error = true;
 }
 // IF VALIDATION ERROR, EXIT
 if ($error) {
     goto render;
 }
 $account = Account::where('name', $req->post('account-name'))->first();
 // IF ACCOUNT EXISTS AND PASSWORD IS WRONG, EXIT
 if ($account && !$account->comparePassword($req->post('password'))) {
     $DevAAC->flashNow('danger', 'This account already exists and password is not correct. Cannot add a character.
                               Enter correct password or try a different account name.');
     $DevAAC->flashNow('password_class', 'has-error');
     goto render;
 }
 $name = ucwords(strtolower($req->post('character-name')));
 // check if character name is available
 $player = Player::where('name', $name)->first();
 if ($player) {
     $DevAAC->flashNow('danger', 'This character already exists.');
     $DevAAC->flashNow('character-name_class', 'has-error');
     goto render;
 }
Пример #2
0
 *      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');
});