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

Commit

Permalink
Revert "Improve the UX of the login fallback when using SSO (#7152)"
Browse files Browse the repository at this point in the history
This was incorrectly merged to `master` instead of develop.

This reverts commit 9024634.
  • Loading branch information
richvdh committed Apr 3, 2020
1 parent 84a901c commit 8d4cbde
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
1 change: 0 additions & 1 deletion changelog.d/7152.feature

This file was deleted.

2 changes: 1 addition & 1 deletion synapse/static/client/login/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body onload="matrixLogin.onLoad()">
<center>
<br/>
<h1 id="title"></h1>
<h1>Log in with one of the following methods</h1>

<span id="feedback" style="color: #f00"></span>

Expand Down
51 changes: 21 additions & 30 deletions synapse/static/client/login/js/login.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
window.matrixLogin = {
endpoint: location.origin + "/_matrix/client/r0/login",
serverAcceptsPassword: false,
serverAcceptsCas: false,
serverAcceptsSso: false,
};

var title_pre_auth = "Log in with one of the following methods";
var title_post_auth = "Logging in...";

var submitPassword = function(user, pwd) {
console.log("Logging in with password...");
set_title(title_post_auth);
var data = {
type: "m.login.password",
user: user,
password: pwd,
};
$.post(matrixLogin.endpoint, JSON.stringify(data), function(response) {
show_login();
matrixLogin.onLogin(response);
}).error(errorFunc);
};

var submitToken = function(loginToken) {
console.log("Logging in with login token...");
set_title(title_post_auth);
var data = {
type: "m.login.token",
token: loginToken
};
$.post(matrixLogin.endpoint, JSON.stringify(data), function(response) {
show_login();
matrixLogin.onLogin(response);
}).error(errorFunc);
};

var errorFunc = function(err) {
// We want to show the error to the user rather than redirecting immediately to the
// SSO portal (if SSO is the only login option), so we inhibit the redirect.
show_login(true);
show_login();

if (err.responseJSON && err.responseJSON.error) {
setFeedbackString(err.responseJSON.error + " (" + err.responseJSON.errcode + ")");
Expand All @@ -49,33 +45,26 @@ var setFeedbackString = function(text) {
$("#feedback").text(text);
};

var show_login = function(inhibit_redirect) {
var show_login = function() {
$("#loading").hide();

var this_page = window.location.origin + window.location.pathname;
$("#sso_redirect_url").val(this_page);

// If inhibit_redirect is false, and SSO is the only supported login method, we can
// redirect straight to the SSO page
if (matrixLogin.serverAcceptsSso) {
if (!inhibit_redirect && !matrixLogin.serverAcceptsPassword) {
$("#sso_form").submit();
return;
}

// Otherwise, show the SSO form
$("#sso_form").show();
}

if (matrixLogin.serverAcceptsPassword) {
$("#password_flow").show();
}

if (!matrixLogin.serverAcceptsPassword && !matrixLogin.serverAcceptsSso) {
$("#no_login_types").show();
if (matrixLogin.serverAcceptsSso) {
$("#sso_flow").show();
} else if (matrixLogin.serverAcceptsCas) {
$("#sso_form").attr("action", "/_matrix/client/r0/login/cas/redirect");
$("#sso_flow").show();
}

set_title(title_pre_auth);

$("#loading").hide();
if (!matrixLogin.serverAcceptsPassword && !matrixLogin.serverAcceptsCas && !matrixLogin.serverAcceptsSso) {
$("#no_login_types").show();
}
};

var show_spinner = function() {
Expand All @@ -85,15 +74,17 @@ var show_spinner = function() {
$("#loading").show();
};

var set_title = function(title) {
$("#title").text(title);
};

var fetch_info = function(cb) {
$.get(matrixLogin.endpoint, function(response) {
var serverAcceptsPassword = false;
var serverAcceptsCas = false;
for (var i=0; i<response.flows.length; i++) {
var flow = response.flows[i];
if ("m.login.cas" === flow.type) {
matrixLogin.serverAcceptsCas = true;
console.log("Server accepts CAS");
}
if ("m.login.sso" === flow.type) {
matrixLogin.serverAcceptsSso = true;
console.log("Server accepts SSO");
Expand All @@ -111,7 +102,7 @@ var fetch_info = function(cb) {
matrixLogin.onLoad = function() {
fetch_info(function() {
if (!try_token()) {
show_login(false);
show_login();
}
});
};
Expand Down

0 comments on commit 8d4cbde

Please sign in to comment.