mirror of
https://github.com/SchildiChat/element-web.git
synced 2024-10-01 01:26:12 -04:00
Save creds to localstorage
This commit is contained in:
parent
22e18471db
commit
e28fde7ae1
@ -3,6 +3,20 @@ var Matrix = require("matrix-js-sdk");
|
||||
|
||||
var matrixClient = null;
|
||||
|
||||
var localStorage = window.localStorage;
|
||||
if (localStorage) {
|
||||
var hs_url = localStorage.getItem("mx_hs_url");
|
||||
var access_token = localStorage.getItem("mx_access_token");
|
||||
var user_id = localStorage.getItem("mx_user_id");
|
||||
if (access_token && user_id && hs_url) {
|
||||
matrixClient = Matrix.createClient({
|
||||
baseUrl: hs_url,
|
||||
accessToken: access_token,
|
||||
userId: user_id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
get: function() {
|
||||
return matrixClient;
|
||||
|
@ -12,7 +12,7 @@ var dis = require("../dispatcher");
|
||||
module.exports = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {
|
||||
logged_in: false
|
||||
logged_in: !!mxCliPeg.get().credentials
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -24,8 +24,10 @@ module.exports = React.createClass({
|
||||
|
||||
onHSChosen: function(ev) {
|
||||
MatrixClientPeg.replaceUsingUrl(this.refs.serverConfig.getHsUrl());
|
||||
this.setState({hs_url: this.refs.serverConfig.getHsUrl()});
|
||||
this.setStep("fetch_stages");
|
||||
var cli = MatrixClientPeg.get();
|
||||
this.setState({busy: true});
|
||||
var that = this;
|
||||
cli.loginFlows().then(function(result) {
|
||||
that.setState({
|
||||
@ -41,11 +43,21 @@ module.exports = React.createClass({
|
||||
},
|
||||
|
||||
onUserPassEntered: function(ev) {
|
||||
this.setState({busy: true});
|
||||
var that = this;
|
||||
MatrixClientPeg.get().login('m.login.password', {
|
||||
'user': that.refs.user.getDOMNode().value,
|
||||
'password': that.refs.pass.getDOMNode().value
|
||||
}).then(function(data) {
|
||||
// XXX: we assume this means we're logged in, but there could be a next stage
|
||||
var localStorage = window.localStorage;
|
||||
if (localStorage) {
|
||||
localStorage.setItem("mx_hs_url", that.state.hs_url);
|
||||
localStorage.setItem("mx_user_id", data.user_id);
|
||||
localStorage.setItem("mx_access_token", data.access_token);
|
||||
} else {
|
||||
console.warn("No local storage available: can't persist session!");
|
||||
}
|
||||
dis.dispatch({
|
||||
'action': 'logged_in'
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user