Merge pull request #1 from prayag17/auth

Add authentication
This commit is contained in:
Prayag authored and GitHub committed 2022-04-02 21:22:11 +05:30
commit f232634187
6 files changed
+1254 -1129

No files matched your search

+18 -1
View File
@@ -1,7 +1,7 @@
import sys,os,requests import sys,os,requests
from localStoragePy import localStoragePy from localStoragePy import localStoragePy
from PySide6.QtWidgets import QApplication, QMainWindow 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.QtGui import QIcon, QPixmap
from PySide6.QtWebEngineWidgets import QWebEngineView from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtWebEngineCore import QWebEngineSettings from PySide6.QtWebEngineCore import QWebEngineSettings
@@ -19,6 +19,11 @@ except ImportError:
storage = localStoragePy('prayag.jellyplayer.app', 'sqlite') storage = localStoragePy('prayag.jellyplayer.app', 'sqlite')
print(f"Server Url:{storage.getItem('server')}") print(f"Server Url:{storage.getItem('server')}")
def restart():
QApplication.quit()
status = QProcess.startDetached(sys.executable, sys.argv)
class Backend(QObject): class Backend(QObject):
@Slot(str, result=bool) @Slot(str, result=bool)
def saveServer(self, data): def saveServer(self, data):
@@ -35,6 +40,7 @@ class Backend(QObject):
def getValuesFromDatabaseBool(self, object): def getValuesFromDatabaseBool(self, object):
print(f"Object: {object}") print(f"Object: {object}")
item = storage.getItem(object) item = storage.getItem(object)
print(item)
if item == "True": if item == "True":
return True return True
elif item == "False": elif item == "False":
@@ -47,6 +53,17 @@ class Backend(QObject):
print(item) print(item)
return 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): class LoginWin(QMainWindow):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
+1147 -1109
View File
File diff suppressed because it is too large. Load diff
+5
View File
@@ -2,6 +2,10 @@
:root { :root {
--main-bg: #0a1827; --main-bg: #0a1827;
--jf-purple-light: #aa5cc3;
--jf-purple-dark: #3e2247;
--jf-blue-light: #00a4dc;
--jf-blue-dark: #003c50;
--warning-yellow: #f18e06; --warning-yellow: #f18e06;
--warning-bg: rgba(220, 128, 1, 0.16); --warning-bg: rgba(220, 128, 1, 0.16);
--error-red: #a94442; --error-red: #a94442;
@@ -15,6 +19,7 @@
--transition-time-fast-1: 150ms; --transition-time-fast-1: 150ms;
--transition-time-default: 250ms; --transition-time-default: 250ms;
--transition-time-slow-1: 350ms; --transition-time-slow-1: 350ms;
--transition-time-slow-2: 550ms;
} }
body, body,
+31 -1
View File
@@ -31,6 +31,36 @@ main {
overflow: hidden; 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 { .page {
position: static; position: static;
width: 100vw; width: 100vw;
@@ -464,7 +494,7 @@ section.user__cont {
display: block; display: block;
width: 0.6em; width: 0.6em;
border-radius: var(--rounding-1); border-radius: var(--rounding-1);
border: 1px solid white; border: 1.5px solid white;
} }
.tick path { .tick path {
+4 -1
View File
@@ -22,7 +22,10 @@
</script> </script>
</head> </head>
<body> <body>
<canvas id="background"></canvas> <div id="background">
<div class="purple"></div>
<div class="blue"></div>
</div>
<main> <main>
<section class="page server"> <section class="page server">
<section class="server__cont"> <section class="server__cont">
+49 -17
View File
@@ -34,6 +34,9 @@ window.onload = () => {
}); });
return value; return value;
}; };
window.setAuthInfo = async (userName, Pw) => {
await window.backend.setAuthInfo(userName, Pw);
};
getServerStat = async () => { getServerStat = async () => {
await window.backend.getValuesFromDatabaseBool("serverGo", (data) => { await window.backend.getValuesFromDatabaseBool("serverGo", (data) => {
if (data == true) { if (data == true) {
@@ -62,7 +65,6 @@ window.onload = () => {
emitter.on("get-server", async () => { emitter.on("get-server", async () => {
window.getServer(); 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 vanilla_token = `${base_token}, Token=""`;
const createUserList = async (server) => { 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'); document.querySelector('.loader').classList.remove('hide');
let users = await window.userApi.getPublicUsers(); let users = await window.userApi.getPublicUsers();
let userlist = users.data; let userlist = users.data;
console.log(userlist); console.log(userlist);
if (userlist.length != 0) { if (userlist != []) {
userlist.forEach(user => { userlist.forEach(user => {
if (user.PrimaryImageTag) { 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)"> 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('.user__cont').insertAdjacentHTML('beforeend', html);
}); });
document.querySelector('.users').classList.remove('hide'); document.querySelector('.users').classList.remove('hide');
document.querySelector(".purple").classList.add("active");
document.querySelector('.users').scrollIntoView({ behavior: "smooth" }); document.querySelector('.users').scrollIntoView({ behavior: "smooth" });
document.querySelector('.loader').classList.add('hide'); document.querySelector('.loader').classList.add('hide');
setTimeout(() => { setTimeout(() => {
@@ -194,7 +190,7 @@ const createDialog = (title, msg, btn, type) => {
}; };
const sendClearDataRequest = () => { const sendClearDataRequest = () => {
ipcRenderer.send('clear-user-data'); window.backend.clearStorage();
}; };
const createManualLogin = () => { const createManualLogin = () => {
@@ -224,6 +220,8 @@ const createManualLogin = () => {
</div>`; </div>`;
document.querySelector('.manual__input').insertAdjacentHTML('beforeend', html); document.querySelector('.manual__input').insertAdjacentHTML('beforeend', html);
document.querySelector('.manual__login').classList.remove('hide'); 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" }); 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__input').querySelector('.user__info').insertAdjacentHTML('afterbegin', html);
} }
document.querySelector('.manual__login').classList.remove('hide'); document.querySelector('.manual__login').classList.remove('hide');
document.querySelector(".blue").classList.add("active");
document.querySelector('.manual__login').scrollIntoView({ behavior: "smooth" }); document.querySelector('.manual__login').scrollIntoView({ behavior: "smooth" });
}; };
const sendAuthInfo = (userName, password, checkbox) => { const sendAuthInfo = (userName, password, checkbox) => {
if (checkbox.checked == true) { var authUser;
ipcRenderer.send('user-auth-details', [userName, password, true]); const auth = async () => {
} else { try {
ipcRenderer.send('user-auth-details', [userName, password, false]); 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"); 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" }); to.scrollIntoView({ behavior: "smooth" });
document.querySelector(".blue").classList.remove("active");
setTimeout(() => { setTimeout(() => {
from.classList.add('hide'); from.classList.add('hide');
from.querySelector(`.${loginForm}`).remove(); from.querySelector(`.${loginForm}`).remove();
@@ -291,12 +307,17 @@ const goBack = (from, to, loginForm, button) => {
emitter.on("serverGo-true", () => { emitter.on("serverGo-true", () => {
emitter.emit('get-server'); emitter.emit('get-server');
emitter.on("server-url", (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.remove('hide');
document.querySelector('.loader').classList.add('hide'); document.querySelector('.loader').classList.add('hide');
createUserList(server); createUserList(server);
}); });
}); });
emitter.on("serverGo-false", () => { emitter.on("serverGo-false", () => {
console.log("hello2"); console.log("hello2");
saveBtn.addEventListener('click', () => { 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"); createAlert('error', "Can't detrmine if the give server address is a valid Jellyfin server", ".server");
}); });
emitter.on('is-jf-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);
});
}); });
}); });