Пример #1
0
    return __param($_POST, $name, $default);
}
function __param($array, $name, $default)
{
    $res = $default;
    if (isset($array[$name])) {
        $res = $array[$name];
    }
    return $res;
}
try {
    if ($code = getParam("code")) {
        if (getParam("final", false)) {
            $res = TAuthCommand::getAccessTokenByCode($code);
            debug("OAuth token from service:", $res);
            $token = OAuth2::fromArray($res);
            debug($token);
            $user_array = TAuthCommand::getUserProfileByToken($token->getAccessToken());
            debug($user_array);
            if (TRUSTED_DB) {
                $user = TDataBaseUser::getUserById($user_array['id']);
                debug("TDataBaseUser::getUserById:", $user);
                if ($user) {
                    //Пользователь уже зарегистрирован
                    debug('Old user');
                    if (onRegUserFound) {
                        debug('Event onRegUserFound');
                        onRegUserFound($user);
                    }
                } else {
                    //Пользователь не найден