Skip to content
You have no unread notifications
funige  /   neo  /   Pull requests #107  /  
Open in github.dev Open in a new github.dev tab Open in codespace
Code

画面移動の関数が定義されている時はユーザーが定義した関数で画面移動 #107

Merged
merged 1 commit into from Feb 19, 2024

Conversation

satopian

Collaborator

これまでPaintBBSは、url_exitで指定されたURLに画面を移動する事で処理を完了していました。
そのURLは

<param name="url_exit" value="./">

で指定していました。
そしてパスワードを掲示板やCMSの本体に送信するにはこの"url_exit"に、

/?password=password

のようにパスワードを記述してGETで渡すケースがほとんどでした。
これを回避するにはいろいろな方法があると思いますが、このGETの処理をPOSTに変更できれば、より安全性は高まります。
しかしながら、この処理は掲示板やCMSによって異なる場合があります。
そこで、掲示板やCMS側でそれぞれの条件にあうように自由にJavaScriptを書いてもらいます。
自由に書いてもらうといっても、例が必要なので以下に示します。

Neo.handleExit = () => {
    <?php if($rep): ?>
    const formData = new FormData();
    formData.append("pwd", "パスワード"); 

    fetch("./", {
        method: 'POST',
        mode: 'same-origin',
        body: formData
    })
    .then(response => {
        if (response.redirected) {
            //レスポンスのリダイレクトを検出して移動
            return window.location.href = response.url;
        } else {
            console.error('There was an error with the fetch operation:', response);
            throw new Error('Fetch operation failed');
        }
    })
    .catch(error => {
        console.error('There was a problem with the fetch operation:', error);
    });
    <?php else: ?>
    return window.location.href = "./";
    <?php endif; ?>
}

従来の動作のままNEOを使いたい人は、この関数を単に書かなればそのまま使えます。

Neo.handleExitが関数かどうか調べて、関数が定義されている時にだけ、掲示板やCMSの開発者が定義した関数による、追加の処理と画面移動が行われます。
関数が定義されていない時は従来通り

<param name="url_exit" value="./">

で設定したURLに移動します。

neo.jsそのものには、追加の処理は入らないようにしているため、neo.jsの変更箇所はごくわずかです。

@satopian satopian merged commit 3458f6d into funige:master Feb 19, 2024

Update branch attempt failed

Oops, something went wrong.

@funige

Add a comment

Select a reply

Slash commands
Beta
Give feedback
Slash commands
Beta
Give feedback

An unexpected error has occurred

Remember, contributions to this repository should follow our GitHub Community Guidelines.
ProTip! Add comments to specific lines under Files changed.
Labels
Apply labels to this pull request
None yet
Projects
Projects
None yet
Development
Link an issue from this repository

Successfully merging this pull request may close these issues.

None yet

1 participant
Lock conversation

Lock conversation on this pull request

  • Other users can’t add new comments to this pull request.
  • You and other collaborators with access to this repository can still leave comments that others can see.
  • You can always unlock this pull request again in the future.

Optionally, choose a reason for locking that others can see. Learn more about when it’s appropriate to lock conversations.

画面移動の関数が定義されている時はユーザーが定義した関数で画面移動 by satopian · Pull Request #107 · funige/neo