Implement logging in via password
This commit is contained in:
parent
f4dd88ed64
commit
b127c30436
2 changed files with 49 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
"use strict";
|
||||
var MatrixClientPeg = require("./MatrixClientPeg");
|
||||
var dis = require("./dispatcher");
|
||||
var q = require("q");
|
||||
|
||||
class Register {
|
||||
|
||||
|
@ -43,6 +44,46 @@ class Login {
|
|||
var flowStep = this._flows[this._currentFlowIndex];
|
||||
return flowStep ? flowStep.type : null;
|
||||
}
|
||||
|
||||
loginViaPassword(username, pass) {
|
||||
var self = this;
|
||||
var isEmail = username.indexOf("@") > 0;
|
||||
var loginParams = {
|
||||
password: pass
|
||||
};
|
||||
if (isEmail) {
|
||||
loginParams.medium = 'email';
|
||||
loginParams.address = username;
|
||||
} else {
|
||||
loginParams.user = username;
|
||||
}
|
||||
|
||||
return MatrixClientPeg.get().login('m.login.password', loginParams).then(function(data) {
|
||||
return q({
|
||||
homeserverUrl: self._hsUrl,
|
||||
identityServerUrl: self._isUrl,
|
||||
userId: data.user_id,
|
||||
accessToken: data.access_token
|
||||
});
|
||||
}, function(error) {
|
||||
if (error.httpStatus == 400 && loginParams.medium) {
|
||||
error.friendlyText = (
|
||||
'This Home Server does not support login using email address.'
|
||||
);
|
||||
}
|
||||
else if (error.httpStatus === 403) {
|
||||
error.friendlyText = (
|
||||
'Incorrect username and/or password.'
|
||||
);
|
||||
}
|
||||
else {
|
||||
error.friendlyText = (
|
||||
'There was a problem logging in. (HTTP ' + error.httpStatus + ")"
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.Register = Register;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue