Skip to content

Commit 6d24da8

Browse files
committed
api sessions js
1 parent a28b5ea commit 6d24da8

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

login-system/main.py

+11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ def logout():
2727
session.pop(d, None)
2828
return redirect(url_for('index'))
2929

30+
@app.route('/api-auth-test')
31+
def apitestauth():
32+
data = {
33+
"test": 'no'
34+
}
35+
if session['username']:
36+
data = {
37+
"test": session['username']
38+
}
39+
return data
40+
3041
@app.route('/test-auth',methods=['GET','POST'])
3142
def auth():
3243
if session['username']=='harsh':

login-system/static/main.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
async function main(){
2+
var url = "localhost:5000/api-auth-test";
3+
const response = await fetch(url);
4+
var data = await response.json();
5+
document.getElementById("size").innerHTML="test = "+data['test'];
6+
console.log(data);
7+
}

login-system/templates/index.html

+19-8
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,27 @@
44
<title>Cloud Desktop</title>
55
</head>
66
<body>
7+
<script>
8+
async function main(){
9+
var url = "http://localhost:5000/api-auth-test";
10+
const response = await fetch(url);
11+
var data = await response.json();
12+
document.getElementById("test").innerHTML="test = "+data['test'];
13+
console.log(data);
14+
}
15+
</script>
716

8-
<h1>Welcome to Cloud Desktop</h1>
9-
<a href="/login"><h2>Login to Continue</h2></a>
17+
<h1>Welcome to Cloud Desktop</h1>
18+
<a href="/login"><h2>Login to Continue</h2></a>
1019

11-
<form action = "login" method = "post">
12-
<p>username : <input type = text name = username> </p>
13-
<p>password : <input type = text name = password> </p>
14-
<p> <input type = submit value = Login> </p>
15-
</form>
16-
20+
<form action = "login" method = "post">
21+
<p>username : <input type = text name = username> </p>
22+
<p>password : <input type = text name = password> </p>
23+
<p> <input type = submit value = Login> </p>
24+
</form>
25+
26+
<button onclick="main()">test</button>
27+
<h3 id="test"> Loading </h3>
1728

1829
</body>
1930
</html>

0 commit comments

Comments
 (0)