mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-18 03:18:19 -07:00
Merge pull request #235 from dkanada/login
Add check for multiserver on login page
This commit is contained in:
commit
da96b1120c
@ -1,91 +1,148 @@
|
|||||||
define(["appSettings", "dom", "connectionManager", "loading", "cardStyle", "emby-checkbox"], function(appSettings, dom, connectionManager, loading) {
|
define(["apphost", "appSettings", "dom", "connectionManager", "loading", "cardStyle", "emby-checkbox"], function(appHost, appSettings, dom, connectionManager, loading) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function authenticateUserByName(page, apiClient, username, password) {
|
function authenticateUserByName(page, apiClient, username, password) {
|
||||||
loading.show(), apiClient.authenticateUserByName(username, password).then(function(result) {
|
loading.show();
|
||||||
var newUrl, user = result.User,
|
apiClient.authenticateUserByName(username, password).then(function(result) {
|
||||||
serverId = getParameterByName("serverid");
|
var user = result.User;
|
||||||
newUrl = user.Policy.IsAdministrator && !serverId ? "dashboard.html" : "home.html", loading.hide(), Dashboard.onServerChanged(user.Id, result.AccessToken, apiClient), Dashboard.navigate(newUrl)
|
var serverId = getParameterByName("serverid");
|
||||||
|
var newUrl = user.Policy.IsAdministrator && !serverId ? "dashboard.html" : "home.html";
|
||||||
|
loading.hide();
|
||||||
|
Dashboard.onServerChanged(user.Id, result.AccessToken, apiClient);
|
||||||
|
Dashboard.navigate(newUrl);
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
page.querySelector("#txtManualName").value = "", page.querySelector("#txtManualPassword").value = "", loading.hide(), 401 == response.status ? require(["toast"], function(toast) {
|
page.querySelector("#txtManualName").value = "";
|
||||||
toast(Globalize.translate("MessageInvalidUser"))
|
page.querySelector("#txtManualPassword").value = "";
|
||||||
}) : showServerConnectionFailure()
|
loading.hide();
|
||||||
})
|
if (response.status === 401) {
|
||||||
}
|
require(["toast"], function(toast) {
|
||||||
|
toast(Globalize.translate("MessageInvalidUser"));
|
||||||
function showServerConnectionFailure() {
|
});
|
||||||
|
} else {
|
||||||
Dashboard.alert({
|
Dashboard.alert({
|
||||||
message: Globalize.translate("MessageUnableToConnectToServer"),
|
message: Globalize.translate("MessageUnableToConnectToServer"),
|
||||||
title: Globalize.translate("HeaderConnectionFailure")
|
title: Globalize.translate("HeaderConnectionFailure")
|
||||||
})
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function showManualForm(context, showCancel, focusPassword) {
|
function showManualForm(context, showCancel, focusPassword) {
|
||||||
context.querySelector(".chkRememberLogin").checked = appSettings.enableAutoLogin(), context.querySelector(".manualLoginForm").classList.remove("hide"), context.querySelector(".visualLoginForm").classList.add("hide"), focusPassword ? context.querySelector("#txtManualPassword").focus() : context.querySelector("#txtManualName").focus(), showCancel ? context.querySelector(".btnCancel").classList.remove("hide") : context.querySelector(".btnCancel").classList.add("hide")
|
context.querySelector(".chkRememberLogin").checked = appSettings.enableAutoLogin();
|
||||||
|
context.querySelector(".manualLoginForm").classList.remove("hide");
|
||||||
|
context.querySelector(".visualLoginForm").classList.add("hide");
|
||||||
|
focusPassword ? context.querySelector("#txtManualPassword").focus() : context.querySelector("#txtManualName").focus();
|
||||||
|
showCancel ? context.querySelector(".btnCancel").classList.remove("hide") : context.querySelector(".btnCancel").classList.add("hide");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var metroColors = ["#6FBD45", "#4BB3DD", "#4164A5", "#E12026", "#800080", "#E1B222", "#008040", "#0094FF", "#FF00C7", "#FF870F", "#7F0037"];
|
||||||
|
|
||||||
function getRandomMetroColor() {
|
function getRandomMetroColor() {
|
||||||
var index = Math.floor(Math.random() * (metroColors.length - 1));
|
var index = Math.floor(Math.random() * (metroColors.length - 1));
|
||||||
return metroColors[index]
|
return metroColors[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMetroColor(str) {
|
function getMetroColor(str) {
|
||||||
if (str) {
|
if (str) {
|
||||||
for (var character = String(str.substr(0, 1).charCodeAt()), sum = 0, i = 0; i < character.length; i++) sum += parseInt(character.charAt(i));
|
var character = String(str.substr(0, 1).charCodeAt());
|
||||||
var index = String(sum).substr(-1);
|
var sum = 0;
|
||||||
return metroColors[index]
|
for (var i = 0; i < character.length; i++) {
|
||||||
|
sum += parseInt(character.charAt(i));
|
||||||
}
|
}
|
||||||
return getRandomMetroColor()
|
var index = String(sum).substr(-1);
|
||||||
|
return metroColors[index];
|
||||||
|
}
|
||||||
|
return getRandomMetroColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadUserList(context, apiClient, users) {
|
function loadUserList(context, apiClient, users) {
|
||||||
for (var html = "", i = 0, length = users.length; i < length; i++) {
|
var html = "";
|
||||||
|
for (var i = 0; i < users.length; i++) {
|
||||||
var user = users[i];
|
var user = users[i];
|
||||||
html += '<button type="button" class="card squareCard scalableCard squareCard-scalable"><div class="cardBox cardBox-bottompadded">', html += '<div class="cardScalable">', html += '<div class="cardPadder cardPadder-square"></div>', html += '<div class="cardContent" data-haspw="' + user.HasPassword + '" data-username="' + user.Name + '" data-userid="' + user.Id + '">';
|
html += '<button type="button" class="card squareCard scalableCard squareCard-scalable"><div class="cardBox cardBox-bottompadded">';
|
||||||
|
html += '<div class="cardScalable">';
|
||||||
|
html += '<div class="cardPadder cardPadder-square"></div>';
|
||||||
|
html += '<div class="cardContent" data-haspw="' + user.HasPassword + '" data-username="' + user.Name + '" data-userid="' + user.Id + '">';
|
||||||
var imgUrl;
|
var imgUrl;
|
||||||
if (user.PrimaryImageTag) imgUrl = apiClient.getUserImageUrl(user.Id, {
|
if (user.PrimaryImageTag) {
|
||||||
|
imgUrl = apiClient.getUserImageUrl(user.Id, {
|
||||||
width: 300,
|
width: 300,
|
||||||
tag: user.PrimaryImageTag,
|
tag: user.PrimaryImageTag,
|
||||||
type: "Primary"
|
type: "Primary"
|
||||||
}), html += '<div class="cardImageContainer coveredImage coveredImage-noScale" style="background-image:url(\'' + imgUrl + "');\"></div>";
|
});
|
||||||
else {
|
html += '<div class="cardImageContainer coveredImage coveredImage-noScale" style="background-image:url(\'' + imgUrl + "');\"></div>";
|
||||||
|
} else {
|
||||||
var background = getMetroColor(user.Id);
|
var background = getMetroColor(user.Id);
|
||||||
imgUrl = "img/logindefault.png", html += '<div class="cardImageContainer coveredImage coveredImage-noScale" style="background-image:url(\'' + imgUrl + "');background-color:" + background + ';"></div>'
|
imgUrl = "img/logindefault.png";
|
||||||
|
html += '<div class="cardImageContainer coveredImage coveredImage-noScale" style="background-image:url(\'' + imgUrl + "');background-color:" + background + ';"></div>';
|
||||||
}
|
}
|
||||||
html += "</div>", html += "</div>", html += '<div class="cardFooter visualCardBox-cardFooter">', html += '<div class="cardText singleCardText cardTextCentered">' + user.Name + "</div>", html += "</div>", html += "</div>", html += "</button>"
|
html += "</div>";
|
||||||
|
html += "</div>";
|
||||||
|
html += '<div class="cardFooter visualCardBox-cardFooter">';
|
||||||
|
html += '<div class="cardText singleCardText cardTextCentered">' + user.Name + "</div>";
|
||||||
|
html += "</div>";
|
||||||
|
html += "</div>";
|
||||||
|
html += "</button>";
|
||||||
}
|
}
|
||||||
context.querySelector("#divUsers").innerHTML = html
|
context.querySelector("#divUsers").innerHTML = html;
|
||||||
}
|
}
|
||||||
var metroColors = ["#6FBD45", "#4BB3DD", "#4164A5", "#E12026", "#800080", "#E1B222", "#008040", "#0094FF", "#FF00C7", "#FF870F", "#7F0037"];
|
|
||||||
return function(view, params) {
|
return function(view, params) {
|
||||||
function getApiClient() {
|
function getApiClient() {
|
||||||
var serverId = params.serverid;
|
var serverId = params.serverid;
|
||||||
return serverId ? connectionManager.getOrCreateApiClient(serverId) : ApiClient
|
return serverId ? connectionManager.getOrCreateApiClient(serverId) : ApiClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showVisualForm() {
|
function showVisualForm() {
|
||||||
view.querySelector(".visualLoginForm").classList.remove("hide"), view.querySelector(".manualLoginForm").classList.add("hide")
|
view.querySelector(".visualLoginForm").classList.remove("hide");
|
||||||
|
view.querySelector(".manualLoginForm").classList.add("hide");
|
||||||
}
|
}
|
||||||
|
|
||||||
view.querySelector("#divUsers").addEventListener("click", function(e) {
|
view.querySelector("#divUsers").addEventListener("click", function(e) {
|
||||||
var card = dom.parentWithClass(e.target, "card"),
|
var card = dom.parentWithClass(e.target, "card");
|
||||||
cardContent = card ? card.querySelector(".cardContent") : null;
|
var cardContent = card ? card.querySelector(".cardContent") : null;
|
||||||
if (cardContent) {
|
if (cardContent) {
|
||||||
var context = view,
|
var context = view;
|
||||||
id = cardContent.getAttribute("data-userid"),
|
var id = cardContent.getAttribute("data-userid");
|
||||||
name = cardContent.getAttribute("data-username"),
|
var name = cardContent.getAttribute("data-username");
|
||||||
haspw = cardContent.getAttribute("data-haspw");
|
var haspw = cardContent.getAttribute("data-haspw");
|
||||||
"manual" == id ? (context.querySelector("#txtManualName").value = "", showManualForm(context, !0)) : "false" == haspw ? authenticateUserByName(context, getApiClient(), name, "") : (context.querySelector("#txtManualName").value = name, context.querySelector("#txtManualPassword").value = "", showManualForm(context, !0, !0))
|
if (id === 'manual') {
|
||||||
|
context.querySelector("#txtManualName").value = "";
|
||||||
|
showManualForm(context, true);
|
||||||
|
} else if (haspw == 'false') {
|
||||||
|
authenticateUserByName(context, getApiClient(), name, "");
|
||||||
|
} else {
|
||||||
|
context.querySelector("#txtManualName").value = name;
|
||||||
|
context.querySelector("#txtManualPassword").value = "";
|
||||||
|
showManualForm(context, true, true);
|
||||||
}
|
}
|
||||||
}), view.querySelector(".manualLoginForm").addEventListener("submit", function(e) {
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
view.querySelector(".manualLoginForm").addEventListener("submit", function(e) {
|
||||||
appSettings.enableAutoLogin(view.querySelector(".chkRememberLogin").checked);
|
appSettings.enableAutoLogin(view.querySelector(".chkRememberLogin").checked);
|
||||||
var apiClient = getApiClient();
|
var apiClient = getApiClient();
|
||||||
return authenticateUserByName(view, apiClient, view.querySelector("#txtManualName").value, view.querySelector("#txtManualPassword").value), e.preventDefault(), !1
|
authenticateUserByName(view, apiClient, view.querySelector("#txtManualName").value, view.querySelector("#txtManualPassword").value);
|
||||||
}), view.querySelector(".btnForgotPassword").addEventListener("click", function() {
|
e.preventDefault();
|
||||||
Dashboard.navigate("forgotpassword.html")
|
return false;
|
||||||
}), view.querySelector(".btnCancel").addEventListener("click", showVisualForm), view.querySelector(".btnManual").addEventListener("click", function() {
|
});
|
||||||
view.querySelector("#txtManualName").value = "", showManualForm(view, !0)
|
|
||||||
}), view.addEventListener("viewshow", function(e) {
|
view.querySelector(".btnForgotPassword").addEventListener("click", function() {
|
||||||
|
Dashboard.navigate("forgotpassword.html");
|
||||||
|
});
|
||||||
|
|
||||||
|
view.querySelector(".btnCancel").addEventListener("click", showVisualForm);
|
||||||
|
|
||||||
|
view.querySelector(".btnManual").addEventListener("click", function() {
|
||||||
|
view.querySelector("#txtManualName").value = "";
|
||||||
|
showManualForm(view, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
view.addEventListener("viewshow", function(e) {
|
||||||
loading.show();
|
loading.show();
|
||||||
|
if (!appHost.supports('multiserver')) {
|
||||||
|
view.querySelector(".btnSelectServer").classList.add("hide");
|
||||||
|
}
|
||||||
var apiClient = getApiClient();
|
var apiClient = getApiClient();
|
||||||
apiClient.getPublicUsers().then(function(users) {
|
apiClient.getPublicUsers().then(function(users) {
|
||||||
if (users.length) {
|
if (users.length) {
|
||||||
@ -105,7 +162,7 @@ define(["appSettings", "dom", "connectionManager", "loading", "cardStyle", "emby
|
|||||||
});
|
});
|
||||||
|
|
||||||
apiClient.getJSON(apiClient.getUrl("Branding/Configuration")).then(function(options) {
|
apiClient.getJSON(apiClient.getUrl("Branding/Configuration")).then(function(options) {
|
||||||
view.querySelector(".disclaimer").textContent = options.LoginDisclaimer || ""
|
view.querySelector(".disclaimer").textContent = options.LoginDisclaimer || "";
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
<span>${ButtonForgotPassword}</span>
|
<span>${ButtonForgotPassword}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<a is="emby-linkbutton" href="selectserver.html" class="raised block">
|
<a is="emby-linkbutton" href="selectserver.html" class="raised block btnSelectServer">
|
||||||
<span>${ButtonChangeServer}</span>
|
<span>${ButtonChangeServer}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user