mirror of
https://github.com/element-hq/synapse
synced 2024-08-19 01:00:54 +00:00
Re-apply fixes to the link-email screen to make it work again (in a somewhat temporary way until home servers sign associations). Unhide the linked emails box.
This commit is contained in:
parent
b1b57a3f28
commit
eb7d7ce354
2 changed files with 54 additions and 27 deletions
|
@ -19,6 +19,17 @@ limitations under the License.
|
||||||
angular.module('SettingsController', ['matrixService', 'mFileUpload', 'mFileInput'])
|
angular.module('SettingsController', ['matrixService', 'mFileUpload', 'mFileInput'])
|
||||||
.controller('SettingsController', ['$scope', 'matrixService', 'mFileUpload',
|
.controller('SettingsController', ['$scope', 'matrixService', 'mFileUpload',
|
||||||
function($scope, matrixService, mFileUpload) {
|
function($scope, matrixService, mFileUpload) {
|
||||||
|
// XXX: duplicated from register
|
||||||
|
var generateClientSecret = function() {
|
||||||
|
var ret = "";
|
||||||
|
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
|
||||||
|
for (var i = 0; i < 32; i++) {
|
||||||
|
ret += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
$scope.config = matrixService.config();
|
$scope.config = matrixService.config();
|
||||||
|
|
||||||
$scope.profile = {
|
$scope.profile = {
|
||||||
|
@ -106,16 +117,22 @@ angular.module('SettingsController', ['matrixService', 'mFileUpload', 'mFileInpu
|
||||||
$scope.linkedEmails = {
|
$scope.linkedEmails = {
|
||||||
linkNewEmail: "", // the email entry box
|
linkNewEmail: "", // the email entry box
|
||||||
emailBeingAuthed: undefined, // to populate verification text
|
emailBeingAuthed: undefined, // to populate verification text
|
||||||
authTokenId: undefined, // the token id from the IS
|
authSid: undefined, // the token id from the IS
|
||||||
emailCode: "", // the code entry box
|
emailCode: "", // the code entry box
|
||||||
linkedEmailList: matrixService.config().emailList // linked email list
|
linkedEmailList: matrixService.config().emailList // linked email list
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.linkEmail = function(email) {
|
$scope.linkEmail = function(email) {
|
||||||
matrixService.linkEmail(email).then(
|
if (email != $scope.linkedEmails.emailBeingAuthed) {
|
||||||
|
$scope.linkedEmails.emailBeingAuthed = email;
|
||||||
|
$scope.clientSecret = generateClientSecret();
|
||||||
|
$scope.sendAttempt = 0;
|
||||||
|
}
|
||||||
|
$scope.sendAttempt++;
|
||||||
|
matrixService.linkEmail(email, $scope.clientSecret, $scope.sendAttempt).then(
|
||||||
function(response) {
|
function(response) {
|
||||||
if (response.data.success === true) {
|
if (response.data.success === true) {
|
||||||
$scope.linkedEmails.authTokenId = response.data.tokenId;
|
$scope.linkedEmails.authSid = response.data.sid;
|
||||||
$scope.emailFeedback = "You have been sent an email.";
|
$scope.emailFeedback = "You have been sent an email.";
|
||||||
$scope.linkedEmails.emailBeingAuthed = email;
|
$scope.linkedEmails.emailBeingAuthed = email;
|
||||||
}
|
}
|
||||||
|
@ -129,34 +146,44 @@ angular.module('SettingsController', ['matrixService', 'mFileUpload', 'mFileInpu
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.submitEmailCode = function(code) {
|
$scope.submitEmailCode = function() {
|
||||||
var tokenId = $scope.linkedEmails.authTokenId;
|
var tokenId = $scope.linkedEmails.authSid;
|
||||||
if (tokenId === undefined) {
|
if (tokenId === undefined) {
|
||||||
$scope.emailFeedback = "You have not requested a code with this email.";
|
$scope.emailFeedback = "You have not requested a code with this email.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
matrixService.authEmail(matrixService.config().user_id, tokenId, code).then(
|
matrixService.authEmail($scope.clientSecret, $scope.linkedEmails.authSid, $scope.linkedEmails.emailCode).then(
|
||||||
function(response) {
|
function(response) {
|
||||||
if ("success" in response.data && response.data.success === false) {
|
if ("errcode" in response.data) {
|
||||||
$scope.emailFeedback = "Failed to authenticate email.";
|
$scope.emailFeedback = "Failed to authenticate email.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var config = matrixService.config();
|
matrixService.bindEmail(matrixService.config().user_id, tokenId, $scope.clientSecret).then(
|
||||||
var emailList = {};
|
function(response) {
|
||||||
if ("emailList" in config) {
|
if ('errcode' in response.data) {
|
||||||
emailList = config.emailList;
|
$scope.emailFeedback = "Failed to link email.";
|
||||||
}
|
return;
|
||||||
emailList[response.address] = response;
|
}
|
||||||
// save the new email list
|
var config = matrixService.config();
|
||||||
config.emailList = emailList;
|
var emailList = {};
|
||||||
matrixService.setConfig(config);
|
if ("emailList" in config) {
|
||||||
matrixService.saveConfig();
|
emailList = config.emailList;
|
||||||
// invalidate the email being authed and update UI.
|
}
|
||||||
$scope.linkedEmails.emailBeingAuthed = undefined;
|
emailList[$scope.linkedEmails.emailBeingAuthed] = response;
|
||||||
$scope.emailFeedback = "";
|
// save the new email list
|
||||||
$scope.linkedEmails.linkedEmailList = emailList;
|
config.emailList = emailList;
|
||||||
$scope.linkedEmails.linkNewEmail = "";
|
matrixService.setConfig(config);
|
||||||
$scope.linkedEmails.emailCode = "";
|
matrixService.saveConfig();
|
||||||
|
// invalidate the email being authed and update UI.
|
||||||
|
$scope.linkedEmails.emailBeingAuthed = undefined;
|
||||||
|
$scope.emailFeedback = "";
|
||||||
|
$scope.linkedEmails.linkedEmailList = emailList;
|
||||||
|
$scope.linkedEmails.linkNewEmail = "";
|
||||||
|
$scope.linkedEmails.emailCode = "";
|
||||||
|
}, function(reason) {
|
||||||
|
$scope.emailFeedback = "Failed to link email: " + reason;
|
||||||
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
function(reason) {
|
function(reason) {
|
||||||
$scope.emailFeedback = "Failed to auth email: " + reason;
|
$scope.emailFeedback = "Failed to auth email: " + reason;
|
||||||
|
@ -182,4 +209,4 @@ angular.module('SettingsController', ['matrixService', 'mFileUpload', 'mFileInpu
|
||||||
$scope.settings.notifications = permission;
|
$scope.settings.notifications = permission;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -23,14 +23,14 @@
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<h3 style="display: none; ">Linked emails</h3>
|
<h3>Linked emails</h3>
|
||||||
<div class="section" style="display: none; ">
|
<div class="section">
|
||||||
<form>
|
<form>
|
||||||
<input size="40" ng-model="linkedEmails.linkNewEmail" ng-enter="linkEmail(linkedEmails.linkNewEmail)" />
|
<input size="40" ng-model="linkedEmails.linkNewEmail" ng-enter="linkEmail(linkedEmails.linkNewEmail)" />
|
||||||
<button ng-disabled="!linkedEmails.linkNewEmail" ng-click="linkEmail(linkedEmails.linkNewEmail)">
|
<button ng-disabled="!linkedEmails.linkNewEmail" ng-click="linkEmail(linkedEmails.linkNewEmail)">
|
||||||
Link Email
|
Link Email
|
||||||
</button>
|
</button>
|
||||||
{{ emailFeedback }}
|
{{ emailFeedback }}
|
||||||
</form>
|
</form>
|
||||||
<form ng-hide="!linkedEmails.emailBeingAuthed">
|
<form ng-hide="!linkedEmails.emailBeingAuthed">
|
||||||
Enter validation token for {{ linkedEmails.emailBeingAuthed }}:
|
Enter validation token for {{ linkedEmails.emailBeingAuthed }}:
|
||||||
|
|
Loading…
Reference in a new issue