This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
132 lines (130 loc) · 4.88 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const {loadUserData, updateUserData} = require("./utils/userData");
const toastr = require('toastr');
const swal = require('sweetalert');
const validator = require('validator');
const {ipcRenderer, remote} = require("electron");
const promptConfirmationCode = (id) => {
swal("Confirmation code", {
content: "input",
})
.then((value) => {
// swal(`You typed: ${value}`);
fetch("http://127.0.0.1:3000/verify", {
method: "POST", // *GET, POST, PUT, DELETE, etc.
mode: "cors", // no-cors, *cors, same-origin
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
credentials: "same-origin", // include, *same-origin, omit
headers: {
"Content-Type": "application/json",
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: "follow", // manual, *follow, error
referrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify({"id":id, "code": value}), // body data type must match "Content-Type" header
})
.then(res => res.json())
.then(res => {
if (res["matched"] === true) {
swal("Congratulations", "You have successfully created your account", "success").then(()=>{
ipcRenderer.send(
"asynchronous-message",
"successfullyLoggedin"
);
updateUserData("loggedIn", true);
updateUserData("id", res["id"]);
return true;
});
} else {
swal("Wrong code", "Please recheck your code", "warning").then(
() => {
promptConfirmationCode(id);
}
);
}
})
});
}
const signup = () => {
let username = document.getElementById("username").value;
let email = document.getElementById("email").value;
let password = document.getElementById("pwd").value;
if(email.length==0)
{
toastr.error("Please provide email", "Email required");
return;
}
if (username.length == 0) {
toastr.error("Please provide username", "Username required");
return;
}
if (password.length == 0) {
toastr.error("Please provide password", "Password required");
return;
}
if(!validator.isEmail(email))
{
toastr.warning("Please provide valid email", "Invalid email");
return;
}
// updateUserData("loggedIn", true);
// console.log(username);
// console.log(email);
// console.log(password);
let signupPostData = {
username,
email,
password
};
fetch("http://127.0.0.1:3000/signup", {
method: "POST", // *GET, POST, PUT, DELETE, etc.
mode: "cors", // no-cors, *cors, same-origin
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
credentials: "same-origin", // include, *same-origin, omit
headers: {
"Content-Type": "application/json",
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: "follow", // manual, *follow, error
referrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(signupPostData), // body data type must match "Content-Type" header
})
.then(res => res.json())
.then(res => {
if(res["signed_up"])
{
promptConfirmationCode(res["id"]);
}else{
toastr.error("User already existed");
}
})
;
// var python = require("child_process").spawn("./backend/venv/Scripts/python",
// ["./backend/test.py", username, email, password]
// );
// python.stdout.on("data", function (data) {
// console.log("Python response: ", data.toString("utf8"));
// const response = JSON.parse(data.toString());
// console.log(response);
// if(response["signed_up"])
// {
// ipcRenderer.send("asynchronous-message", "successfullySignedup");
// }
// // result.textContent = data.toString("utf8");
// });
// python.stderr.on("data", (data) => {
// console.error(`stderr: ${data}`);
// });
// python.on("close", (code) => {
// console.log(`child process exited with code ${code}`);
// });
}
document.getElementById("showLogin").addEventListener("click", () => {
// console.log("Working!");
ipcRenderer.send("asynchronous-message", "showLoginForm");
});
// const showLoginForm = () => {
// ipcRenderer.send("asynchronous-message", "showLogin");
// }
// const showSignup = () => {
// ipcRenderer.send("asynchronous-message", "showSignup");
// };