diff --git a/Applications/VK.app/Localizations/Dutch.lang b/Applications/VK.app/Localizations/Dutch.lang index 88730cb5..f85de603 100644 --- a/Applications/VK.app/Localizations/Dutch.lang +++ b/Applications/VK.app/Localizations/Dutch.lang @@ -8,6 +8,8 @@ username = "E-mail of telefoon nummer", password = "Wachtwoord", login = "Log in", + twoFactorEnabled = "2FA enthalten", + twoFactor = "2FA code", saveLogin = "Sla login informatie op:", loadCountConversations = "Het aantal geladen dialogen", diff --git a/Applications/VK.app/Localizations/English.lang b/Applications/VK.app/Localizations/English.lang index 46dfed2b..8f2fc0d4 100644 --- a/Applications/VK.app/Localizations/English.lang +++ b/Applications/VK.app/Localizations/English.lang @@ -8,6 +8,8 @@ username = "E-mail or phone number", password = "Password", login = "Enter", + twoFactorEnabled = "Use 2FA", + twoFactor = "2FA code", saveLogin = "Save login information:", loadCountConversations = "The number of loaded dialogues", diff --git a/Applications/VK.app/Localizations/Russian.lang b/Applications/VK.app/Localizations/Russian.lang index 7923e087..ef1ec6d2 100644 --- a/Applications/VK.app/Localizations/Russian.lang +++ b/Applications/VK.app/Localizations/Russian.lang @@ -8,6 +8,8 @@ username = "E-mail или номер телефона", password = "Пароль", login = "Войти", + twoFactorEnabled = "Использовать 2FA", + twoFactor = "Код 2FA", saveLogin = "Сохранять данные входа:", loadCountConversations = "Число загружаемых диалогов", diff --git a/Applications/VK.app/Main.lua b/Applications/VK.app/Main.lua index 2e74f6ff..af99de5f 100644 --- a/Applications/VK.app/Main.lua +++ b/Applications/VK.app/Main.lua @@ -120,7 +120,8 @@ local function request(url, postData, headers) return data else - GUI.alert("Failed to perform internet request: " .. tostring(reason)) + --GUI.alert("Failed to perform internet request: " .. tostring(reason)) + return nil, reason end end @@ -1668,6 +1669,9 @@ local function login() logo.height = logo.height + 1 local usernameInput = layout:addChild(GUI.input(1, 1, 36, 3, style.UIInputBackground, style.UIInputForeground, style.UIInputPlaceholder, style.UIInputBackground, style.UIInputFocusedForeground, config.username or "", localization.username)) local passwordInput = layout:addChild(GUI.input(1, 1, 36, 3, style.UIInputBackground, style.UIInputForeground, style.UIInputPlaceholder, style.UIInputBackground, style.UIInputFocusedForeground, config.password or "", localization.password, true, "•")) + local twoFactorSwitch = layout:addChild(GUI.switchAndLabel(1, 1, 36, 6, style.UISwitchActive, style.UISwitchPassive, style.UISwitchPipe, style.UIText, localization.twoFactorEnabled, false)) + local twoFactorInput = layout:addChild(GUI.input(1, 1, 36, 3, style.UIInputBackground, style.UIInputForeground, style.UIInputPlaceholder, style.UIInputBackground, style.UIInputFocusedForeground, config.twoFactor or "", localization.twoFactor)) + twoFactorInput.hidden = true local loginButton = layout:addChild(GUI.button(1, 1, 36, 3, style.UIButtonDefaultBackground, style.UIButtonDefaultForeground, style.UIButtonPressedBackground, style.UIButtonPressedForeground, localization.login)) loginButton.colors.disabled = { background = style.UIButtonDisabledBackground, @@ -1678,13 +1682,19 @@ local function login() loginusernameInput.hidden = true usernameInput.onInputFinished = function() - loginButton.disabled = #usernameInput.text == 0 or #passwordInput.text == 0 + loginButton.disabled = #usernameInput.text == 0 or #passwordInput.text == 0 or twoFactorSwitch.switch.state and #twoFactorInput.text == 0 workspace:draw() end passwordInput.onInputFinished = usernameInput.onInputFinished + twoFactorInput.onInputFinished = usernameInput.onInputFinished + + twoFactorSwitch.switch.onStateChanged = function() + twoFactorInput.hidden = not twoFactorSwitch.switch.state + usernameInput.onInputFinished() + end loginButton.onTouch = function() - local result, reason = request("https://oauth.vk.com/token?grant_type=password&client_id=2274003&client_secret=hHbZxrka2uZ6jB1inYsH&username=" .. internet.encode(usernameInput.text) .. "&password=" .. internet.encode(passwordInput.text) .. "&v=" .. VKAPIVersion) + local result, reason = request("https://oauth.vk.com/token?grant_type=password&client_id=2274003&client_secret=hHbZxrka2uZ6jB1inYsH&2fa_supported=1&username=" .. internet.encode(usernameInput.text) .. "&password=" .. internet.encode(passwordInput.text) .. "&code=" .. twoFactorInput.text .. "&v=" .. VKAPIVersion) if result then if result.access_token then currentAccessToken = result.access_token @@ -1701,6 +1711,8 @@ local function login() end saveConfig() + else + GUI.alert("An error occurred while logging in: " .. reason) end end