Browse Source

Https mixed content workaround

Fix #237
master
Igor Zhukov 11 years ago
parent
commit
b7cf8f36ba
  1. 20
      app/js/controllers.js
  2. 22
      app/js/lib/mtproto.js
  3. 5
      app/partials/confirm_modal.html
  4. 7
      app/partials/error_modal.html

20
app/js/controllers.js

@ -155,6 +155,15 @@ angular.module('myApp.controllers', [])
}, function (error) { }, function (error) {
$scope.progress.enabled = false; $scope.progress.enabled = false;
switch (error.type) { switch (error.type) {
case 'NETWORK_BAD_REQUEST':
if (location.protocol == 'https:') {
ErrorService.confirm({type: 'HTTPS_MIXED_FAIL'}).then(function () {
location = location.toString().replace('/^https:/', 'http:');
});
error.handled = true;
}
break;
case 'PHONE_NUMBER_INVALID': case 'PHONE_NUMBER_INVALID':
$scope.error = {field: 'phone'}; $scope.error = {field: 'phone'};
error.handled = true; error.handled = true;
@ -282,7 +291,7 @@ angular.module('myApp.controllers', [])
} }
}) })
.controller('AppImDialogsController', function ($scope, $location, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager) { .controller('AppImDialogsController', function ($scope, $location, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager, ErrorService) {
// console.log('init controller'); // console.log('init controller');
@ -374,6 +383,15 @@ angular.module('myApp.controllers', [])
} }
}, function (error) { }, function (error) {
if (error.type == 'NETWORK_BAD_REQUEST') {
if (location.protocol == 'https:') {
ErrorService.confirm({type: 'HTTPS_MIXED_FAIL'}).then(function () {
location = location.toString().replace('/^https:/', 'http:');
});
error.handled = true;
}
}
if (error.code == 401) { if (error.code == 401) {
MtpApiManager.logOut()['finally'](function () { MtpApiManager.logOut()['finally'](function () {
$location.url('/login'); $location.url('/login');

22
app/js/lib/mtproto.js

@ -1196,14 +1196,25 @@ factory('MtpAuthorizer', function (MtpDcConfigurator, MtpRsaKeysManager, MtpSecu
transformResponse: function (responseBuffer) { transformResponse: function (responseBuffer) {
var deserializer = new TLDeserialization(responseBuffer, {mtproto: true}); var deserializer = new TLDeserialization(responseBuffer, {mtproto: true});
var auth_key_id = deserializer.fetchLong('auth_key_id'); try {
var msg_id = deserializer.fetchLong('msg_id');
var msg_len = deserializer.fetchInt('msg_len'); var auth_key_id = deserializer.fetchLong('auth_key_id');
var msg_id = deserializer.fetchLong('msg_id');
var msg_len = deserializer.fetchInt('msg_len');
} catch (e) {
return $q.reject({code: 406, type: 'NETWORK_BAD_RESPONSE', problem: e.message, stack: e.stack});
}
rng_seed_time(); rng_seed_time();
return deserializer; return deserializer;
} }
})['catch'](function (error) {
if (!error.message && !error.type) {
error = {code: 406, type: 'NETWORK_BAD_REQUEST'};
}
return $q.reject(error);
}); });
}; };
@ -2189,6 +2200,11 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato
return $http.post('http://' + MtpDcConfigurator.chooseServer(self.dcID) + '/apiw1', resultArray, { return $http.post('http://' + MtpDcConfigurator.chooseServer(self.dcID) + '/apiw1', resultArray, {
responseType: 'arraybuffer', responseType: 'arraybuffer',
transformRequest: null transformRequest: null
})['catch'](function (error) {
if (!error.message && !error.type) {
error = {code: 406, type: 'NETWORK_BAD_REQUEST'};
}
return $q.reject(error);
}); });
}); });
}; };

5
app/partials/confirm_modal.html

@ -9,6 +9,11 @@
<span ng-switch-when="WEBOGRAM_UPDATED_RELOAD">A new version of Webogram is available. Load it?</span> <span ng-switch-when="WEBOGRAM_UPDATED_RELOAD">A new version of Webogram is available. Load it?</span>
<span ng-switch-when="HISTORY_FLUSH">Are you sure? This can not be undone!</span> <span ng-switch-when="HISTORY_FLUSH">Are you sure? This can not be undone!</span>
<span ng-switch-when="TERMINATE_SESSIONS">Are you sure you want to log out all devices except for the current one?</span> <span ng-switch-when="TERMINATE_SESSIONS">Are you sure you want to log out all devices except for the current one?</span>
<span ng-switch-when="HTTPS_MIXED_FAIL">
Your browser does not support mixed content which is neccessary for MTProto support on https. <a href="https://github.com/zhukov/webogram/issues/237" target="_blank">Learn more &rarr;</a><br/>
Would you like use http-version instead?
</span>
<span ng-switch-when="FILES_CLIPBOARD_PASTE"> <span ng-switch-when="FILES_CLIPBOARD_PASTE">
<ng-pluralize count="files.length" <ng-pluralize count="files.length"
when="{'one': 'Are you sure to send file from clipboard?', 'other': 'Are you sure to send {} files from clipboard?'}"> when="{'one': 'Are you sure to send file from clipboard?', 'other': 'Are you sure to send {} files from clipboard?'}">

7
app/partials/error_modal.html

@ -10,6 +10,7 @@
<span ng-switch-when="401">Unauthorized</span> <span ng-switch-when="401">Unauthorized</span>
<span ng-switch-when="403">Access denied</span> <span ng-switch-when="403">Access denied</span>
<span ng-switch-when="404">Not found</span> <span ng-switch-when="404">Not found</span>
<span ng-switch-when="406">Network error</span>
<span ng-switch-when="420">Too fast</span> <span ng-switch-when="420">Too fast</span>
<span ng-switch-default>Server error</span> <span ng-switch-default>Server error</span>
</span> </span>
@ -20,6 +21,12 @@
<div class="modal-body"> <div class="modal-body">
<div ng-if="error" class="error_modal_description" ng-switch="error.type"> <div ng-if="error" class="error_modal_description" ng-switch="error.type">
<span ng-switch-when="NETWORK_BAD_REQUEST">
Please check your internet connection.
</span>
<span ng-switch-when="NETWORK_BAD_RESPONSE">
Please check your internet connection.
</span>
<span ng-switch-when="FIRSTNAME_INVALID"> <span ng-switch-when="FIRSTNAME_INVALID">
The first name you entered is invalid. The first name you entered is invalid.
</span> </span>

Loading…
Cancel
Save