mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 02:05:45 +03:00
Merge pull request #413 from matrix-org/rav/device_display_name
Set initial_device_display_name on login and register
This commit is contained in:
commit
7992042526
5 changed files with 47 additions and 15 deletions
|
@ -69,6 +69,7 @@ export function loadSession(opts) {
|
||||||
let enableGuest = opts.enableGuest || false;
|
let enableGuest = opts.enableGuest || false;
|
||||||
const guestHsUrl = opts.guestHsUrl;
|
const guestHsUrl = opts.guestHsUrl;
|
||||||
const guestIsUrl = opts.guestIsUrl;
|
const guestIsUrl = opts.guestIsUrl;
|
||||||
|
const defaultDeviceDisplayName = opts.defaultDeviceDisplayName;
|
||||||
|
|
||||||
if (fragmentQueryParams.client_secret && fragmentQueryParams.sid) {
|
if (fragmentQueryParams.client_secret && fragmentQueryParams.sid) {
|
||||||
// this happens during email validation: the email contains a link to the
|
// this happens during email validation: the email contains a link to the
|
||||||
|
@ -87,7 +88,7 @@ export function loadSession(opts) {
|
||||||
if (!realQueryParams.homeserver) {
|
if (!realQueryParams.homeserver) {
|
||||||
console.warn("Cannot log in with token: can't determine HS URL to use");
|
console.warn("Cannot log in with token: can't determine HS URL to use");
|
||||||
} else {
|
} else {
|
||||||
return _loginWithToken(realQueryParams);
|
return _loginWithToken(realQueryParams, defaultDeviceDisplayName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,20 +112,25 @@ export function loadSession(opts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enableGuest) {
|
if (enableGuest) {
|
||||||
return _registerAsGuest(guestHsUrl, guestIsUrl);
|
return _registerAsGuest(guestHsUrl, guestIsUrl, defaultDeviceDisplayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fall back to login screen
|
// fall back to login screen
|
||||||
return q();
|
return q();
|
||||||
}
|
}
|
||||||
|
|
||||||
function _loginWithToken(queryParams) {
|
function _loginWithToken(queryParams, defaultDeviceDisplayName) {
|
||||||
// create a temporary MatrixClient to do the login
|
// create a temporary MatrixClient to do the login
|
||||||
var client = Matrix.createClient({
|
var client = Matrix.createClient({
|
||||||
baseUrl: queryParams.homeserver,
|
baseUrl: queryParams.homeserver,
|
||||||
});
|
});
|
||||||
|
|
||||||
return client.loginWithToken(queryParams.loginToken).then(function(data) {
|
return client.login(
|
||||||
|
"m.login.token", {
|
||||||
|
token: queryParams.loginToken,
|
||||||
|
initial_device_display_name: defaultDeviceDisplayName,
|
||||||
|
},
|
||||||
|
).then(function(data) {
|
||||||
console.log("Logged in with token");
|
console.log("Logged in with token");
|
||||||
setLoggedIn({
|
setLoggedIn({
|
||||||
userId: data.user_id,
|
userId: data.user_id,
|
||||||
|
@ -139,15 +145,22 @@ function _loginWithToken(queryParams) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function _registerAsGuest(hsUrl, isUrl) {
|
function _registerAsGuest(hsUrl, isUrl, defaultDeviceDisplayName) {
|
||||||
console.log("Doing guest login on %s", hsUrl);
|
console.log("Doing guest login on %s", hsUrl);
|
||||||
|
|
||||||
|
// TODO: we should probably de-duplicate this and Signup.Login.loginAsGuest.
|
||||||
|
// Not really sure where the right home for it is.
|
||||||
|
|
||||||
// create a temporary MatrixClient to do the login
|
// create a temporary MatrixClient to do the login
|
||||||
var client = Matrix.createClient({
|
var client = Matrix.createClient({
|
||||||
baseUrl: hsUrl,
|
baseUrl: hsUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
return client.registerGuest().then((creds) => {
|
return client.registerGuest({
|
||||||
|
body: {
|
||||||
|
initial_device_display_name: defaultDeviceDisplayName,
|
||||||
|
},
|
||||||
|
}).then((creds) => {
|
||||||
console.log("Registered as guest: %s", creds.user_id);
|
console.log("Registered as guest: %s", creds.user_id);
|
||||||
setLoggedIn({
|
setLoggedIn({
|
||||||
userId: creds.user_id,
|
userId: creds.user_id,
|
||||||
|
|
|
@ -14,9 +14,10 @@ const EMAIL_STAGE_TYPE = "m.login.email.identity";
|
||||||
* storage of HS/IS URLs.
|
* storage of HS/IS URLs.
|
||||||
*/
|
*/
|
||||||
class Signup {
|
class Signup {
|
||||||
constructor(hsUrl, isUrl) {
|
constructor(hsUrl, isUrl, opts) {
|
||||||
this._hsUrl = hsUrl;
|
this._hsUrl = hsUrl;
|
||||||
this._isUrl = isUrl;
|
this._isUrl = isUrl;
|
||||||
|
this._defaultDeviceDisplayName = opts.defaultDeviceDisplayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
getHomeserverUrl() {
|
getHomeserverUrl() {
|
||||||
|
@ -51,8 +52,8 @@ class Signup {
|
||||||
* Registration logic class
|
* Registration logic class
|
||||||
*/
|
*/
|
||||||
class Register extends Signup {
|
class Register extends Signup {
|
||||||
constructor(hsUrl, isUrl) {
|
constructor(hsUrl, isUrl, opts) {
|
||||||
super(hsUrl, isUrl);
|
super(hsUrl, isUrl, opts);
|
||||||
this.setStep("START");
|
this.setStep("START");
|
||||||
this.data = null; // from the server
|
this.data = null; // from the server
|
||||||
// random other stuff (e.g. query params, NOT params from the server)
|
// random other stuff (e.g. query params, NOT params from the server)
|
||||||
|
@ -135,6 +136,7 @@ class Register extends Signup {
|
||||||
bindEmail = true;
|
bindEmail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO need to figure out how to send the device display name to /register.
|
||||||
return client.register(
|
return client.register(
|
||||||
this.username, this.password, this.params.sessionId, authDict, bindEmail,
|
this.username, this.password, this.params.sessionId, authDict, bindEmail,
|
||||||
this.guestAccessToken
|
this.guestAccessToken
|
||||||
|
@ -295,8 +297,8 @@ class Register extends Signup {
|
||||||
|
|
||||||
|
|
||||||
class Login extends Signup {
|
class Login extends Signup {
|
||||||
constructor(hsUrl, isUrl, fallbackHsUrl) {
|
constructor(hsUrl, isUrl, fallbackHsUrl, opts) {
|
||||||
super(hsUrl, isUrl);
|
super(hsUrl, isUrl, opts);
|
||||||
this._fallbackHsUrl = fallbackHsUrl;
|
this._fallbackHsUrl = fallbackHsUrl;
|
||||||
this._currentFlowIndex = 0;
|
this._currentFlowIndex = 0;
|
||||||
this._flows = [];
|
this._flows = [];
|
||||||
|
@ -327,7 +329,11 @@ class Login extends Signup {
|
||||||
|
|
||||||
loginAsGuest() {
|
loginAsGuest() {
|
||||||
var client = this._createTemporaryClient();
|
var client = this._createTemporaryClient();
|
||||||
return client.registerGuest().then((creds) => {
|
return client.registerGuest({
|
||||||
|
body: {
|
||||||
|
initial_device_display_name: this._defaultDeviceDisplayName,
|
||||||
|
},
|
||||||
|
}).then((creds) => {
|
||||||
return {
|
return {
|
||||||
userId: creds.user_id,
|
userId: creds.user_id,
|
||||||
accessToken: creds.access_token,
|
accessToken: creds.access_token,
|
||||||
|
@ -349,7 +355,8 @@ class Login extends Signup {
|
||||||
var self = this;
|
var self = this;
|
||||||
var isEmail = username.indexOf("@") > 0;
|
var isEmail = username.indexOf("@") > 0;
|
||||||
var loginParams = {
|
var loginParams = {
|
||||||
password: pass
|
password: pass,
|
||||||
|
initial_device_display_name: this._defaultDeviceDisplayName,
|
||||||
};
|
};
|
||||||
if (isEmail) {
|
if (isEmail) {
|
||||||
loginParams.medium = 'email';
|
loginParams.medium = 'email';
|
||||||
|
|
|
@ -185,6 +185,7 @@ module.exports = React.createClass({
|
||||||
enableGuest: this.props.enableGuest,
|
enableGuest: this.props.enableGuest,
|
||||||
guestHsUrl: this.getCurrentHsUrl(),
|
guestHsUrl: this.getCurrentHsUrl(),
|
||||||
guestIsUrl: this.getCurrentIsUrl(),
|
guestIsUrl: this.getCurrentIsUrl(),
|
||||||
|
defaultDisplayName: this.props.config.default_device_name,
|
||||||
}).done(()=>{
|
}).done(()=>{
|
||||||
// stuff this through the dispatcher so that it happens
|
// stuff this through the dispatcher so that it happens
|
||||||
// after the on_logged_in action.
|
// after the on_logged_in action.
|
||||||
|
@ -1039,6 +1040,7 @@ module.exports = React.createClass({
|
||||||
customHsUrl={this.getCurrentHsUrl()}
|
customHsUrl={this.getCurrentHsUrl()}
|
||||||
customIsUrl={this.getCurrentIsUrl()}
|
customIsUrl={this.getCurrentIsUrl()}
|
||||||
registrationUrl={this.props.registrationUrl}
|
registrationUrl={this.props.registrationUrl}
|
||||||
|
defaultDeviceDisplayName={this.props.config.default_device_name}
|
||||||
onLoggedIn={this.onRegistered}
|
onLoggedIn={this.onRegistered}
|
||||||
onLoginClick={this.onLoginClick}
|
onLoginClick={this.onLoginClick}
|
||||||
onRegisterClick={this.onRegisterClick}
|
onRegisterClick={this.onRegisterClick}
|
||||||
|
@ -1065,6 +1067,7 @@ module.exports = React.createClass({
|
||||||
customHsUrl={this.getCurrentHsUrl()}
|
customHsUrl={this.getCurrentHsUrl()}
|
||||||
customIsUrl={this.getCurrentIsUrl()}
|
customIsUrl={this.getCurrentIsUrl()}
|
||||||
fallbackHsUrl={this.getFallbackHsUrl()}
|
fallbackHsUrl={this.getFallbackHsUrl()}
|
||||||
|
defaultDeviceDisplayName={this.props.config.default_device_name}
|
||||||
onForgotPasswordClick={this.onForgotPasswordClick}
|
onForgotPasswordClick={this.onForgotPasswordClick}
|
||||||
enableGuest={this.props.enableGuest}
|
enableGuest={this.props.enableGuest}
|
||||||
onCancelClick={this.guestCreds ? this.onReturnToGuestClick : null}
|
onCancelClick={this.guestCreds ? this.onReturnToGuestClick : null}
|
||||||
|
|
|
@ -44,6 +44,8 @@ module.exports = React.createClass({
|
||||||
// different home server without confusing users.
|
// different home server without confusing users.
|
||||||
fallbackHsUrl: React.PropTypes.string,
|
fallbackHsUrl: React.PropTypes.string,
|
||||||
|
|
||||||
|
defaultDeviceDisplayName: React.PropTypes.string,
|
||||||
|
|
||||||
// login shouldn't know or care how registration is done.
|
// login shouldn't know or care how registration is done.
|
||||||
onRegisterClick: React.PropTypes.func.isRequired,
|
onRegisterClick: React.PropTypes.func.isRequired,
|
||||||
|
|
||||||
|
@ -136,7 +138,9 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
var fallbackHsUrl = hsUrl == this.props.defaultHsUrl ? this.props.fallbackHsUrl : null;
|
var fallbackHsUrl = hsUrl == this.props.defaultHsUrl ? this.props.fallbackHsUrl : null;
|
||||||
|
|
||||||
var loginLogic = new Signup.Login(hsUrl, isUrl, fallbackHsUrl);
|
var loginLogic = new Signup.Login(hsUrl, isUrl, fallbackHsUrl, {
|
||||||
|
defaultDeviceDisplayName: this.props.defaultDeviceDisplayName,
|
||||||
|
});
|
||||||
this._loginLogic = loginLogic;
|
this._loginLogic = loginLogic;
|
||||||
|
|
||||||
loginLogic.getFlows().then(function(flows) {
|
loginLogic.getFlows().then(function(flows) {
|
||||||
|
|
|
@ -45,6 +45,9 @@ module.exports = React.createClass({
|
||||||
email: React.PropTypes.string,
|
email: React.PropTypes.string,
|
||||||
username: React.PropTypes.string,
|
username: React.PropTypes.string,
|
||||||
guestAccessToken: React.PropTypes.string,
|
guestAccessToken: React.PropTypes.string,
|
||||||
|
|
||||||
|
defaultDeviceDisplayName: React.PropTypes.string,
|
||||||
|
|
||||||
// registration shouldn't know or care how login is done.
|
// registration shouldn't know or care how login is done.
|
||||||
onLoginClick: React.PropTypes.func.isRequired,
|
onLoginClick: React.PropTypes.func.isRequired,
|
||||||
onCancelClick: React.PropTypes.func
|
onCancelClick: React.PropTypes.func
|
||||||
|
@ -71,7 +74,9 @@ module.exports = React.createClass({
|
||||||
this.dispatcherRef = dis.register(this.onAction);
|
this.dispatcherRef = dis.register(this.onAction);
|
||||||
// attach this to the instance rather than this.state since it isn't UI
|
// attach this to the instance rather than this.state since it isn't UI
|
||||||
this.registerLogic = new Signup.Register(
|
this.registerLogic = new Signup.Register(
|
||||||
this.props.customHsUrl, this.props.customIsUrl
|
this.props.customHsUrl, this.props.customIsUrl, {
|
||||||
|
defaultDeviceDisplayName: this.props.defaultDeviceDisplayName,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
this.registerLogic.setClientSecret(this.props.clientSecret);
|
this.registerLogic.setClientSecret(this.props.clientSecret);
|
||||||
this.registerLogic.setSessionId(this.props.sessionId);
|
this.registerLogic.setSessionId(this.props.sessionId);
|
||||||
|
|
Loading…
Reference in a new issue