Add authentication
This commit is contained in:
6 files changed
+1254
-1129
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import sys,os,requests
|
||||
from localStoragePy import localStoragePy
|
||||
from PySide6.QtWidgets import QApplication, QMainWindow
|
||||
from PySide6.QtCore import QUrl, Slot, QObject
|
||||
from PySide6.QtCore import QUrl, Slot, QObject, QCoreApplication, QProcess
|
||||
from PySide6.QtGui import QIcon, QPixmap
|
||||
from PySide6.QtWebEngineWidgets import QWebEngineView
|
||||
from PySide6.QtWebEngineCore import QWebEngineSettings
|
||||
@@ -19,6 +19,11 @@ except ImportError:
|
||||
|
||||
storage = localStoragePy('prayag.jellyplayer.app', 'sqlite')
|
||||
print(f"Server Url:{storage.getItem('server')}")
|
||||
|
||||
def restart():
|
||||
QApplication.quit()
|
||||
status = QProcess.startDetached(sys.executable, sys.argv)
|
||||
|
||||
class Backend(QObject):
|
||||
@Slot(str, result=bool)
|
||||
def saveServer(self, data):
|
||||
@@ -35,6 +40,7 @@ class Backend(QObject):
|
||||
def getValuesFromDatabaseBool(self, object):
|
||||
print(f"Object: {object}")
|
||||
item = storage.getItem(object)
|
||||
print(item)
|
||||
if item == "True":
|
||||
return True
|
||||
elif item == "False":
|
||||
@@ -47,6 +53,17 @@ class Backend(QObject):
|
||||
print(item)
|
||||
return item
|
||||
|
||||
@Slot(str, str)
|
||||
def setAuthInfo(self, userName, Pw):
|
||||
print(f"User: {userName}, Password: {Pw}")
|
||||
storage.setItem("UserName", userName)
|
||||
storage.setItem("UserPw", Pw)
|
||||
|
||||
@Slot()
|
||||
def clearStorage(self):
|
||||
storage.clear()
|
||||
restart()
|
||||
|
||||
class LoginWin(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
+1147
-1109
File diff suppressed because it is too large.
Load diff
@@ -2,6 +2,10 @@
|
||||
|
||||
:root {
|
||||
--main-bg: #0a1827;
|
||||
--jf-purple-light: #aa5cc3;
|
||||
--jf-purple-dark: #3e2247;
|
||||
--jf-blue-light: #00a4dc;
|
||||
--jf-blue-dark: #003c50;
|
||||
--warning-yellow: #f18e06;
|
||||
--warning-bg: rgba(220, 128, 1, 0.16);
|
||||
--error-red: #a94442;
|
||||
@@ -15,6 +19,7 @@
|
||||
--transition-time-fast-1: 150ms;
|
||||
--transition-time-default: 250ms;
|
||||
--transition-time-slow-1: 350ms;
|
||||
--transition-time-slow-2: 550ms;
|
||||
}
|
||||
|
||||
body,
|
||||
|
||||
+31
-1
@@ -31,6 +31,36 @@ main {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#background {
|
||||
background: transparent;
|
||||
position: fixed;
|
||||
z-index: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
#background > * {
|
||||
width: inherit;
|
||||
height: inherit;
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
transition: opacity var(--transition-time-slow-2);
|
||||
}
|
||||
|
||||
#background .purple {
|
||||
background: linear-gradient(140deg, var(--jf-purple-light), transparent);
|
||||
}
|
||||
|
||||
#background .blue {
|
||||
background: linear-gradient(140deg, transparent, var(--jf-blue-light));
|
||||
z-index: -2;
|
||||
}
|
||||
|
||||
#background .purple.active,
|
||||
#background .blue.active {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.page {
|
||||
position: static;
|
||||
width: 100vw;
|
||||
@@ -464,7 +494,7 @@ section.user__cont {
|
||||
display: block;
|
||||
width: 0.6em;
|
||||
border-radius: var(--rounding-1);
|
||||
border: 1px solid white;
|
||||
border: 1.5px solid white;
|
||||
}
|
||||
|
||||
.tick path {
|
||||
|
||||
@@ -22,7 +22,10 @@
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="background"></canvas>
|
||||
<div id="background">
|
||||
<div class="purple"></div>
|
||||
<div class="blue"></div>
|
||||
</div>
|
||||
<main>
|
||||
<section class="page server">
|
||||
<section class="server__cont">
|
||||
|
||||
+49
-17
@@ -34,6 +34,9 @@ window.onload = () => {
|
||||
});
|
||||
return value;
|
||||
};
|
||||
window.setAuthInfo = async (userName, Pw) => {
|
||||
await window.backend.setAuthInfo(userName, Pw);
|
||||
};
|
||||
getServerStat = async () => {
|
||||
await window.backend.getValuesFromDatabaseBool("serverGo", (data) => {
|
||||
if (data == true) {
|
||||
@@ -62,7 +65,6 @@ window.onload = () => {
|
||||
|
||||
emitter.on("get-server", async () => {
|
||||
window.getServer();
|
||||
console.log('dsk')
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -72,18 +74,11 @@ const base_token = `MediaBrowser Client="JellyPlayer", Device="${window.navigato
|
||||
const vanilla_token = `${base_token}, Token=""`;
|
||||
|
||||
const createUserList = async (server) => {
|
||||
console.log(`from userlist ${server}`)
|
||||
const ax = axios.create({
|
||||
headers: {
|
||||
Authorization: vanilla_token
|
||||
}
|
||||
});
|
||||
window.userApi = new window.UserApi(undefined, server, ax);
|
||||
document.querySelector('.loader').classList.remove('hide');
|
||||
let users = await window.userApi.getPublicUsers();
|
||||
let userlist = users.data;
|
||||
console.log(userlist);
|
||||
if (userlist.length != 0) {
|
||||
if (userlist != []) {
|
||||
userlist.forEach(user => {
|
||||
if (user.PrimaryImageTag) {
|
||||
html = `<div class="user__card" data-user="${user.Name}" data-userid="${user.Id}" onclick="createEnterPassword(this.dataset.user, true, this.dataset.userid)">
|
||||
@@ -104,6 +99,7 @@ const createUserList = async (server) => {
|
||||
document.querySelector('.user__cont').insertAdjacentHTML('beforeend', html);
|
||||
});
|
||||
document.querySelector('.users').classList.remove('hide');
|
||||
document.querySelector(".purple").classList.add("active");
|
||||
document.querySelector('.users').scrollIntoView({ behavior: "smooth" });
|
||||
document.querySelector('.loader').classList.add('hide');
|
||||
setTimeout(() => {
|
||||
@@ -194,7 +190,7 @@ const createDialog = (title, msg, btn, type) => {
|
||||
};
|
||||
|
||||
const sendClearDataRequest = () => {
|
||||
ipcRenderer.send('clear-user-data');
|
||||
window.backend.clearStorage();
|
||||
};
|
||||
|
||||
const createManualLogin = () => {
|
||||
@@ -224,6 +220,8 @@ const createManualLogin = () => {
|
||||
</div>`;
|
||||
document.querySelector('.manual__input').insertAdjacentHTML('beforeend', html);
|
||||
document.querySelector('.manual__login').classList.remove('hide');
|
||||
document.querySelector(".purple").classList.add("active");
|
||||
document.querySelector(".blue").classList.add("active");
|
||||
document.querySelector('.manual__login').scrollIntoView({ behavior: "smooth" });
|
||||
};
|
||||
|
||||
@@ -264,14 +262,31 @@ const createEnterPassword = (userName, userImg, userId) => {
|
||||
document.querySelector('.manual__input').querySelector('.user__info').insertAdjacentHTML('afterbegin', html);
|
||||
}
|
||||
document.querySelector('.manual__login').classList.remove('hide');
|
||||
document.querySelector(".blue").classList.add("active");
|
||||
document.querySelector('.manual__login').scrollIntoView({ behavior: "smooth" });
|
||||
};
|
||||
|
||||
const sendAuthInfo = (userName, password, checkbox) => {
|
||||
if (checkbox.checked == true) {
|
||||
ipcRenderer.send('user-auth-details', [userName, password, true]);
|
||||
} else {
|
||||
ipcRenderer.send('user-auth-details', [userName, password, false]);
|
||||
var authUser;
|
||||
const auth = async () => {
|
||||
try {
|
||||
authUser = await window.userApi.authenticateUserByName({
|
||||
authenticateUserByName: {
|
||||
Username: userName,
|
||||
Pw: password
|
||||
}
|
||||
});
|
||||
return authUser.data;
|
||||
} catch (error) {
|
||||
console.log(`[Err]Can't login, Reason: ${error}`);
|
||||
createAlert("error", "Invalid Username or Password entered try again", ".manual__login");
|
||||
return "err";
|
||||
}
|
||||
};
|
||||
if (auth() != "err") {
|
||||
if (checkbox.checked == true) {
|
||||
window.setAuthInfo(userName, password);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -279,8 +294,9 @@ const changeServer = () => {
|
||||
createDialog('Are you sure?', "You want to remove this server", "yes__no", "warning");
|
||||
};
|
||||
|
||||
const goBack = (from, to, loginForm, button) => {
|
||||
const goBack = (from, to, loginForm) => {
|
||||
to.scrollIntoView({ behavior: "smooth" });
|
||||
document.querySelector(".blue").classList.remove("active");
|
||||
setTimeout(() => {
|
||||
from.classList.add('hide');
|
||||
from.querySelector(`.${loginForm}`).remove();
|
||||
@@ -291,12 +307,17 @@ const goBack = (from, to, loginForm, button) => {
|
||||
emitter.on("serverGo-true", () => {
|
||||
emitter.emit('get-server');
|
||||
emitter.on("server-url", (server) => {
|
||||
window.ax = axios.create({
|
||||
headers: {
|
||||
Authorization: vanilla_token
|
||||
}
|
||||
});
|
||||
window.userApi = new window.UserApi(undefined, server, window.ax);
|
||||
document.querySelector('.loader').classList.remove('hide');
|
||||
document.querySelector('.loader').classList.add('hide');
|
||||
createUserList(server);
|
||||
});
|
||||
});
|
||||
|
||||
emitter.on("serverGo-false", () => {
|
||||
console.log("hello2");
|
||||
saveBtn.addEventListener('click', () => {
|
||||
@@ -308,6 +329,17 @@ emitter.on("serverGo-false", () => {
|
||||
createAlert('error', "Can't detrmine if the give server address is a valid Jellyfin server", ".server");
|
||||
});
|
||||
emitter.on('is-jf-server', () => {
|
||||
createUserList(serverUrl.value);
|
||||
emitter.emit('get-server');
|
||||
emitter.on("server-url", (server) => {
|
||||
window.ax = axios.create({
|
||||
headers: {
|
||||
Authorization: vanilla_token
|
||||
}
|
||||
});
|
||||
window.userApi = new window.UserApi(undefined, server, window.ax);
|
||||
document.querySelector('.loader').classList.remove('hide');
|
||||
document.querySelector('.loader').classList.add('hide');
|
||||
createUserList(server);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user