Skip to content

Commit 7a8101d

Browse files
committed
Make init code
1 parent 89a5292 commit 7a8101d

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

login-system/main.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from flask import request, jsonify, Flask, session, redirect, url_for, escape, render_template
2+
# from flask_cors import CORS, cross_origin
3+
# from flask_pymongo import PyMongo,ObjectId
4+
5+
app = Flask(__name__)
6+
app.secret_key = 'Superrandom'
7+
8+
session_details = ['username', 'password']
9+
10+
@app.route('/')
11+
def index():
12+
return render_template("index.html")
13+
14+
@app.route('/login', methods = ['GET', 'POST'])
15+
def login():
16+
if request.method == 'POST':
17+
session['username'] = request.form['username']
18+
session['password'] = request.form['password']
19+
return "Login"+str(session['username']),200
20+
return render_template("login.html")
21+
22+
@app.route('/logout')
23+
def logout():
24+
# remove the username from the session if it is there
25+
# session.pop('username', None)
26+
for d in session_details:
27+
session.pop(d, None)
28+
return redirect(url_for('index'))
29+
30+
@app.route('/test-auth',methods=['GET','POST'])
31+
def auth():
32+
if session['username']=='harsh':
33+
return "HS",200
34+
return "OK",200
35+
36+
@app.route('/test-login/<username>',methods=['GET','POST'])
37+
def lo(username):
38+
session['username'] = username
39+
return username,200
40+
41+
@app.route('/test-connection',methods=['GET','POST'])
42+
def func():
43+
return "OK",200
44+
45+
if __name__ == "__main__":
46+
app.run(host="0.0.0.0")

login-system/templates/index.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Cloud Desktop</title>
5+
</head>
6+
<body>
7+
8+
<h1>Welcome to Cloud Desktop</h1>
9+
<a href="/login"><h2>Login to Continue</h2></a>
10+
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+
17+
18+
</body>
19+
</html>

login-system/templates/login.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Cloud Desktop</title>
5+
</head>
6+
<body>
7+
8+
<h1>Login to Continue</h1>
9+
10+
<form action = "login" method = "post">
11+
<p><input type = text name = username> </p>
12+
<p><input type = text name = password> </p>
13+
<p<<input type = submit value = Login/> </p>
14+
</form>
15+
16+
17+
</body>
18+
</html>

login-system/templates/logout.html

Whitespace-only changes.

0 commit comments

Comments
 (0)