Migaro. 技術Tips

                       

ミガロ. 製品の技術情報
IBMiの活用に役立つ情報を掲載!


Cobos4i(SP4i) ログオン時のエラーメッセージ変更方法

以前、Cobos4i(SP4i)のエラーメッセージの変更方法についてご紹介をしました。
今回のTipsでは、SmartPad4iのログオン処理時のエラーメッセージを変更する方法をご紹介いたします。
Cobos4iとSmartPad4iで設定方法が異なりますのでご注意ください。

Cobos4i ログオン時のエラーメッセージの変更

Cobos4iのログオン時のエラーメッセージは[HTTPDocumentRoot]/cobos4i/exec/sp4imsg.js に定義されています。

	//const - logon
	MSG_Userid = "\u30e6\u30fc\u30b6\u30fcID\u304c\u5fc5\u8981\u3067\u3059",
	MSG_Passwd = "\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u5fc5\u8981\u3067\u3059",
	MSG_Errpwd = "\u30d1\u30b9\u30ef\u30fc\u30c9\u306f\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002",
	MSG_Libapp = 'Program library required.',
	MSG_Pgmapp = 'Program to start required.',
	MSG_Libenv = 'Environment library required.',
	MSG_Pgmenv = 'Environment program required.',
	MSG_User_Not_Found = "\u30e6\u30fc\u30b6\u30fc\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093",
	MSG_User_Disabled = '\u30E6\u30FC\u30B6\u30FC\u304C\u7121\u52B9\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u3002',
	MSG_Password_Expired = 'Expired password.',

Cobos4iではエラーメッセージが簡単に変更できるようになっています。
前回ご紹介した、以下の記事のように設定することでエラーメッセージを変更することができます。

・SmartPad4i エラーメッセージや表示値を変更する方法
https://www.migaro.co.jp/tips/3669/

SmartPad4i ログオン時のエラーメッセージの変更

SmartPad4iのログオン時のエラーメッセージは[HTTPDocumentRoot]/smartpad4i/exec/ErrRes.txt で定義されています。

CPF2203="User profile not correct."
CPF2204="User profile not found."
CPF22C0="Password does not meet password rules."
CPF22C1="NEWOWN and USRPRF parameters cannot be the same."
CPF22C2="Password less than 6 characters."
CPF22C3="Password longer than 10 characters."
CPF22C4="Password matches one of &1 previous passwords."
CPF22C5="Password contains one of the following: &1."
CPF22C6="Password contains two numbers next to each other."
CPF22C7="Password contains a character used more than once."
CPF22C8="Same character in same position as previous password."
CPF22C9="Password must contain a number."
CPF22CA="Not allowed to change this user profile."
CPF22E2="Password not correct for this user profile."
CPF22E3="This user profile is disabled."
CPF22E4="Password for this user profile has expired."
CPF22E5="No password associated with this user profile."

SmartPad4iでは、IBMiのエラーメッセージ毎にメッセージが定義されています。
IBMi V7R5以降では、ユーザープロファイルとパスワードの両方が入力された場合に認証失敗になると、CPF2204のかわりにCPF22E2が返却されます。また、ユーザープロファイルまたはパスワードのどちらかが未入力の状態で認証処理が実行された場合にはCPF2203が返却されます。
そのため、V7R5以降ではエラーメッセージを変更する場合にはCPF2203、CPF22E2を変更します。
 ※IBMi環境に合わせてCPF2204も変更ください。

メッセージに日本語を設定する場合には、エラーメッセージをUTF-8でエンコードしてください。
また、ログオン時に使用されるJavaScriptファイル [HTTPDocumentRoot]/cobos4i/exec/sp4ilogon.min.js をカスタマイズする必要があります。

SmartPad4i メッセージの変更

エラーメッセージはUTF-8でエンコードした文字列を設定する必要があります。
例えば、「ユーザーまたはパスワードに誤りがあります。」は以下のような文字列になります。

%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E3%81%BE%E3%81%9F%E3%81%AF%E3%83%91%E3%82%B9%E3%83%AF%E3%83%BC%E3%83%89%E3%81%AB%E8%AA%A4%E3%82%8A%E3%81%8C%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%E3%80%82

CPF2203="%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E3%81%BE%E3%81%9F%E3%81%AF%E3%83%91%E3%82%B9%E3%83%AF%E3%83%BC%E3%83%89%E3%81%AB%E8%AA%A4%E3%82%8A%E3%81%8C%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%E3%80%82"
CPF2204="User profile not found."
CPF22C0="Password does not meet password rules."
CPF22C1="NEWOWN and USRPRF parameters cannot be the same."
CPF22C2="Password less than 6 characters."
CPF22C3="Password longer than 10 characters."
CPF22C4="Password matches one of &1 previous passwords."
CPF22C5="Password contains one of the following: &1."
CPF22C6="Password contains two numbers next to each other."
CPF22C7="Password contains a character used more than once."
CPF22C8="Same character in same position as previous password."
CPF22C9="Password must contain a number."
CPF22CA="Not allowed to change this user profile."
CPF22E2="%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E3%81%BE%E3%81%9F%E3%81%AF%E3%83%91%E3%82%B9%E3%83%AF%E3%83%BC%E3%83%89%E3%81%AB%E8%AA%A4%E3%82%8A%E3%81%8C%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%E3%80%82"
CPF22E3="This user profile is disabled."
CPF22E4="Password for this user profile has expired."
CPF22E5="No password associated with this user profile."

このテキストファイルはSmartPad4i起動時に読み込まれる設定のため、編集後にアプリケーションの再起動が必要となります。

SmartPad4i sp4ilogon.min.jsのカスタマイズ

sp4ilogon.min.jsのカスタマイズは以下のように文字列をデコードして表示するように変更します。

        setFocus = function() {
            var e = self.USERID.value.length > 0 ? self.PASSWD : self.USERID;
            if (window.MSG_PASSWD) {
                var t = decodeURIComponent(MSG_PASSWD);
                switch (MSG_PASSWD = void 0, alert(t.substr(7)), t.substr(0, 7)) {
                    case "CPF2203":
                    case "CPF2204":
                    case "CPF22E3":
                        e = self.USERID
                }
            }
            self.USERID.readOnly && (e = self.PASSWD), e.focus(), e.select()
        },

ログオン時のエラーメッセージが変更できました。