mirror of https://github.com/vector-im/riot-web
Merge pull request #6635 from matrix-org/palid/dx/typescriptify-password-reset
Migrate PasswordReset.js to typescriptpull/21833/head
commit
36540a99b9
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createClient } from 'matrix-js-sdk/src/matrix';
|
import { createClient, IRequestTokenResponse, MatrixClient } from 'matrix-js-sdk/src/matrix';
|
||||||
import { _t } from './languageHandler';
|
import { _t } from './languageHandler';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,12 +26,18 @@ import { _t } from './languageHandler';
|
||||||
* API on the homeserver in question with the new password.
|
* API on the homeserver in question with the new password.
|
||||||
*/
|
*/
|
||||||
export default class PasswordReset {
|
export default class PasswordReset {
|
||||||
|
private client: MatrixClient;
|
||||||
|
private clientSecret: string;
|
||||||
|
private identityServerDomain: string;
|
||||||
|
private password: string;
|
||||||
|
private sessionId: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the endpoints for password resetting.
|
* Configure the endpoints for password resetting.
|
||||||
* @param {string} homeserverUrl The URL to the HS which has the account to reset.
|
* @param {string} homeserverUrl The URL to the HS which has the account to reset.
|
||||||
* @param {string} identityUrl The URL to the IS which has linked the email -> mxid mapping.
|
* @param {string} identityUrl The URL to the IS which has linked the email -> mxid mapping.
|
||||||
*/
|
*/
|
||||||
constructor(homeserverUrl, identityUrl) {
|
constructor(homeserverUrl: string, identityUrl: string) {
|
||||||
this.client = createClient({
|
this.client = createClient({
|
||||||
baseUrl: homeserverUrl,
|
baseUrl: homeserverUrl,
|
||||||
idBaseUrl: identityUrl,
|
idBaseUrl: identityUrl,
|
||||||
|
@ -47,7 +53,7 @@ export default class PasswordReset {
|
||||||
* @param {string} newPassword The new password for the account.
|
* @param {string} newPassword The new password for the account.
|
||||||
* @return {Promise} Resolves when the email has been sent. Then call checkEmailLinkClicked().
|
* @return {Promise} Resolves when the email has been sent. Then call checkEmailLinkClicked().
|
||||||
*/
|
*/
|
||||||
resetPassword(emailAddress, newPassword) {
|
public resetPassword(emailAddress, newPassword): Promise<IRequestTokenResponse> {
|
||||||
this.password = newPassword;
|
this.password = newPassword;
|
||||||
return this.client.requestPasswordEmailToken(emailAddress, this.clientSecret, 1).then((res) => {
|
return this.client.requestPasswordEmailToken(emailAddress, this.clientSecret, 1).then((res) => {
|
||||||
this.sessionId = res.sid;
|
this.sessionId = res.sid;
|
||||||
|
@ -69,7 +75,7 @@ export default class PasswordReset {
|
||||||
* with a "message" property which contains a human-readable message detailing why
|
* with a "message" property which contains a human-readable message detailing why
|
||||||
* the reset failed, e.g. "There is no mapped matrix user ID for the given email address".
|
* the reset failed, e.g. "There is no mapped matrix user ID for the given email address".
|
||||||
*/
|
*/
|
||||||
async checkEmailLinkClicked() {
|
public async checkEmailLinkClicked(): Promise<void> {
|
||||||
const creds = {
|
const creds = {
|
||||||
sid: this.sessionId,
|
sid: this.sessionId,
|
||||||
client_secret: this.clientSecret,
|
client_secret: this.clientSecret,
|
Loading…
Reference in New Issue