This repository has been archived by the owner on Oct 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistration.html
124 lines (116 loc) · 4.2 KB
/
registration.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>File Manager</title>
<script src="/js/jquery-3.3.1.min.js"></script>
<script src="/js/jsencrypt.min.js"></script>
<link rel="stylesheet" href="/css/demo.css">
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<div class="container">
<header style="color:#F0F8FF;">
<br>
<h1>Simple File Manager</h1>
</header>
<div id="LoggingInput" class="logbody">
Username: <input type="text" id="username"><br>
Password: <input type="password" id="password"><br>
<button class="logbtn" id="loginBtn">Log in</button>
<button class="logbtn" id="registBtn">Register</button>
</div>
<footer>
<div>
<p>Author: LKCT, FMH, YKQ, LXT, WRX<br>Copyright © www.helloweba.net</p>
</div>
</footer>
</div>
</body>
<script>
// Login
$(document).ready(() => {
$("#loginBtn").on("click", function () {
var name = $("#username").val();
var value = Encrypt($("#password").val());
var auth = new URLSearchParams();
var params = new URLSearchParams();
var formData = new FormData();
auth.append("user", name);
auth.append("passwd", value);
params.append("func", "login");
formData.append("auth", auth);
formData.append("params", params);
// Login Request
$.ajax({
url: "/cgi-bin/serve.py",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function (response) {
var json = JSON.parse(response);
localStorage.token = json.token;
localStorage.path = "/" + name;
window.location.href = "/Main_page.html";
},
error: function (xhr) {
var json = JSON.parse(xhr.responseText);
if (json.errno == 2) {
alert("The password does not match the username or the username does not exist!");
}
}
});
});
// Registration
$("#registBtn").on("click", function () {
var name = $("#username").val();
var value = Encrypt($("#password").val());
var auth = new URLSearchParams();
var params = new URLSearchParams();
var formData = new FormData();
auth.append("user", name);
auth.append("passwd", value);
params.append("func", "reg");
formData.append("auth", auth);
formData.append("params", params);
$.ajax({
url: "/cgi-bin/serve.py",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function (response) {
alert("You've already registered!\nPlease log in.");
},
error: function (xhr) {
var json = JSON.parse(xhr.responseText);
if (json.errno == 4)
alert("Illegal username! Please choose another username!");
else if (json.errno == 8)
alert('Oops! The username has already been used!');
}
});
});
});
function Encrypt(passwd) {
var key = "";
$.ajax({
async: false,
url: "/public.key",
type: "GET",
success: function (response) {
key = response;
},
error: function (xhr) {
alert(xhr.status + " " + xhr.statusText + "\n"
+ xhr.responseText);
}
});
var encrypt = new JSEncrypt();
encrypt.setPublicKey(key);
var res = encrypt.encrypt(passwd);
return res;
}
</script>
</html>