1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Add API calls for other requestToken endpoints

This commit is contained in:
David Baker
2016-07-08 17:24:59 +01:00
parent abf903246c
commit 03d0aecc26

View File

@@ -2807,6 +2807,61 @@ MatrixClient.prototype.register = function(username, password,
*/ */
MatrixClient.prototype.requestRegisterEmailToken = function(email, clientSecret, MatrixClient.prototype.requestRegisterEmailToken = function(email, clientSecret,
sendAttempt, nextLink, callback) { sendAttempt, nextLink, callback) {
return this._requestTokenFromEndpoint(
"/register/email/requestToken", email, clientSecret, sendAttempt, nextLink, callback
);
};
/**
* Requests an email verification token for the purposes of adding a
* third party identifier to an account.
* This API proxies the Identity Server /validate/email/requestToken API,
* adding specific behaviour for the addition of email addresses to an
* account. Specifically, if an account with
* the given email address already exists, it will either send an email
* to the address informing them of this or return M_THREEPID_IN_USE
* (which one is up to the Home Server).
*
* requestEmailToken calls the equivalent API directly on the ID server,
* therefore bypassing the email addition specific logic.
*
* Parameters and return value are as for requestEmailToken
*/
MatrixClient.prototype.request3pidAddEmailToken = function(email, clientSecret,
sendAttempt, nextLink, callback) {
return this._requestTokenFromEndpoint(
"/account/3pid/email/requestToken", email, clientSecret, sendAttempt, nextLink, callback
);
};
/**
* Requests an email verification token for the purposes of resetting
* the password on an account.
* This API proxies the Identity Server /validate/email/requestToken API,
* adding specific behaviour for the password resetting. Specifically,
* if no account with the given email address exists, it may either
* return M_THREEPID_NOT_FOUND or send an email
* to the address informing them of this (which one is up to the Home Server).
*
* requestEmailToken calls the equivalent API directly on the ID server,
* therefore bypassing the password reset specific logic.
*
* Parameters and return value are as for requestEmailToken
*/
MatrixClient.prototype.requestPasswordEmailToken = function(email, clientSecret,
sendAttempt, nextLink, callback) {
return this._requestTokenFromEndpoint(
"/account/password/email/requestToken", email, clientSecret, sendAttempt, nextLink, callback
);
};
/**
* Internal utility function for requesting validation tokens from usage-specific
* requestToken endpoints.
*/
MatrixClient.prototype._requestTokenFromEndpoint = function(endpoint,
email, clientSecret,
sendAttempt, nextLink, callback) {
var id_server_url = url.parse(this.idBaseUrl); var id_server_url = url.parse(this.idBaseUrl);
if (id_server_url.host === null) { if (id_server_url.host === null) {
throw new Error("Invalid ID server URL: " + this.idBaseUrl); throw new Error("Invalid ID server URL: " + this.idBaseUrl);
@@ -2820,7 +2875,7 @@ MatrixClient.prototype.requestRegisterEmailToken = function(email, clientSecret,
id_server: id_server_url.host, id_server: id_server_url.host,
}; };
return this._http.request( return this._http.request(
callback, "POST", "/register/email/requestToken", undefined, callback, "POST", endpoint, undefined,
params params
); );
}; };