Browse Source

Fixed baseDcId update for authorization

master
Igor Zhukov 11 years ago
parent
commit
9ca91d02c5
  1. 4
      app/index.html
  2. 10
      app/js/controllers.js
  3. 6
      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?5"></script>
<script type="text/javascript" src="js/lib/mtproto.js?6"></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?7"></script>
<script type="text/javascript" src="js/controllers.js?8"></script>
<script type="text/javascript" src="js/filters.js?3"></script>
<script type="text/javascript" src="js/directives.js?5"></script>

10
app/js/controllers.js

@ -22,13 +22,13 @@ angular.module('myApp.controllers', []) @@ -22,13 +22,13 @@ angular.module('myApp.controllers', [])
})
.controller('AppLoginController', function ($scope, $location, MtpApiManager, ErrorService) {
var dcID = 1;
var options = {dcID: 1};
$scope.credentials = {};
$scope.progress = {};
function saveAuth (result) {
MtpApiManager.setUserAuth(dcID, {
MtpApiManager.setUserAuth(options.dcID, {
expires: result.expires,
id: result.user.id
});
@ -40,7 +40,7 @@ angular.module('myApp.controllers', []) @@ -40,7 +40,7 @@ angular.module('myApp.controllers', [])
$scope.progress.enabled = true;
MtpApiManager.invokeApi('auth.checkPhone', {
phone_number: $scope.credentials.phone_number
}, {dcID: dcID}).then(function (result) {
}, options).then(function (result) {
$scope.progress.enabled = false;
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.');
@ -53,7 +53,7 @@ angular.module('myApp.controllers', []) @@ -53,7 +53,7 @@ angular.module('myApp.controllers', [])
sms_type: 0,
api_id: 2496,
api_hash: '8da85b0d5bfe62527e5b244c209159c3'
}, {dcID: dcID}).then(function (sentCode) {
}, options).then(function (sentCode) {
$scope.progress.enabled = false;
$scope.credentials.phone_code_hash = sentCode.phone_code_hash;
@ -98,7 +98,7 @@ angular.module('myApp.controllers', []) @@ -98,7 +98,7 @@ angular.module('myApp.controllers', [])
}
$scope.progress.enabled = true;
MtpApiManager.invokeApi(method, params, {dcID: dcID}).then(saveAuth, function (error) {
MtpApiManager.invokeApi(method, params, options).then(saveAuth, function (error) {
$scope.progress.enabled = false;
if (error.code == 400 && error.type == 'PHONE_NUMBER_UNOCCUPIED') {
return $scope.logIn(true);

6
app/js/lib/mtproto.js

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

Loading…
Cancel
Save