Skip to content

Commit 4e0d930

Browse files
author
Steven Hammerton
committed
Pull down some CAS stuff from vector into controller and logic class
1 parent 3f67d85 commit 4e0d930

3 files changed

Lines changed: 69 additions & 3 deletions

File tree

‎src/CasLogic.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var Url = require ('url');
20+
21+
function getServiceUrl() {
22+
var parsedUrl = Url.parse(window.location.href);
23+
return parsedUrl.protocol + "//" + parsedUrl.host + parsedUrl.pathname;
24+
}
25+
26+
module.exports = {
27+
getServiceUrl: getServiceUrl
28+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var React = require("react");
20+
var MatrixClientPeg = require("../../MatrixClientPeg");
21+
var Cas = require("../../CasLogic");
22+
23+
module.exports = {
24+
25+
onCasClicked: function(ev) {
26+
var serviceRedirectUrl = Cas.getServiceUrl() + "#/login/cas";
27+
var self = this;
28+
MatrixClientPeg.get().getCasServer().done(function(data) {
29+
var serverUrl = data.serverUrl + "/login?service=" + encodeURIComponent(serviceRedirectUrl);
30+
window.location.href = serverUrl;
31+
}, function(error) {
32+
self.setStep("stage_m.login.cas");
33+
self.setState({errorText: 'Login failed.'});
34+
});
35+
},
36+
37+
};

‎src/controllers/pages/MatrixChat.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var q = require("q");
2323
var sdk = require('../../index');
2424
var MatrixTools = require('../../MatrixTools');
2525

26+
var Cas = require("../../CasLogic");
27+
2628
module.exports = {
2729
PageTypes: {
2830
RoomView: "room_view",
@@ -132,12 +134,11 @@ module.exports = {
132134

133135
var self = this;
134136
var client = MatrixClientPeg.get();
135-
var splitLocation = window.location.href.split('/');
136-
var serviceUrl = splitLocation[0] + "//" + splitLocation[2];
137+
var serviceUrl = Cas.getServiceUrl();
137138

138139
client.loginWithCas(payload.params.ticket, serviceUrl).done(function(data) {
139140
MatrixClientPeg.replaceUsingAccessToken(
140-
client.getHsUrl(), client.getIsUrl(),
141+
client.getHomeserverUrl(), client.getIdentityServerUrl(),
141142
data.user_id, data.access_token
142143
);
143144
self.setState({

0 commit comments

Comments
 (0)