From 9c06dccf65aaca30d09f7f7128698296631f9075 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Sat, 12 Aug 2023 15:37:18 +0900 Subject: [PATCH 1/9] =?UTF-8?q?[add]=20-=20=E3=83=A6=E3=83=BC=E3=82=B6?= =?UTF-8?q?=E3=83=BC=E7=99=BB=E9=8C=B2=E6=99=82=E3=81=AEID=E3=81=8B?= =?UTF-8?q?=E3=81=B6=E3=82=8A=E5=88=A4=E5=AE=9A=E3=81=A8=E5=90=8D=E5=89=8D?= =?UTF-8?q?=E3=81=8B=E3=81=B6=E3=82=8A=E5=88=A4=E5=AE=9A=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auth.js | 91 +++++++++++++++++++++++++++++++++++++------------------- index.js | 6 ++-- 2 files changed, 63 insertions(+), 34 deletions(-) diff --git a/auth.js b/auth.js index e3adc66..bfee6c2 100644 --- a/auth.js +++ b/auth.js @@ -173,7 +173,7 @@ let registerUser = async function registerUser(dat) { //dat=[0=>name(名前), 1= //招待コードが一致しているかどうか if ( db.dataServer.registration.invite.inviteCode !== dat[1] ) { console.log("auth :: registerUser : 招待コード違うわ"); - return {key:-1, userid:-1}; + return {result: "WRONG_CODE", key:-1, userid:-1}; } console.log("auth :: registerUser : 招待コード合ってる!"); @@ -182,43 +182,72 @@ let registerUser = async function registerUser(dat) { //dat=[0=>name(名前), 1= //ID格納用 let newID = ""; - //ID生成 - for ( let i=0; i<8; i++ ) { - newID += Math.trunc(Math.random() * 9); //乱数を追加 - - } - //パスワードを生成 const pwGenerated = generateKey(); //DBに書くためにハッシュ化する const pwHashed = await bcrypt.hash(pwGenerated, 10); + //setIntervalを格納する変数 + let CheckIDInterval = null; - //DBに登録 - db.dataUser.user[newID] = { - "name": dat[0], - "role": "Member", - "pw": pwHashed, - "icon": "", - "state": { - "loggedin": false, - "session_id": "", - "sessions": {}, - "banned": false - }, - "channel": db.dataServer.config.CHANNEL.CHANNEL_DEFAULT_JOINONREGISTER - }; - - console.log("registerUser :: 登録結果 ↓"); - console.log(db.dataUser.user[newID]); - - //サーバーのJSONファイルを更新 - fs.writeFileSync("./user.json", JSON.stringify(db.dataUser, null, 4)); + //ユーザー名の空きを調べる + for ( let index in db.dataUser.user ) { + //ユーザー名がすでに使われていたら停止 + if ( db.dataUser.user[index].name === dat[0] ) { + return {result: "USED_NAME", key:-1, userid:-1}; - //デフォルトアイコンを新規ユーザー用にクローン - fs.copyFileSync("./img/default.jpeg", "./img/" + newID + ".jpeg"); + } + + } - //パスワードを返す - return {key:pwGenerated, userid:newID}; + //ユーザーIDの空きを調べて作る + return new Promise((resolve) => { + CheckIDInterval = setInterval(() => { + //ID用変数を初期化 + newID = ""; + //IDへ乱数生成して格納 + for ( let i=0; i<8; i++ ) { + newID += Math.trunc(Math.random() * 9); //乱数を追加 + + } + + //もし生成したIDが空いてるならここで次の処理へ + if ( db.dataUser.user[newID] === undefined ) resolve(); + + }, 10); + + + }).then(() => { + //IDの空き確認用Intervalを停止 + clearInterval(CheckIDInterval); + + //DBに登録 + db.dataUser.user[newID] = { + "name": dat[0], + "role": "Member", + "pw": pwHashed, + "icon": "", + "state": { + "loggedin": false, + "session_id": "", + "sessions": {}, + "banned": false + }, + "channel": db.dataServer.config.CHANNEL.CHANNEL_DEFAULT_JOINONREGISTER + }; + + console.log("registerUser :: 登録結果 ↓"); + console.log(db.dataUser.user[newID]); + + //サーバーのJSONファイルを更新 + fs.writeFileSync("./user.json", JSON.stringify(db.dataUser, null, 4)); + + //デフォルトアイコンを新規ユーザー用にクローン + fs.copyFileSync("./img/default.jpeg", "./img/" + newID + ".jpeg"); + + //パスワードを返す + return {result: "SUCCESS", key:pwGenerated}; + + }); } diff --git a/index.js b/index.js index 6c6cb4e..a63aabb 100644 --- a/index.js +++ b/index.js @@ -1195,8 +1195,8 @@ io.on("connection", (socket) => { let createdUserAuth = await auth.registerUser(dat); //返り値が-1じゃないなら - if ( createdUserAuth.key !== -1 ) { - socket.emit("registerEnd", createdUserAuth.key); //パスワードを送信 + if ( createdUserAuth.result === "SUCCESS" ) { + socket.emit("registerEnd", {"pass":createdUserAuth.key, "result": "SUCCESS"}); //パスワードを送信 //記録するシステムメッセージ let SystemMessageLogging = { @@ -1223,7 +1223,7 @@ io.on("connection", (socket) => { io.to("loggedin").emit("messageReceive", SystemMessageResult); } else { - socket.emit("registerEnd", -1); + socket.emit("registerEnd", {"pass":"", "result": createdUserAuth.result}); } From 3ee66fc4365c9232a54611d670feb15216c43c46 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Sat, 12 Aug 2023 15:46:29 +0900 Subject: [PATCH 2/9] =?UTF-8?q?[change]=20-=20=E7=99=BB=E9=8C=B2=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E6=99=82=E3=81=AE=E3=83=91=E3=83=A9=E3=83=A1?= =?UTF-8?q?=E3=83=BC=E3=82=BF=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auth.js | 6 +++--- index.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/auth.js b/auth.js index bfee6c2..60fc22b 100644 --- a/auth.js +++ b/auth.js @@ -173,7 +173,7 @@ let registerUser = async function registerUser(dat) { //dat=[0=>name(名前), 1= //招待コードが一致しているかどうか if ( db.dataServer.registration.invite.inviteCode !== dat[1] ) { console.log("auth :: registerUser : 招待コード違うわ"); - return {result: "WRONG_CODE", key:-1, userid:-1}; + return {result: "FAILED", pass:""}; } console.log("auth :: registerUser : 招待コード合ってる!"); @@ -193,7 +193,7 @@ let registerUser = async function registerUser(dat) { //dat=[0=>name(名前), 1= for ( let index in db.dataUser.user ) { //ユーザー名がすでに使われていたら停止 if ( db.dataUser.user[index].name === dat[0] ) { - return {result: "USED_NAME", key:-1, userid:-1}; + return {result: "FAILED", pass:""}; } @@ -245,7 +245,7 @@ let registerUser = async function registerUser(dat) { //dat=[0=>name(名前), 1= fs.copyFileSync("./img/default.jpeg", "./img/" + newID + ".jpeg"); //パスワードを返す - return {result: "SUCCESS", key:pwGenerated}; + return {result: "SUCCESS", pass:pwGenerated}; }); diff --git a/index.js b/index.js index a63aabb..5f4952c 100644 --- a/index.js +++ b/index.js @@ -1196,7 +1196,7 @@ io.on("connection", (socket) => { //返り値が-1じゃないなら if ( createdUserAuth.result === "SUCCESS" ) { - socket.emit("registerEnd", {"pass":createdUserAuth.key, "result": "SUCCESS"}); //パスワードを送信 + socket.emit("registerEnd", {"pass":createdUserAuth.pass, "result": "SUCCESS"}); //パスワードを送信 //記録するシステムメッセージ let SystemMessageLogging = { From 2712229f8ad32832baa37efd8c253d9dd81c5d66 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Sat, 12 Aug 2023 15:49:30 +0900 Subject: [PATCH 3/9] =?UTF-8?q?[fix]=20-=20=E3=82=B7=E3=82=B9=E3=83=86?= =?UTF-8?q?=E3=83=A0=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=81=8C?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=81=97=E3=81=A6=E3=81=AA=E3=81=8B=E3=81=A3?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auth.js | 6 +++--- index.js | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/auth.js b/auth.js index 60fc22b..6a3aaf6 100644 --- a/auth.js +++ b/auth.js @@ -173,7 +173,7 @@ let registerUser = async function registerUser(dat) { //dat=[0=>name(名前), 1= //招待コードが一致しているかどうか if ( db.dataServer.registration.invite.inviteCode !== dat[1] ) { console.log("auth :: registerUser : 招待コード違うわ"); - return {result: "FAILED", pass:""}; + return {result: "FAILED", pass:"", userid:""}; } console.log("auth :: registerUser : 招待コード合ってる!"); @@ -193,7 +193,7 @@ let registerUser = async function registerUser(dat) { //dat=[0=>name(名前), 1= for ( let index in db.dataUser.user ) { //ユーザー名がすでに使われていたら停止 if ( db.dataUser.user[index].name === dat[0] ) { - return {result: "FAILED", pass:""}; + return {result: "FAILED", pass:"", userid:""}; } @@ -245,7 +245,7 @@ let registerUser = async function registerUser(dat) { //dat=[0=>name(名前), 1= fs.copyFileSync("./img/default.jpeg", "./img/" + newID + ".jpeg"); //パスワードを返す - return {result: "SUCCESS", pass:pwGenerated}; + return {result: "SUCCESS", pass:pwGenerated, userid:newID}; }); diff --git a/index.js b/index.js index 5f4952c..8e65f00 100644 --- a/index.js +++ b/index.js @@ -1192,16 +1192,18 @@ io.on("connection", (socket) => { //新規登録 socket.on("register", async (dat) => { //DBにユーザーを登録、パスワードとユーザーIDの取得 + //↓useridがついて来るがシステムメッセージにしか使っていない let createdUserAuth = await auth.registerUser(dat); //返り値が-1じゃないなら if ( createdUserAuth.result === "SUCCESS" ) { - socket.emit("registerEnd", {"pass":createdUserAuth.pass, "result": "SUCCESS"}); //パスワードを送信 + socket.emit("registerEnd", {"pass":createdUserAuth.pass, "result":"SUCCESS"}); //パスワードを送信 //記録するシステムメッセージ let SystemMessageLogging = { userid: "SYSTEM", channelid: db.dataServer.config.CHANNEL.CHANNEL_DEFAULT_REGISTERANNOUNCE, + role: "SYSTEM", replyData: { isReplying: false, messageid: "", @@ -1220,7 +1222,7 @@ io.on("connection", (socket) => { //システムメッセージを記録して送信 let SystemMessageResult = msg.msgMix(SystemMessageLogging); - io.to("loggedin").emit("messageReceive", SystemMessageResult); + io.to("loggedin").emit("messageReceive", SystemMessageLogging); } else { socket.emit("registerEnd", {"pass":"", "result": createdUserAuth.result}); From 3d37d5b551c4846f77c7ca7bf4c429d99d18d542 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Sat, 12 Aug 2023 15:55:15 +0900 Subject: [PATCH 4/9] =?UTF-8?q?[change]=20-=20=E3=81=84=E3=82=89=E3=81=AA?= =?UTF-8?q?=E3=81=84=E9=83=A8=E5=88=86=E3=82=92=E7=9C=81=E3=81=84=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8e65f00..df9a81f 100644 --- a/index.js +++ b/index.js @@ -1221,7 +1221,7 @@ io.on("connection", (socket) => { }; //システムメッセージを記録して送信 - let SystemMessageResult = msg.msgMix(SystemMessageLogging); + msg.msgMix(SystemMessageLogging); io.to("loggedin").emit("messageReceive", SystemMessageLogging); } else { From 267911bf6eee891941d942f4409c16e9c0dd4955 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Sat, 12 Aug 2023 16:26:16 +0900 Subject: [PATCH 5/9] =?UTF-8?q?[change]=20-=20=E3=83=A6=E3=83=BC=E3=82=B6?= =?UTF-8?q?=E3=83=BC=E7=99=BB=E9=8C=B2=E6=99=82=E3=81=AE=E3=83=91=E3=83=A9?= =?UTF-8?q?=E3=83=A1=E3=83=BC=E3=82=BF=E3=82=92=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auth.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/auth.js b/auth.js index 6a3aaf6..677a484 100644 --- a/auth.js +++ b/auth.js @@ -171,7 +171,7 @@ let registerUser = async function registerUser(dat) { //dat=[0=>name(名前), 1= //招待制だったらコードを確認 if ( db.dataServer.registration.invite.inviteOnly && db.dataServer.registration.available ) { //招待制かどうか //招待コードが一致しているかどうか - if ( db.dataServer.registration.invite.inviteCode !== dat[1] ) { + if ( db.dataServer.registration.invite.inviteCode !== dat.code ) { console.log("auth :: registerUser : 招待コード違うわ"); return {result: "FAILED", pass:"", userid:""}; @@ -192,7 +192,7 @@ let registerUser = async function registerUser(dat) { //dat=[0=>name(名前), 1= //ユーザー名の空きを調べる for ( let index in db.dataUser.user ) { //ユーザー名がすでに使われていたら停止 - if ( db.dataUser.user[index].name === dat[0] ) { + if ( db.dataUser.user[index].name === dat.username ) { return {result: "FAILED", pass:"", userid:""}; } @@ -222,7 +222,7 @@ let registerUser = async function registerUser(dat) { //dat=[0=>name(名前), 1= //DBに登録 db.dataUser.user[newID] = { - "name": dat[0], + "name": dat.username, "role": "Member", "pw": pwHashed, "icon": "", From 0fd2205dba45983f0c47bf7fe25dbe07486e81a2 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Sat, 12 Aug 2023 16:26:32 +0900 Subject: [PATCH 6/9] =?UTF-8?q?[fix]=20-=20=E3=83=91=E3=82=B9=E3=83=AF?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=81=AE=E3=83=8F=E3=83=83=E3=82=B7=E3=83=A5?= =?UTF-8?q?=E8=A8=88=E7=AE=97=E3=82=92=E5=BE=85=E3=81=A3=E3=81=A6=E3=81=AA?= =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auth.js | 124 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 63 insertions(+), 61 deletions(-) diff --git a/auth.js b/auth.js index 677a484..6e89bd0 100644 --- a/auth.js +++ b/auth.js @@ -18,74 +18,76 @@ let authUser = async function authUser(cred) { let index = Object.keys(db.dataUser.user)[i]; //ユーザー名とパスワードの一致を確認してセッションIDを生成する - if ( - db.dataUser.user[index].name === username && - ( - bcrypt.compare(password, db.dataUser.user[index].pw) || //ハッシュ化とパスワード比較 - db.dataUser.user[index].pw === password //一応平文前提でも、そしてハッシュ化する(次期ビルドで削除) - ) - ) { - //セッションID入れるよう - let _session = ""; + if ( db.dataUser.user[index].name === username ) { + //パスワードのハッシュ値計算 + let passComparedResult = await bcrypt.compare(password, db.dataUser.user[index].pw); + //認証成功したら + if ( passComparedResult ) { + console.log("認証結果->",passComparedResult,); - //BANされているならそう結果を返す - if ( db.dataUser.user[index].state.banned ) { - return {result: false}; + //セッションID入れるよう + let _session = ""; - } + //BANされているならそう結果を返す + if ( db.dataUser.user[index].state.banned ) { + return {result: false}; - //セッションID用に24文字のコードを生成 - let sessionidCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; //セッションIDに使う英数字 - let sessionidLength = 24; //文字数 - _session = Array.from(Array(sessionidLength)).map(()=>sessionidCharset[Math.floor(Math.random()*sessionidCharset.length)]).join(''); + } - let username = db.dataUser.user[index].name; //ユーザー名取得 - - //ログイン時間を記録する用 - let t = new Date(); - //ログイン時間(分まで)を変数へ格納 - let _loginTime = t.getFullYear() + (t.getMonth()+1).toString().padStart(2,0) + t.getDate().toString().padStart(2,0) + t.getHours().toString().padStart(2,0) + t.getMinutes().toString().padStart(2,0); - try { - //セッションコードとデバイスを設定 - db.dataUser.user[index].state.sessions[_session] = { - sessionName: "とあるデバイス", - loggedinTime: _loginTime, - loggedinTimeFirst: _loginTime - }; - } catch(e) { - //セッションいれるところすらないなら作る - db.dataUser.user[index].state.sessions = {}; - db.dataUser.user[index].state.sessions[_session] = { - sessionName: "とあるデバイス", - loggedinTime: _loginTime, - loggedinTimeFirst: _loginTime - }; - } + //セッションID用に24文字のコードを生成 + let sessionidCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; //セッションIDに使う英数字 + let sessionidLength = 24; //文字数 + _session = Array.from(Array(sessionidLength)).map(()=>sessionidCharset[Math.floor(Math.random()*sessionidCharset.length)]).join(''); - // !!!! ↓↓次期ビルドで削除↓↓ !!!! - /************************************************************/ - //パスワードが平文保存されているならハッシュ化して保存 - if ( db.dataUser.user[index].pw === password ) { - db.dataUser.user[index].pw = await bcrypt.hash(cred.password, 10); + let username = db.dataUser.user[index].name; //ユーザー名取得 + + //ログイン時間を記録する用 + let t = new Date(); + //ログイン時間(分まで)を変数へ格納 + let _loginTime = t.getFullYear() + (t.getMonth()+1).toString().padStart(2,0) + t.getDate().toString().padStart(2,0) + t.getHours().toString().padStart(2,0) + t.getMinutes().toString().padStart(2,0); + try { + //セッションコードとデバイスを設定 + db.dataUser.user[index].state.sessions[_session] = { + sessionName: "とあるデバイス", + loggedinTime: _loginTime, + loggedinTimeFirst: _loginTime + }; + } catch(e) { + //セッションいれるところすらないなら作る + db.dataUser.user[index].state.sessions = {}; + db.dataUser.user[index].state.sessions[_session] = { + sessionName: "とあるデバイス", + loggedinTime: _loginTime, + loggedinTimeFirst: _loginTime + }; + } + + // !!!! ↓↓次期ビルドで削除↓↓ !!!! + /************************************************************/ + //パスワードが平文保存されているならハッシュ化して保存 + if ( db.dataUser.user[index].pw === password ) { + db.dataUser.user[index].pw = await bcrypt.hash(cred.password, 10); + + } + //以前の形式のせっしょんIDがあるなら削除 + if ( db.dataUser.user[index].state.session_id !== undefined ) { + delete db.dataUser.user[index].state.session_id; + } + /************************************************************/ + + //サーバーのJSONファイルを更新 + fs.writeFileSync("./user.json", JSON.stringify(db.dataUser, null, 4)); + + return { + result: true, //ログイン成功の印 + userid: index, //ユーザーID + username: username, //ユーザー名 + sessionid: _session, //セッションコード + role: db.dataUser.user[index].role, //ロール + channelJoined: db.dataUser.user[index].channel //参加しているチャンネル + }; //ユーザーの情報を送信 } - //以前の形式のせっしょんIDがあるなら削除 - if ( db.dataUser.user[index].state.session_id !== undefined ) { - delete db.dataUser.user[index].state.session_id; - } - /************************************************************/ - - //サーバーのJSONファイルを更新 - fs.writeFileSync("./user.json", JSON.stringify(db.dataUser, null, 4)); - - return { - result: true, //ログイン成功の印 - userid: index, //ユーザーID - username: username, //ユーザー名 - sessionid: _session, //セッションコード - role: db.dataUser.user[index].role, //ロール - channelJoined: db.dataUser.user[index].channel //参加しているチャンネル - }; //ユーザーの情報を送信 } From d0f82905101df5300393178f9c2e1251020b14f2 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Sat, 12 Aug 2023 16:30:39 +0900 Subject: [PATCH 7/9] =?UTF-8?q?[fix]=20-=20=E3=83=91=E3=82=B9=E3=83=AF?= =?UTF-8?q?=E3=83=BC=E3=83=89=E5=A4=89=E6=9B=B4=E6=99=82=E3=81=AE=E3=83=8F?= =?UTF-8?q?=E3=83=83=E3=82=B7=E3=83=A5=E8=A8=88=E7=AE=97=E3=82=92=E5=BE=85?= =?UTF-8?q?=E3=81=A3=E3=81=A6=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auth.js | 10 ++++++---- index.js | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/auth.js b/auth.js index 6e89bd0..9e2d898 100644 --- a/auth.js +++ b/auth.js @@ -23,8 +23,6 @@ let authUser = async function authUser(cred) { let passComparedResult = await bcrypt.compare(password, db.dataUser.user[index].pw); //認証成功したら if ( passComparedResult ) { - console.log("認証結果->",passComparedResult,); - //セッションID入れるよう let _session = ""; @@ -101,14 +99,18 @@ let authUser = async function authUser(cred) { //パスワードを変更 let changePassword = async function changePassword(dat) { + //現在のパスワードをハッシュ比較 + let passComparedResult = await bcrypt.compare(dat.currentPassword, db.dataUser.user[dat.reqSender.userid].pw); + //今のパスワードが一致しないならここで停止 - if ( + if ( db.dataUser.user[dat.reqSender.userid].pw !== dat.currentPassword && //平文でも比較 次期ビルドで削除 - !bcrypt.compare(dat.currentPassword, db.dataUser.user[dat.reqSender.userid].pw) + !passComparedResult ) { return -1; } + //パスワードをハッシュ化 let newPassword = await bcrypt.hash(dat.newPassword, 10); //パスワード変更 diff --git a/index.js b/index.js index df9a81f..60cd144 100644 --- a/index.js +++ b/index.js @@ -1195,7 +1195,7 @@ io.on("connection", (socket) => { //↓useridがついて来るがシステムメッセージにしか使っていない let createdUserAuth = await auth.registerUser(dat); - //返り値が-1じゃないなら + //成功したら送信 if ( createdUserAuth.result === "SUCCESS" ) { socket.emit("registerEnd", {"pass":createdUserAuth.pass, "result":"SUCCESS"}); //パスワードを送信 @@ -1224,7 +1224,7 @@ io.on("connection", (socket) => { msg.msgMix(SystemMessageLogging); io.to("loggedin").emit("messageReceive", SystemMessageLogging); - } else { + } else { //失敗したら失敗を伝える socket.emit("registerEnd", {"pass":"", "result": createdUserAuth.result}); } From fe6dc572f76273e6507e8ab9200b93cce2eafcdb Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Sat, 12 Aug 2023 16:33:22 +0900 Subject: [PATCH 8/9] =?UTF-8?q?[add]=20-=20=E3=82=B3=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 60cd144..ff2b01a 100644 --- a/index.js +++ b/index.js @@ -143,7 +143,7 @@ let sendUrlPreview = function sendUrlPreview(urlDataItem, channelid, msgId) { io.to("loggedin").emit("messageUpdate", dat); //履歴を返す } - +//外部スクリプトで使う用 exports.sendUrlPreview = sendUrlPreview; //////////////////////////////////////////////////////////////// From b8f4bf2eef40ca73ad9cc58f04d09f0427b4aff9 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Sat, 12 Aug 2023 16:37:52 +0900 Subject: [PATCH 9/9] =?UTF-8?q?[add]=20-=20=E3=83=A6=E3=83=BC=E3=82=B6?= =?UTF-8?q?=E3=83=BC=E7=99=BB=E9=8C=B2=E6=99=82=E3=81=AB=E5=90=8D=E5=89=8D?= =?UTF-8?q?=E3=81=AE=E9=95=B7=E3=81=95=E3=81=8C=EF=BC=93=E6=96=87=E5=AD=97?= =?UTF-8?q?=E6=9C=AA=E6=BA=80=E3=81=AA=E3=82=89=E5=81=9C=E6=AD=A2=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index ff2b01a..45b885d 100644 --- a/index.js +++ b/index.js @@ -1191,6 +1191,13 @@ io.on("connection", (socket) => { //新規登録 socket.on("register", async (dat) => { + //ユーザー名が2文字以下なら停止 + if ( dat.username.length <= 2 ) { + socket.emit("registerEnd", {"pass":"", "result": "FAILED"}); + return; + + } + //DBにユーザーを登録、パスワードとユーザーIDの取得 //↓useridがついて来るがシステムメッセージにしか使っていない let createdUserAuth = await auth.registerUser(dat);