unset($account);
    if ($result['error'] === false) {
        $account = new account($dbo);
        $account->setState(ACCOUNT_STATE_ENABLED);
        $account->setLastActive();
        $result = $account->signin($username, $password);
        unset($account);
        if ($result['error'] === false) {
            $auth = new auth($dbo);
            $result = $auth->create($result['accountId'], $clientId);
            if ($result['error'] === false) {
                $account = new account($dbo, $result['accountId']);
                if (strlen($facebookId) != 0) {
                    $helper = new helper($dbo);
                    if ($helper->getUserIdByFacebook($facebookId) == 0) {
                        $account->setFacebookId($facebookId);
                    }
                } else {
                    $account->setFacebookId("");
                }
                if (strlen($gcm_regId) != 0) {
                    $account->setGCM_regId($gcm_regId);
                }
                $result['account'] = array();
                array_push($result['account'], $account->get());
            }
        }
    }
    echo json_encode($result);
    exit;
}
<?php

/*!
 * ifsoft.co.uk engine v1.0
 *
 * http://ifsoft.com.ua, http://ifsoft.co.uk
 * qascript@ifsoft.co.uk
 *
 * Copyright 2012-2015 Demyanchuk Dmitry (https://vk.com/dmitry.demyanchuk)
 */
include_once $_SERVER['DOCUMENT_ROOT'] . "/core/init.inc.php";
include_once $_SERVER['DOCUMENT_ROOT'] . "/config/api.inc.php";
if (!empty($_POST)) {
    $accountId = isset($_POST['accountId']) ? $_POST['accountId'] : 0;
    $accessToken = isset($_POST['accessToken']) ? $_POST['accessToken'] : '';
    $gcm_regId = isset($_POST['gcm_regId']) ? $_POST['gcm_regId'] : '';
    $gcm_regId = helper::clearText($gcm_regId);
    $gcm_regId = helper::escapeText($gcm_regId);
    $result = array("error" => true, "error_code" => ERROR_UNKNOWN);
    $auth = new auth($dbo);
    if (!$auth->authorize($accountId, $accessToken)) {
        api::printError(ERROR_ACCESS_TOKEN, "Error authorization.");
    }
    $account = new account($dbo, $accountId);
    $result = $account->setGCM_regId($gcm_regId);
    echo json_encode($result);
    exit;
}