Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix CAS support by using a temporary Matrix client
Browse files Browse the repository at this point in the history
Signed-off-by: Shell Turner <cam.turn@gmail.com>
  • Loading branch information
VShell committed Sep 9, 2016
1 parent 14227b5 commit 1380bf7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var MatrixClientPeg = require("./MatrixClientPeg");
var SignupStages = require("./SignupStages");
var dis = require("./dispatcher");
var q = require("q");
var url = require("url");

const EMAIL_STAGE_TYPE = "m.login.email.identity";

Expand Down Expand Up @@ -413,6 +414,15 @@ class Login extends Signup {
throw error;
});
}

redirectToCas() {
var client = this._createTemporaryClient();
var parsedUrl = url.parse(window.location.href, true);
parsedUrl.query["homeserver"] = client.getHomeserverUrl();
parsedUrl.query["identityServer"] = client.getIdentityServerUrl();
var casUrl = client.getCasLoginUrl(url.format(parsedUrl));
window.location.href = casUrl;
}
}

module.exports.Register = Register;
Expand Down
6 changes: 5 additions & 1 deletion src/components/structures/login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ module.exports = React.createClass({
}).done();
},

onCasLogin: function() {
this._loginLogic.redirectToCas();
},

_onLoginAsGuestClick: function() {
var self = this;
self.setState({
Expand Down Expand Up @@ -225,7 +229,7 @@ module.exports = React.createClass({
);
case 'm.login.cas':
return (
<CasLogin />
<CasLogin onSubmit={this.onCasLogin} />
);
default:
if (!step) {
Expand Down
13 changes: 3 additions & 10 deletions src/components/views/login/CasLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,19 @@ limitations under the License.

'use strict';

var MatrixClientPeg = require("../../../MatrixClientPeg");
var React = require('react');
var url = require("url");

module.exports = React.createClass({
displayName: 'CasLogin',

onCasClicked: function(ev) {
var cli = MatrixClientPeg.get();
var parsedUrl = url.parse(window.location.href, true);
parsedUrl.query["homeserver"] = cli.getHomeserverUrl();
parsedUrl.query["identityServer"] = cli.getIdentityServerUrl();
var casUrl = MatrixClientPeg.get().getCasLoginUrl(url.format(parsedUrl));
window.location.href = casUrl;
propTypes: {
onSubmit: React.PropTypes.func, // fn()
},

render: function() {
return (
<div>
<button onClick={this.onCasClicked}>Sign in with CAS</button>
<button onClick={this.props.onSubmit}>Sign in with CAS</button>
</div>
);
}
Expand Down

0 comments on commit 1380bf7

Please sign in to comment.