From c764845c21b3d7ebab63d78b0269ddde2e0ae7bb Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sun, 27 Nov 2016 19:17:46 +0300 Subject: [PATCH] Improved login form Also supported delayed account reset --- app/js/controllers.js | 23 ++++++++++++++----- app/js/filters.js | 11 ++++----- app/js/locales/en-us.json | 14 +++++++----- app/partials/desktop/error_modal.html | 5 +++++ app/partials/desktop/login.html | 32 +++++++++++++-------------- app/partials/mobile/login.html | 26 ++++++++++++---------- 6 files changed, 67 insertions(+), 44 deletions(-) diff --git a/app/js/controllers.js b/app/js/controllers.js index 27897dee..3502815b 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -235,6 +235,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.credentials.type = sentCode.type $scope.nextPending.type = sentCode.next_type || false $scope.nextPending.remaining = sentCode.timeout || false + delete $scope.nextPending.progress nextTimeoutCheck() @@ -248,6 +249,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.nextPending.remaining > 0) { return } + $scope.nextPending.progress = true MtpApiManager.invokeApi('auth.resendCode', { phone_number: $scope.credentials.phone_full, phone_code_hash: $scope.credentials.phone_code_hash @@ -260,10 +262,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.nextPending.remaining === false) { return } - if (!(--$scope.nextPending.remaining)) { - $scope.nextPending.success = false - $scope.sendNext() - } else { + if ((--$scope.nextPending.remaining) > 0) { nextTimeout = $timeout(nextTimeoutCheck, 1000) } } @@ -283,7 +282,6 @@ angular.module('myApp.controllers', ['myApp.i18n']) delete $scope.credentials.phone_unoccupied delete $scope.credentials.phone_code_valid delete $scope.nextPending.remaining - delete $scope.nextPending.success } $scope.$watch('credentials.phone_code', function (newVal) { @@ -297,6 +295,10 @@ angular.module('myApp.controllers', ['myApp.i18n']) }) $scope.logIn = function (forceSignUp) { + if ($scope.progress.enabled && + $scope.progress.forceSignUp == forceSignUp) { + return + } var method = 'auth.signIn' var params = { phone_number: $scope.credentials.phone_full, @@ -311,6 +313,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) }) } + $scope.progress.forceSignUp = forceSignUp; $scope.progress.enabled = true MtpApiManager.invokeApi(method, params, options).then(saveAuth, function (error) { $scope.progress.enabled = false @@ -358,7 +361,9 @@ angular.module('myApp.controllers', ['myApp.i18n']) } $scope.checkPassword = function () { + $scope.progress.enabled = true return PasswordManager.check($scope.password, $scope.credentials.password, options).then(saveAuth, function (error) { + $scope.progress.enabled = false switch (error.type) { case 'PASSWORD_HASH_INVALID': $scope.error = {field: 'password'} @@ -416,7 +421,13 @@ angular.module('myApp.controllers', ['myApp.i18n']) delete $scope.progress.enabled delete $scope.credentials.password_needed $scope.credentials.phone_unoccupied = true - }, function () { + }, function (error) { + if (error.type && + error.type.substr(0, 17) == '2FA_CONFIRM_WAIT_') { + error.waitTime = error.type.substr(17) + error.type = '2FA_CONFIRM_WAIT_TIME' + } + delete $scope.progress.enabled }) }) diff --git a/app/js/filters.js b/app/js/filters.js index 3665094e..c3c0c818 100644 --- a/app/js/filters.js +++ b/app/js/filters.js @@ -139,14 +139,15 @@ angular.module('myApp.filters', ['myApp.i18n']) if (isNaN(duration)) { duration = 0 } + var hours = Math.floor(duration / 3600) + var mins = Math.floor((duration % 3600) / 60) var secs = duration % 60 - var mins = Math.floor((duration - secs) / 60.0) - if (secs < 10) { - secs = '0' + secs - } + var durationStr = (hours ? hours + ':' : '') + mins + ':' secs + + durationStr = durationStr.replace(/:(\d(?::|$))/g, ':0\1') - return mins + ':' + secs + return durationStr } }]) diff --git a/app/js/locales/en-us.json b/app/js/locales/en-us.json index 902582af..936c97c2 100644 --- a/app/js/locales/en-us.json +++ b/app/js/locales/en-us.json @@ -414,6 +414,8 @@ "error_modal_channel_not_accessible": "Sorry, this channel is not accessible.", "error_modal_not_contact_flood": "Sorry, you can only send messages to mutual contacts at the moment. {more-info-link: More info ยป}", "error_modal_gelocation_na": "App was unable to determine your current location", + "error_modal_2fa_recent_confirm": "Your recent attempts to reset this account have been cancelled by its active user. Please try again in 7 days.", + "error_modal_2fa_delayed_time_md": "You'll be able to reset your account in: **{time}**", "head_telegram": "Telegram", @@ -509,12 +511,14 @@ "login_generating_key": "Generating keys", "login_generating_keys_info": "Keys are only generated once. This can take a few minutes on slower devices, please be patient.", "login_edit_number": "Edit phone number", - "login_enter_code_label_md": "We've sent you a code via **Telegram** (not SMS).\nPlease check your Telegram messages and enter the code below.", + "login_enter_code_label_md": "We've sent the code to the **Telegram** app on your other device.\nPlease enter the code below.", + "login_enter_sms_code_label_md": "We've sent an SMS with an activation code to your phone.\nPlease enter the code below.", + "login_enter_call_code_label_md": "We are calling your phone to dictate a code.\nPlease enter the code below.", + "login_code_remaining": "You will be able to request SMS in {remaining}", + "login_call_remaining": "You will be able to request call in {remaining}", "login_code_not_received": "Send code via SMS", - "login_enter_sms_code_label_md": "We have sent you a code via SMS.\nPlease enter it below.", - "login_call_remaining": "Telegram will call you in {remaining}", - "login_calling": "Telegram is calling you", - "login_number_dialed": "Telegram dialed your number", + "login_code_not_received_call": "Send code via Call", + "login_code_requesting": "Requesting code", "login_incorrect_sms_code": "Incorrect SMS code", "login_number_input_placeholder": "Enter your code", "login_checking_code": "Checking code", diff --git a/app/partials/desktop/error_modal.html b/app/partials/desktop/error_modal.html index a47dfa4c..43a97e08 100644 --- a/app/partials/desktop/error_modal.html +++ b/app/partials/desktop/error_modal.html @@ -48,6 +48,11 @@ {0} + + + + + diff --git a/app/partials/desktop/login.html b/app/partials/desktop/login.html index 3917b6d1..f67f2aa5 100644 --- a/app/partials/desktop/login.html +++ b/app/partials/desktop/login.html @@ -33,7 +33,7 @@
-
+
@@ -59,29 +59,29 @@
+
-
+
- -
- -
-
- -
@@ -96,13 +96,13 @@
- +
- +
diff --git a/app/partials/mobile/login.html b/app/partials/mobile/login.html index c5cae8fd..77f3f074 100644 --- a/app/partials/mobile/login.html +++ b/app/partials/mobile/login.html @@ -43,7 +43,7 @@