Browse Source

fixed send sms on unregistered number

master
Igor Zhukov 11 years ago
parent
commit
b09a290674
  1. 4
      app/index.html
  2. 48
      app/js/controllers.js
  3. 15
      app/js/lib/mtproto.js

4
app/index.html

@ -33,12 +33,12 @@ @@ -33,12 +33,12 @@
<script type="text/javascript" src="js/lib/config.js"></script>
<script type="text/javascript" src="js/lib/mtproto.js?2"></script>
<script type="text/javascript" src="js/lib/mtproto.js?3"></script>
<script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript" src="js/app.js?3"></script>
<script type="text/javascript" src="js/services.js?6"></script>
<script type="text/javascript" src="js/controllers.js?5"></script>
<script type="text/javascript" src="js/controllers.js?6"></script>
<script type="text/javascript" src="js/filters.js?3"></script>
<script type="text/javascript" src="js/directives.js?5"></script>

48
app/js/controllers.js

@ -38,34 +38,40 @@ angular.module('myApp.controllers', []) @@ -38,34 +38,40 @@ angular.module('myApp.controllers', [])
$scope.sendCode = function () {
$scope.progress.enabled = true;
MtpApiManager.invokeApi('auth.sendCode', {
phone_number: $scope.credentials.phone_number,
sms_type: 0,
api_id: 2496,
api_hash: '8da85b0d5bfe62527e5b244c209159c3'
}, {dcID: dcID}).then(function (sentCode) {
MtpApiManager.invokeApi('auth.checkPhone', {
phone_number: $scope.credentials.phone_number
}, {dcID: dcID}).then(function (result) {
$scope.progress.enabled = false;
if (!sentCode.phone_registered) {
if (!result.phone_registered) {
ErrorService.showSimpleError('No account', 'Sorry, there is no Telegram account for ' + $scope.credentials.phone_number + '. Please sign up using our mobile apps.');
return false;
}
$scope.credentials.phone_code_hash = sentCode.phone_code_hash;
$scope.credentials.phone_occupied = sentCode.phone_registered;
$scope.error = {};
$scope.progress.enabled = true;
MtpApiManager.invokeApi('auth.sendCode', {
phone_number: $scope.credentials.phone_number,
sms_type: 0,
api_id: 2496,
api_hash: '8da85b0d5bfe62527e5b244c209159c3'
}, {dcID: dcID}).then(function (sentCode) {
$scope.progress.enabled = false;
$scope.credentials.phone_code_hash = sentCode.phone_code_hash;
$scope.credentials.phone_occupied = sentCode.phone_registered;
$scope.error = {};
}, function (error) {
$scope.progress.enabled = false;
dLog('sendCode error', error);
switch (error.type) {
case 'PHONE_NUMBER_INVALID':
$scope.error = {field: 'phone'};
break;
}
});
}, function (error) {
$scope.progress.enabled = false;
dLog('sendCode', error);
if (error.code == 303) {
var newDcID = error.type.match(/^(PHONE_MIGRATE_|NETWORK_MIGRATE_)(\d+)/)[2];
if (newDcID != dcID) {
dcID = newDcID;
$scope.sendCode();
return;
}
}
dLog('checkPhone error', error);
switch (error.type) {
case 'PHONE_NUMBER_INVALID':
$scope.error = {field: 'phone'};

15
app/js/lib/mtproto.js

@ -2240,7 +2240,20 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker @@ -2240,7 +2240,20 @@ factory('MtpApiManager', function (AppConfigManager, MtpAuthorizer, MtpNetworker
}, function (error) {
deferred.reject(error);
});
} else {
}
else if (error.code == 303) {
var newDcID = error.type.match(/^(PHONE_MIGRATE_|NETWORK_MIGRATE_)(\d+)/)[2];
if (newDcID != dcID) {
mtpGetNetworker(newDcID).then(function (networker) {
networker.wrapApiCall(method, params, options).then(function (result) {
deferred.resolve(result);
}, function (error) {
deferred.reject(error);
});
});
}
}
else {
deferred.reject(error);
}
});

Loading…
Cancel
Save