Browse Source

Improved login form

Also supported delayed account reset
master
Igor Zhukov 8 years ago
parent
commit
c764845c21
  1. 23
      app/js/controllers.js
  2. 11
      app/js/filters.js
  3. 14
      app/js/locales/en-us.json
  4. 5
      app/partials/desktop/error_modal.html
  5. 32
      app/partials/desktop/login.html
  6. 26
      app/partials/mobile/login.html

23
app/js/controllers.js

@ -235,6 +235,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.credentials.type = sentCode.type $scope.credentials.type = sentCode.type
$scope.nextPending.type = sentCode.next_type || false $scope.nextPending.type = sentCode.next_type || false
$scope.nextPending.remaining = sentCode.timeout || false $scope.nextPending.remaining = sentCode.timeout || false
delete $scope.nextPending.progress
nextTimeoutCheck() nextTimeoutCheck()
@ -248,6 +249,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.nextPending.remaining > 0) { $scope.nextPending.remaining > 0) {
return return
} }
$scope.nextPending.progress = true
MtpApiManager.invokeApi('auth.resendCode', { MtpApiManager.invokeApi('auth.resendCode', {
phone_number: $scope.credentials.phone_full, phone_number: $scope.credentials.phone_full,
phone_code_hash: $scope.credentials.phone_code_hash phone_code_hash: $scope.credentials.phone_code_hash
@ -260,10 +262,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.nextPending.remaining === false) { $scope.nextPending.remaining === false) {
return return
} }
if (!(--$scope.nextPending.remaining)) { if ((--$scope.nextPending.remaining) > 0) {
$scope.nextPending.success = false
$scope.sendNext()
} else {
nextTimeout = $timeout(nextTimeoutCheck, 1000) nextTimeout = $timeout(nextTimeoutCheck, 1000)
} }
} }
@ -283,7 +282,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
delete $scope.credentials.phone_unoccupied delete $scope.credentials.phone_unoccupied
delete $scope.credentials.phone_code_valid delete $scope.credentials.phone_code_valid
delete $scope.nextPending.remaining delete $scope.nextPending.remaining
delete $scope.nextPending.success
} }
$scope.$watch('credentials.phone_code', function (newVal) { $scope.$watch('credentials.phone_code', function (newVal) {
@ -297,6 +295,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}) })
$scope.logIn = function (forceSignUp) { $scope.logIn = function (forceSignUp) {
if ($scope.progress.enabled &&
$scope.progress.forceSignUp == forceSignUp) {
return
}
var method = 'auth.signIn' var method = 'auth.signIn'
var params = { var params = {
phone_number: $scope.credentials.phone_full, phone_number: $scope.credentials.phone_full,
@ -311,6 +313,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}) })
} }
$scope.progress.forceSignUp = forceSignUp;
$scope.progress.enabled = true $scope.progress.enabled = true
MtpApiManager.invokeApi(method, params, options).then(saveAuth, function (error) { MtpApiManager.invokeApi(method, params, options).then(saveAuth, function (error) {
$scope.progress.enabled = false $scope.progress.enabled = false
@ -358,7 +361,9 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} }
$scope.checkPassword = function () { $scope.checkPassword = function () {
$scope.progress.enabled = true
return PasswordManager.check($scope.password, $scope.credentials.password, options).then(saveAuth, function (error) { return PasswordManager.check($scope.password, $scope.credentials.password, options).then(saveAuth, function (error) {
$scope.progress.enabled = false
switch (error.type) { switch (error.type) {
case 'PASSWORD_HASH_INVALID': case 'PASSWORD_HASH_INVALID':
$scope.error = {field: 'password'} $scope.error = {field: 'password'}
@ -416,7 +421,13 @@ angular.module('myApp.controllers', ['myApp.i18n'])
delete $scope.progress.enabled delete $scope.progress.enabled
delete $scope.credentials.password_needed delete $scope.credentials.password_needed
$scope.credentials.phone_unoccupied = true $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 delete $scope.progress.enabled
}) })
}) })

11
app/js/filters.js

@ -139,14 +139,15 @@ angular.module('myApp.filters', ['myApp.i18n'])
if (isNaN(duration)) { if (isNaN(duration)) {
duration = 0 duration = 0
} }
var hours = Math.floor(duration / 3600)
var mins = Math.floor((duration % 3600) / 60)
var secs = duration % 60 var secs = duration % 60
var mins = Math.floor((duration - secs) / 60.0)
if (secs < 10) { var durationStr = (hours ? hours + ':' : '') + mins + ':' secs
secs = '0' + secs
} durationStr = durationStr.replace(/:(\d(?::|$))/g, ':0\1')
return mins + ':' + secs return durationStr
} }
}]) }])

14
app/js/locales/en-us.json

@ -414,6 +414,8 @@
"error_modal_channel_not_accessible": "Sorry, this channel is not accessible.", "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_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_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", "head_telegram": "Telegram",
@ -509,12 +511,14 @@
"login_generating_key": "Generating keys", "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_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_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_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_code_not_received_call": "Send code via Call",
"login_call_remaining": "Telegram will call you in {remaining}", "login_code_requesting": "Requesting code",
"login_calling": "Telegram is calling you",
"login_number_dialed": "Telegram dialed your number",
"login_incorrect_sms_code": "Incorrect SMS code", "login_incorrect_sms_code": "Incorrect SMS code",
"login_number_input_placeholder": "Enter your code", "login_number_input_placeholder": "Enter your code",
"login_checking_code": "Checking code", "login_checking_code": "Checking code",

5
app/partials/desktop/error_modal.html

@ -48,6 +48,11 @@
<span ng-switch-when="PEER_FLOOD" my-i18n="error_modal_not_contact_flood"> <span ng-switch-when="PEER_FLOOD" my-i18n="error_modal_not_contact_flood">
<my-i18n-param name="more-info-link"><a href="https://telegram.me/spambot">{0}</a></my-i18n-param> <my-i18n-param name="more-info-link"><a href="https://telegram.me/spambot">{0}</a></my-i18n-param>
</span> </span>
<span ng-switch-when="2FA_RECENT_CONFIRM" my-i18n="error_modal_2fa_recent_confirm"></span>
<span ng-switch-when="2FA_CONFIRM_WAIT_TIME" my-i18n="error_modal_2fa_delayed_time_md">
<my-i18n-param name="time"><span ng-bind="error.waitTime | duration"></span></my-i18n-param>
</span>
<span ng-switch-when="CALLBACK_RESPONSE" ng-bind-html="error.description_html"></span> <span ng-switch-when="CALLBACK_RESPONSE" ng-bind-html="error.description_html"></span>

32
app/partials/desktop/login.html

@ -33,7 +33,7 @@
<div class="md-input-group md-input-has-value login_phone_country_input_group" ng-click="chooseCountry()"> <div class="md-input-group md-input-has-value login_phone_country_input_group" ng-click="chooseCountry()">
<label class="md-input-label" my-i18n="login_country_select_placeholder"></label> <label class="md-input-label" my-i18n="login_country_select_placeholder"></label>
<div autocomplete="off" class="md-input"ng-bind="credentials.phone_country_name"></div> <div autocomplete="off" class="md-input" ng-bind="credentials.phone_country_name"></div>
</div> </div>
<div class="login_phone_groups_wrap clearfix"> <div class="login_phone_groups_wrap clearfix">
@ -59,29 +59,29 @@
<div ng-switch="credentials.type._"> <div ng-switch="credentials.type._">
<p ng-switch-when="auth.sentCodeTypeApp" class="login_smscode_lead" my-i18n="login_enter_code_label_md"></p> <p ng-switch-when="auth.sentCodeTypeApp" class="login_smscode_lead" my-i18n="login_enter_code_label_md"></p>
<p ng-switch-when="auth.sentCodeTypeCall" class="login_smscode_lead" my-i18n="login_enter_call_code_label_md"></p>
<p ng-switch-default class="login_smscode_lead" my-i18n="login_enter_sms_code_label_md"></p> <p ng-switch-default class="login_smscode_lead" my-i18n="login_enter_sms_code_label_md"></p>
</div> </div>
<div ng-if="nextPending.type" ng-switch="nextPending.remaining === false"> <div ng-if="nextPending.type" ng-switch="nextPending.remaining > 0">
<p ng-switch-when="true" class="login_smscode_lead"> <p ng-switch-when="true" class="login_smscode_lead">
<a ng-click="sendNext()" my-i18n="login_code_not_received"></a> <span ng-switch="nextPending.type._" my-i18n>
</p> <span ng-switch-when="auth.codeTypeCall" my-i18n-format="login_call_remaining"></span>
<p ng-switch-default class="login_smscode_lead"> <span ng-switch-default my-i18n-format="login_code_remaining"></span>
<span ng-show="nextPending.remaining > 0" my-i18n="login_call_remaining">
<my-i18n-param name="remaining" ng-bind="nextPending.remaining | duration"></my-i18n-param> <my-i18n-param name="remaining" ng-bind="nextPending.remaining | duration"></my-i18n-param>
</span> </span>
<span ng-show="!nextPending.remaining" my-i18n="login_calling"></span>
</p> </p>
</div> <p ng-switch-default class="login_smscode_lead" ng-switch="nextPending.progress">
<a ng-switch-when="true" ng-disabled class="disabled">
<div ng-if="credentials.type._ == 'auth.sentCodeTypeCall'"> <span my-i18n="login_code_requesting"></span><span my-loading-dots></span>
<p class="login_smscode_lead"> </a>
<span my-i18n="login_number_dialed"></span> <a ng-switch-default ng-click="sendNext()" ng-switch="nextPending.type._">
<span ng-switch-when="auth.codeTypeCall" my-i18n="login_code_not_received_call"></span>
<span ng-switch-default my-i18n="login_code_not_received"></span>
</a>
</p> </p>
</div> </div>
<div class="md-input-group md-input-group-centered" ng-class="{'md-input-error': error.field == 'phone_code'}" my-labeled-input ng-switch="error.field == 'phone_code'"> <div class="md-input-group md-input-group-centered" ng-class="{'md-input-error': error.field == 'phone_code'}" my-labeled-input ng-switch="error.field == 'phone_code'">
<label ng-switch-when="true" class="md-input-label" my-i18n="login_incorrect_sms_code"></label> <label ng-switch-when="true" class="md-input-label" my-i18n="login_incorrect_sms_code"></label>
<label ng-switch-default class="md-input-label" my-i18n="login_number_input_placeholder"></label> <label ng-switch-default class="md-input-label" my-i18n="login_number_input_placeholder"></label>
@ -96,13 +96,13 @@
<div class="md-input-group" ng-class="{'md-input-error': error.field == 'first_name'}" my-labeled-input ng-switch="error.field == 'first_name'"> <div class="md-input-group" ng-class="{'md-input-error': error.field == 'first_name'}" my-labeled-input ng-switch="error.field == 'first_name'">
<label ng-switch-when="true" class="md-input-label" my-i18n="login_incorrect_first_name"></label> <label ng-switch-when="true" class="md-input-label" my-i18n="login_incorrect_first_name"></label>
<label ng-switch-default class="md-input-label" my-i18n="login_first_name"></label> <label ng-switch-default class="md-input-label" my-i18n="login_first_name"></label>
<input autocomplete="off" class="md-input" my-focused name="first_name" type="text" ng-model="credentials.first_name" required /> <input autocomplete="off" class="md-input" my-focused name="first_name" type="text" ng-model="credentials.first_name" my-submit-on-enter required />
</div> </div>
<div class="md-input-group" ng-class="{'md-input-error': error.field == 'last_name'}" my-labeled-input ng-switch="error.field == 'last_name'"> <div class="md-input-group" ng-class="{'md-input-error': error.field == 'last_name'}" my-labeled-input ng-switch="error.field == 'last_name'">
<label ng-switch-when="true" class="md-input-label" my-i18n="login_incorrect_last_name"></label> <label ng-switch-when="true" class="md-input-label" my-i18n="login_incorrect_last_name"></label>
<label ng-switch-default class="md-input-label" my-i18n="login_last_name"></label> <label ng-switch-default class="md-input-label" my-i18n="login_last_name"></label>
<input autocomplete="off" class="md-input" name="last_name" type="text" ng-model="credentials.last_name" /> <input autocomplete="off" class="md-input" name="last_name" type="text" ng-model="credentials.last_name" my-submit-on-enter />
</div> </div>
</form> </form>

26
app/partials/mobile/login.html

@ -43,7 +43,7 @@
<div class="md-input-group md-input-has-value login_phone_country_input_group" ng-click="chooseCountry()"> <div class="md-input-group md-input-has-value login_phone_country_input_group" ng-click="chooseCountry()">
<label class="md-input-label" my-i18n="login_country_select_placeholder"></label> <label class="md-input-label" my-i18n="login_country_select_placeholder"></label>
<div autocomplete="off" class="md-input"ng-bind="credentials.phone_country_name"></div> <div autocomplete="off" class="md-input" ng-bind="credentials.phone_country_name"></div>
</div> </div>
<div class="login_phone_groups_wrap clearfix"> <div class="login_phone_groups_wrap clearfix">
@ -69,24 +69,26 @@
<div ng-switch="credentials.type._"> <div ng-switch="credentials.type._">
<p ng-switch-when="auth.sentCodeTypeApp" class="login_smscode_lead" my-i18n="login_enter_code_label_md"></p> <p ng-switch-when="auth.sentCodeTypeApp" class="login_smscode_lead" my-i18n="login_enter_code_label_md"></p>
<p ng-switch-when="auth.sentCodeTypeCall" class="login_smscode_lead" my-i18n="login_enter_call_code_label_md"></p>
<p ng-switch-default class="login_smscode_lead" my-i18n="login_enter_sms_code_label_md"></p> <p ng-switch-default class="login_smscode_lead" my-i18n="login_enter_sms_code_label_md"></p>
</div> </div>
<div ng-if="nextPending.type" ng-switch="nextPending.remaining === false"> <div ng-if="nextPending.type" ng-switch="nextPending.remaining > 0">
<p ng-switch-when="true" class="login_smscode_lead"> <p ng-switch-when="true" class="login_smscode_lead">
<a ng-click="sendNext()" my-i18n="login_code_not_received"></a> <span ng-switch="nextPending.type._" my-i18n>
</p> <span ng-switch-when="auth.codeTypeCall" my-i18n-format="login_call_remaining"></span>
<p ng-switch-default class="login_smscode_lead"> <span ng-switch-default my-i18n-format="login_code_remaining"></span>
<span ng-show="nextPending.remaining > 0" my-i18n="login_call_remaining">
<my-i18n-param name="remaining" ng-bind="nextPending.remaining | duration"></my-i18n-param> <my-i18n-param name="remaining" ng-bind="nextPending.remaining | duration"></my-i18n-param>
</span> </span>
<span ng-show="!nextPending.remaining" my-i18n="login_calling"></span>
</p> </p>
</div> <p ng-switch-default class="login_smscode_lead" ng-switch="nextPending.progress">
<a ng-switch-when="true" ng-disabled class="disabled">
<div ng-if="credentials.type._ == 'auth.sentCodeTypeCall'"> <span my-i18n="login_code_requesting"></span><span my-loading-dots></span>
<p class="login_smscode_lead"> </a>
<span my-i18n="login_number_dialed"></span> <a ng-switch-default ng-click="sendNext()" ng-switch="nextPending.type._">
<span ng-switch-when="auth.codeTypeCall" my-i18n="login_code_not_received_call"></span>
<span ng-switch-default my-i18n="login_code_not_received"></span>
</a>
</p> </p>
</div> </div>

Loading…
Cancel
Save