Compare commits

...

2 Commits

Author SHA1 Message Date
56599bfdb3 Setup childprocess 2023-10-26 21:57:21 +05:30
546c09cca2 Implement Electron
- Run npm start / npm test for devmode
2023-10-25 22:53:46 +05:30
14 changed files with 1204 additions and 15 deletions

View File

@ -9,6 +9,9 @@ from data_handler import DataHandler
app: Flask = Flask(__name__)
if __name__ == "__main__":
app.run(debug=True)
def handle_first_launched():
"""

37
backend/rest_api.spec Normal file
View File

@ -0,0 +1,37 @@
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['rest_api.py', 'encryption_handler.py', 'data_handler.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='rest_api',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)

View File

View File

@ -3,6 +3,13 @@
<head>
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https://fonts.googleapis.com;
font-src 'self' https://fonts.gstatic.com;
connect-src 'self' http://127.0.0.1:5000;
style-src 'self' https://fonts.googleapis.com 'unsafe-inline';
script-src 'self' 'unsafe-inline';
script-src-elem 'self' 'unsafe-inline';
img-src 'self' http://www.google.com/s2/favicons https://t1.gstatic.com https://t0.gstatic.com https://t2.gstatic.com">
<title>DashBoard</title>
<link rel="stylesheet" href="../styles/dashboard.css"/>
</head>

View File

@ -3,6 +3,14 @@
<html>
<head>
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https://fonts.googleapis.com;
font-src 'self' https://fonts.gstatic.com;
connect-src 'self' http://127.0.0.1:5000;
style-src 'self' https://fonts.googleapis.com 'unsafe-inline';">
<meta
http-equiv="X-Content-Security-Policy"
content="default-src 'self'; script-src 'self'"
/>
<link rel="stylesheet" href="../styles/index.css"/>
<title>Login</title>
<link rel="preconnect" href="https://fonts.googleapis.com">

View File

@ -3,6 +3,12 @@
<html>
<head>
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https://fonts.googleapis.com;
font-src 'self' https://fonts.gstatic.com;
connect-src 'self' http://127.0.0.1:5000;
style-src 'self' https://fonts.googleapis.com 'unsafe-inline';
script-src 'self' 'unsafe-inline';
script-src-elem 'self' 'unsafe-inline'">
<link rel="stylesheet" href="../styles/register.css"/>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

77
frontend/main.js Normal file
View File

@ -0,0 +1,77 @@
const { app, BrowserWindow, shell } = require('electron')
const path = require('path')
const { spawn } = require('node:child_process');
const rest_api = spawn('python', ['./backend/rest_api.py']);
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
}
})
win.loadFile('frontend/html/index.html')
win.setMenu(null);
win.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: 'deny' };
});
win.webContents.openDevTools();
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
rest_api.stdout.on('data', (data) => {
console.log(data.toString());
});
rest_api.stderr.on('data', (data) => {
console.error(data.toString());
});
rest_api.on('exit', (code) => {
console.log(`Child exited with code ${code}`);
});
});
app.on('before-quit', () => {
rest_api.kill();
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('web-contents-created', (event, contents) => {
contents.on('new-window', (event, navigationUrl) => {
event.preventDefault();
require('electron').shell.openExternal(navigationUrl);
});
});

View File

@ -14,9 +14,11 @@
//-----------------------------------------------------------------------------------------(Getting Data)
const PORT = 5000;
async function getData() {
try {
let response = await fetch('/get_data', {
let response = await fetch(`http://127.0.0.1:${PORT}/get_data`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
@ -223,7 +225,7 @@ const errorlabel = document.querySelector('.fieldcontainer label')
async function sendData(formData){
try {
const response = await fetch('/add_entry', {
const response = await fetch(`http://127.0.0.1:${PORT}/add_entry`, {
method: "POST",
body: formData
});
@ -401,7 +403,7 @@ async function deleteEntry() {
const formData = new FormData()
formData.append("entry_name", localStorage.getItem("editVal"))
try {
const response = await fetch('/delete_entry', {
const response = await fetch(`http://127.0.0.1:${PORT}/delete_entry`, {
method: "POST",
body: formData
});
@ -479,7 +481,7 @@ async function sendPass(password) {
const formData = new FormData()
formData.append("password", password)
try {
const response = await fetch('/change_password', {
const response = await fetch(`http://127.0.0.1:${PORT}/change_password`, {
method: "POST",
body: formData
});
@ -599,7 +601,7 @@ async function addNewField(sitename, field, value) {
formData.append("field_value", value)
try {
const response = await fetch('/add_field', {
const response = await fetch(`http://127.0.0.1:${PORT}/add_field`, {
method: "POST",
body: formData
});
@ -628,7 +630,7 @@ async function editFieldValue(sitename, field, value) {
formData.append("field_value", value)
try {
const response = await fetch('/edit_field_value', {
const response = await fetch(`http://127.0.0.1:${PORT}/edit_field_value`, {
method: "POST",
body: formData
});
@ -655,7 +657,7 @@ async function changeEntryName(entryname, sitename) {
formData.append("new_entry_name", sitename)
try {
const response = await fetch('/edit_entry_name', {
const response = await fetch(`http://127.0.0.1:${PORT}/edit_entry_name`, {
method: "POST",
body: formData
});
@ -795,7 +797,7 @@ function closePopup() {
async function logOut() {
try{
await fetch("/logout", {
await fetch(`http://127.0.0.1:${PORT}/logout`, {
method:'POST',
headers: {
'Content-Type': 'application/json',

View File

@ -1,3 +1,5 @@
const PORT = 5000;
let loginb = document.getElementById("loginb");
loginb.addEventListener("click", validateLogin);
@ -48,7 +50,7 @@ formData.append('password', _password);
// console.log(formData)
try {
const response = await fetch('/login', {
const response = await fetch(`http://127.0.0.1:${PORT}/login`, {
method: "post",
body: formData
});
@ -88,7 +90,7 @@ register.addEventListener("click", function(event) {
window.onload = async function() {
try {
let response = await fetch('/get_data', {
let response = await fetch(`http://127.0.0.1:${PORT}/get_data`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'

View File

@ -1,4 +1,4 @@
const PORT = 5000
const errlabel = document.getElementById('errlabel')
function validateRegister() {
@ -29,7 +29,7 @@ async function createUser(username,password) {
formData.append("password", password)
try {
const response = await fetch('/add_user', {
const response = await fetch(`http://127.0.0.1:${PORT}/add_user`, {
method: "POST",
body: formData
});
@ -40,7 +40,7 @@ async function createUser(username,password) {
const errorMessage = await response.text();
errlabel.textContentL = errorMessage;
setTimeout(()=> {
errorlabel.textContent = "";
errlabel.textContent = "";
},3000)
throw new Error(errorMessage);
}
@ -55,7 +55,7 @@ async function Login(username,password){
formData.append('password', password);
try {
const response = await fetch('/login', {
const response = await fetch(`http://127.0.0.1:${PORT}/login`, {
method: "post",
body: formData
});

View File

@ -1193,7 +1193,6 @@ footer p{
@media (max-width: 860px) {
.container{
position: fixed;
width: 774px;
}
}

1030
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

18
package.json Normal file
View File

@ -0,0 +1,18 @@
{
"name": "password-manager",
"version": "1.0.0",
"description": "A Password Manager",
"main": "frontend/main.js",
"scripts": {
"test": "electronmon .",
"start": "electron ."
},
"author": "",
"license": "MIT",
"dependencies": {
"electron": "^27.0.2"
},
"devDependencies": {
"electronmon": "^2.0.2"
}
}