set email branding after registration

This commit is contained in:
Matthew Hodgson 2016-06-02 13:14:52 +01:00
parent 83fd02bdfa
commit 1d31463140
3 changed files with 24 additions and 9 deletions

View file

@ -51,7 +51,6 @@ class Register extends Signup {
this.username = undefined; // desired
this.email = undefined; // desired
this.password = undefined; // desired
this.brand = undefined; // optional brand to let the HS brand its mail notifs
}
setClientSecret(secret) {
@ -74,10 +73,6 @@ class Register extends Signup {
this.guestAccessToken = token;
}
setBrand(brand) {
this.brand = brand;
}
getStep() {
return this._step;
}
@ -136,7 +131,7 @@ class Register extends Signup {
return MatrixClientPeg.get().register(
this.username, this.password, this.params.sessionId, authDict, bindEmail,
this.guestAccessToken, this.brand
this.guestAccessToken
).then(function(result) {
self.credentials = result;
self.setStep("COMPLETE");

View file

@ -100,7 +100,7 @@ module.exports = {
return this.getEmailPusher(pushers, address) !== undefined;
},
addEmailPusher: function(address) {
addEmailPusher: function(address, data) {
return MatrixClientPeg.get().setPusher({
kind: 'email',
app_id: "m.email",
@ -108,7 +108,7 @@ module.exports = {
app_display_name: 'Email Notifications',
device_display_name: address,
lang: navigator.language,
data: {},
data: data,
append: true, // We always append for email pushers since we don't want to stop other accounts notifying to the same email address
});
},

View file

@ -22,6 +22,7 @@ var sdk = require('../../../index');
var dis = require('../../../dispatcher');
var Signup = require("../../../Signup");
var ServerConfig = require("../../views/login/ServerConfig");
var MatrixClientPeg = require("../../../MatrixClientPeg");
var RegistrationForm = require("../../views/login/RegistrationForm");
var CaptchaForm = require("../../views/login/CaptchaForm");
@ -67,7 +68,6 @@ module.exports = React.createClass({
this.registerLogic.setRegistrationUrl(this.props.registrationUrl);
this.registerLogic.setIdSid(this.props.idSid);
this.registerLogic.setGuestAccessToken(this.props.guestAccessToken);
this.registerLogic.setBrand(this.props.brand);
this.registerLogic.recheckState();
},
@ -147,6 +147,26 @@ module.exports = React.createClass({
identityServerUrl: self.registerLogic.getIdentityServerUrl(),
accessToken: response.access_token
});
if (self.props.brand) {
MatrixClientPeg.get().getPushers().done((resp)=>{
var pushers = resp.pushers;
for (var i = 0; i < pushers.length; ++i) {
if (pushers[i].kind == 'email') {
var emailPusher = pushers[i];
emailPusher.data = { brand: self.props.brand };
MatrixClientPeg.get().setPusher(emailPusher).done(() => {
console.log("Set email branding to " + self.props.brand);
}, (error) => {
console.error("Couldn't set email branding: " + error);
});
}
}
}, (error) => {
console.error("Couldn't get pushers: " + error);
});
}
}, function(err) {
if (err.message) {
self.setState({