From f9526af6e2236193cbd5bbab7af5d8e386c2233e Mon Sep 17 00:00:00 2001 From: Sergey Bolhovskoy Date: Thu, 29 Oct 2015 18:24:58 +0000 Subject: VKontakte: fix for cleaning access token on login or password change version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@15649 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/misc.cpp | 13 +++++-- protocols/VKontakte/src/version.h | 2 +- protocols/VKontakte/src/vk_options.cpp | 69 +++++++++++++++++++++++----------- protocols/VKontakte/src/vk_proto.h | 2 + 4 files changed, 61 insertions(+), 25 deletions(-) (limited to 'protocols') diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 3d77b0b0a4..8d1661fcc4 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -134,6 +134,15 @@ char* ExpUrlEncode(const char *szUrl, bool strict) ///////////////////////////////////////////////////////////////////////////////////////// +void CVkProto::ClearAccessToken() +{ + debugLogA("CVkProto::ClearAccessToken"); + setDword("LastAccessTokenTime", (DWORD)time(NULL)); + m_szAccessToken = NULL; + delSetting("AccessToken"); + ShutdownSession(); +} + TCHAR* CVkProto::GetUserStoredPassword() { debugLogA("CVkProto::GetUserStoredPassword"); @@ -253,9 +262,7 @@ bool CVkProto::CheckJsonResult(AsyncHttpRequest *pReq, const JSONNode &jnNode) case VKERR_ACCESS_DENIED: if (time(NULL) - getDword("LastAccessTokenTime", 0) > 60 * 60 * 24) { debugLogA("CVkProto::CheckJsonResult VKERR_ACCESS_DENIED (AccessToken fail?)"); - setDword("LastAccessTokenTime", (DWORD)time(NULL)); - delSetting("AccessToken"); - ShutdownSession(); + ClearAccessToken(); return false; } debugLogA("CVkProto::CheckJsonResult VKERR_ACCESS_DENIED"); diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h index 8a0a366134..5f067dfbd6 100644 --- a/protocols/VKontakte/src/version.h +++ b/protocols/VKontakte/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 1 -#define __BUILD_NUM 17 +#define __BUILD_NUM 18 #include diff --git a/protocols/VKontakte/src/vk_options.cpp b/protocols/VKontakte/src/vk_options.cpp index 86470e1295..03fbb011c0 100644 --- a/protocols/VKontakte/src/vk_options.cpp +++ b/protocols/VKontakte/src/vk_options.cpp @@ -34,13 +34,13 @@ INT_PTR CALLBACK VKAccountProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)IcoLib_GetIconByHandle(ppro->m_hProtoIcon, 1)); SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)IcoLib_GetIconByHandle(ppro->m_hProtoIcon)); { - ptrT tszLogin(ppro->getTStringA("Login")); - if (tszLogin != NULL) - SetDlgItemText(hwndDlg, IDC_LOGIN, tszLogin); + ptrT ptszLogin(ppro->getTStringA("Login")); + if (ptszLogin != NULL) + SetDlgItemText(hwndDlg, IDC_LOGIN, ptszLogin); - ptrT tszPassw(ppro->GetUserStoredPassword()); - if (tszPassw != NULL) - SetDlgItemText(hwndDlg, IDC_PASSWORD, tszPassw); + ptrT ptszPassw(ppro->GetUserStoredPassword()); + if (ptszPassw != NULL) + SetDlgItemText(hwndDlg, IDC_PASSWORD, ptszPassw); } return TRUE; @@ -63,13 +63,27 @@ INT_PTR CALLBACK VKAccountProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: TCHAR str[1025]; + bool bNeedClearToken = false; GetDlgItemText(hwndDlg, IDC_LOGIN, str, _countof(str)); - ppro->setTString("Login", str); + + CMString tszLogin(ptrT(ppro->getTStringA("Login"))); + if (tszLogin != str) { + bNeedClearToken = true; + ppro->setTString("Login", str); + } GetDlgItemText(hwndDlg, IDC_PASSWORD, str, _countof(str)); + CMString tszPassw(ptrT(ppro->GetUserStoredPassword())); + T2Utf szRawPasswd(str); - if (szRawPasswd != NULL) + if (szRawPasswd != NULL && tszPassw != str) { + bNeedClearToken = true; ppro->setString("Password", szRawPasswd); + } + + if (bNeedClearToken) + ppro->ClearAccessToken(); + } break; @@ -108,13 +122,13 @@ INT_PTR CALLBACK CVkProto::OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)IcoLib_GetIconByHandle(ppro->m_hProtoIcon, 1)); SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)IcoLib_GetIconByHandle(ppro->m_hProtoIcon)); { - ptrT tszLogin(ppro->getTStringA("Login")); - if (tszLogin != NULL) - SetDlgItemText(hwndDlg, IDC_LOGIN, tszLogin); + ptrT ptszLogin(ppro->getTStringA("Login")); + if (ptszLogin != NULL) + SetDlgItemText(hwndDlg, IDC_LOGIN, ptszLogin); - ptrT tszPassw(ppro->GetUserStoredPassword()); - if (tszPassw != NULL) - SetDlgItemText(hwndDlg, IDC_PASSWORD, tszPassw); + ptrT ptszPassw(ppro->GetUserStoredPassword()); + if (ptszPassw != NULL) + SetDlgItemText(hwndDlg, IDC_PASSWORD, ptszPassw); SetDlgItemText(hwndDlg, IDC_GROUPNAME, ppro->getGroup()); } @@ -170,20 +184,30 @@ INT_PTR CALLBACK CVkProto::OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L case WM_NOTIFY: if (((LPNMHDR)lParam)->code == PSN_APPLY) { TCHAR str[1025]; + bool bNeedClearToken = false; GetDlgItemText(hwndDlg, IDC_LOGIN, str, _countof(str)); - ppro->setTString("Login", str); - GetDlgItemText(hwndDlg, IDC_GROUPNAME, str, _countof(str)); - if (mir_tstrcmp(ppro->getGroup(), str)) { - ppro->setGroup(str); - ppro->setTString("ProtoGroup", str); + CMString tszLogin(ptrT(ppro->getTStringA("Login"))); + if (tszLogin != str) { + bNeedClearToken = true; + ppro->setTString("Login", str); } GetDlgItemText(hwndDlg, IDC_PASSWORD, str, _countof(str)); + CMString tszPassw(ptrT(ppro->GetUserStoredPassword())); + T2Utf szRawPasswd(str); - if (szRawPasswd != NULL) + if (szRawPasswd != NULL && tszPassw != str) { + bNeedClearToken = true; ppro->setString("Password", szRawPasswd); - + } + + GetDlgItemText(hwndDlg, IDC_GROUPNAME, str, _countof(str)); + if (mir_tstrcmp(ppro->getGroup(), str)) { + ppro->setGroup(str); + ppro->setTString("ProtoGroup", str); + } + ppro->m_bServerDelivery = IsDlgButtonChecked(hwndDlg, IDC_DELIVERY) == BST_CHECKED; ppro->setByte("ServerDelivery", ppro->m_bServerDelivery); @@ -212,6 +236,9 @@ INT_PTR CALLBACK CVkProto::OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L ppro->m_iSyncHistoryMetod = sync3Days; ppro->setByte("SyncHistoryMetod", ppro->m_iSyncHistoryMetod); + + if (bNeedClearToken) + ppro->ClearAccessToken(); } break; diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 3422e066f6..6623addcb8 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -270,6 +270,8 @@ struct CVkProto : public PROTO static mir_cs m_csTimer; static UINT_PTR m_timer; + void ClearAccessToken(); + private: friend struct AsyncHttpRequest; -- cgit v1.2.3