diff options
author | George Hazan <george.hazan@gmail.com> | 2024-01-15 18:22:46 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-01-15 18:22:46 +0300 |
commit | b39e2087e034546e7de1ee9c9f5ce5e34080c91b (patch) | |
tree | cf39e1fac13d900c4fd2d5f52eb26bdf5ec51ed9 /protocols | |
parent | 383e4401315371bef93c510479b36c8fd53ecdc0 (diff) |
Discord:
- fixes #4122 (Discord: добавить поддержку входа с резервным кодом);
- fixes #4121 (Discord: добавить поддержку СМС в качестве второго фактора);
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Discord/res/discord.rc | 2 | ||||
-rw-r--r-- | protocols/Discord/src/mfa.cpp | 59 | ||||
-rw-r--r-- | protocols/Discord/src/resource.h | 4 |
3 files changed, 44 insertions, 21 deletions
diff --git a/protocols/Discord/res/discord.rc b/protocols/Discord/res/discord.rc index 73a238be61..673dc3dfd5 100644 --- a/protocols/Discord/res/discord.rc +++ b/protocols/Discord/res/discord.rc @@ -123,7 +123,7 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,259,31,50,14
LTEXT "",IDC_LABEL,7,8,238,12
EDITTEXT IDC_CODE,250,7,59,16,ES_AUTOHSCROLL
- PUSHBUTTON "Use another method",IDC_ANOTHER,7,31,131,14
+ COMBOBOX IDC_ANOTHER,7,32,133,30,CBS_DROPDOWNLIST | WS_TABSTOP
END
diff --git a/protocols/Discord/src/mfa.cpp b/protocols/Discord/src/mfa.cpp index 9bdc1539f4..5962efc60d 100644 --- a/protocols/Discord/src/mfa.cpp +++ b/protocols/Discord/src/mfa.cpp @@ -21,12 +21,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. class CMfaDialog : public CDiscordDlgBase { - bool m_bHasSms, m_bHasTotp, m_bUseTotp = true; + bool m_bHasSms, m_bHasTotp; + int m_mode = 0; CMStringA m_szTicket; CCtrlBase m_label; CCtrlEdit edtCode; - CCtrlButton btnCancel, btnAnother; + CCtrlCombo cmbAnother; + CCtrlButton btnCancel; public: CMfaDialog(CDiscordProto *ppro, const JSONNode &pRoot) : @@ -34,10 +36,12 @@ public: m_label(this, IDC_LABEL), edtCode(this, IDC_CODE), btnCancel(this, IDCANCEL), - btnAnother(this, IDC_ANOTHER) + cmbAnother(this, IDC_ANOTHER) { btnCancel.OnClick = Callback(this, &CMfaDialog::onClick_Cancel); + cmbAnother.OnChange = Callback(this, &CMfaDialog::onChange_Combo); + m_bHasSms = pRoot["sms"].as_bool(); m_bHasTotp = pRoot["totp"].as_bool(); m_szTicket = pRoot["ticket"].as_mstring(); @@ -45,29 +49,48 @@ public: bool OnInitDialog() override { - if (m_bUseTotp) - m_label.SetText(TranslateT("Enter Discord verification code:")); - else - m_label.SetText(TranslateT("Enter SMS code")); - - // if (!m_bHasSms) - btnAnother.Disable(); + if (m_bHasTotp) + cmbAnother.AddString(TranslateT("Use authentication app"), 0); + if (m_bHasSms) + cmbAnother.AddString(TranslateT("Use a code sent to your phone"), 1); + cmbAnother.AddString(TranslateT("Use a backup code"), 2); + cmbAnother.SetCurSel(0); return true; } bool OnApply() override { + JSONNode root; + root << CHAR_PARAM("ticket", m_szTicket); + + const char *wszUrl; ptrW wszCode(edtCode.GetText()); + if (mir_wstrlen(wszCode)) { + wszUrl = (m_mode == 1) ? "/auth/mfa/sms" : "/auth/mfa/totp"; + root << WCHAR_PARAM("code", wszCode); + } + else wszUrl = "/auth/mfa/sms/send"; + + auto *pReq = new AsyncHttpRequest(m_proto, REQUEST_POST, wszUrl, &CDiscordProto::OnSendTotp, &root); + pReq->pUserInfo = this; + m_proto->Push(pReq); + return false; + } - if (m_bUseTotp) { - JSONNode root; - root << WCHAR_PARAM("code", wszCode) << CHAR_PARAM("ticket", m_szTicket); + void onChange_Combo(CCtrlCombo *) + { + edtCode.SetText(L""); - auto *pReq = new AsyncHttpRequest(m_proto, REQUEST_POST, "/auth/mfa/totp", &CDiscordProto::OnSendTotp, &root); - pReq->pUserInfo = this; - m_proto->Push(pReq); + switch (m_mode = cmbAnother.GetCurData()) { + case 0: + m_label.SetText(TranslateT("Enter Discord verification code:")); break; + case 1: + m_label.SetText(TranslateT("Enter SMS code you received:")); + OnApply(); + break; + default: + m_label.SetText(TranslateT("Enter one of your backup codes")); } - return false; } void onClick_Cancel(CCtrlButton *) @@ -78,7 +101,7 @@ public: void WrongCode() { edtCode.SetText(L""); - Beep(470, 200); + MessageBeep(MB_ICONERROR); } }; diff --git a/protocols/Discord/src/resource.h b/protocols/Discord/src/resource.h index 00f55d2886..b7f625fa1e 100644 --- a/protocols/Discord/src/resource.h +++ b/protocols/Discord/src/resource.h @@ -21,8 +21,8 @@ #define IDC_DELETE_MSGS 1009
#define IDC_ANOTHER 1009
#define IDC_LABEL 1010
-#define IDC_BUTTON1 1011
#define IDC_LOGOUT 1011
+#define IDC_COMBO1 1012
// Next default values for new objects
//
@@ -30,7 +30,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 108
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1012
+#define _APS_NEXT_CONTROL_VALUE 1013
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
|