You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Refactor code to base 'login' method.
This commit is contained in:
@@ -262,7 +262,19 @@ MatrixBaseApis.prototype.login = function(loginType, data, callback) {
|
|||||||
utils.extend(login_data, data);
|
utils.extend(login_data, data);
|
||||||
|
|
||||||
return this._http.authedRequest(
|
return this._http.authedRequest(
|
||||||
callback, "POST", "/login", undefined, login_data,
|
(error, response) => {
|
||||||
|
if (loginType === "m.login.password" && response &&
|
||||||
|
response.access_token && response.user_id) {
|
||||||
|
this._http.opts.accessToken = response.access_token;
|
||||||
|
this.credentials = {
|
||||||
|
userId: response.user_id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
callback(error, response);
|
||||||
|
}
|
||||||
|
}, "POST", "/login", undefined, login_data,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -277,21 +289,7 @@ MatrixBaseApis.prototype.loginWithPassword = function(user, password, callback)
|
|||||||
return this.login("m.login.password", {
|
return this.login("m.login.password", {
|
||||||
user: user,
|
user: user,
|
||||||
password: password,
|
password: password,
|
||||||
}, (error, response) => {
|
}, callback);
|
||||||
if (response && response.access_token) {
|
|
||||||
this._http.opts.accessToken = response.access_token;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response && response.user_id) {
|
|
||||||
this.credentials = {
|
|
||||||
userId: response.user_id,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback) {
|
|
||||||
callback(error, response);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user