-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
120 lines (105 loc) · 3.7 KB
/
app.py
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
from flask import Flask
from flask import Response
from flask import render_template
from flask import Blueprint
# from flask import request
from flask import request, jsonify
import uuid
import json
# from app import app, mongo
from pymongo import MongoClient
from bson import json_util
from flask import redirect
MONGODB_HOST = 'localhost'
MONGODB_PORT = 27017
DB_NAME = 'Asrez'
COLLECTION_LINK="Link"
class flaskLocal(Flask):
def process_response(self, response):
# response.headers
return(response)
app = flaskLocal(__name__)
#app.config.SERVER_NAME = 'asrez.base:80'
#app.config
@app.route('/')
def index():
return render_template('index.html')
@app.route('/single')
def single():
return render_template('single.html')
@app.route('/projects/')
def projects():
return 'The project page'
@app.route('/about')
def about():
return 'The about page'
# doc_count = col.count_documents(filter, skip=skip)
# results = col.find(filter).sort(sort).skip(skip).limit(limit)
linkRegistered= [
"api",
"login",
"register",
"exit",
"signin",
"signout",
]
@app.route('/link/', methods=['GET','POST'], defaults={'identifier':None})
@app.route('/link/<string:identifier>/',methods=['GET'])
def link(identifier):
mainSite="http://asrez.base/"
site="http://asrez.base/link/"
if identifier == None or identifier == '':
if request.method == "GET":
return render_template('link_index.html', error=False, method=request.method, random=uuid.uuid4().hex.upper()[0:7].lower(), site=site, mainSite=mainSite)
else:
url=request.form.get("url")
identifier=request.form.get("identifier")
if url and identifier:
allow=True
for item in linkRegistered:
if identifier in item:
allow=False
break
if allow:
exists=collectionLink.count_documents({"identifier":identifier})
if exists == False:
mydict = {"url":url,"identifier":identifier}
x = collectionLink.insert_one(mydict)
if x.inserted_id:
message="Success"
status=True
return render_template('link_index.html', error=False, message=message, method=request.method, identifier=identifier, status=status, site=site, mainSite=mainSite)
else:
status=False
message="Problem occur in generate link!"
return render_template('link_index.html', error=False, message=message, method=request.method, identifier=identifier, status=status, site=site, mainSite=mainSite)
else:
status=False
message="Aleady Exists!"
return render_template('link_index.html', error=False, message=message, method=request.method, identifier=identifier, status=status, site=site, mainSite=mainSite)
else:
status=False
message="Identifier is not Allow!"
return render_template('link_index.html', error=False, message=message, method=request.method, identifier=identifier, status=status, site=site, mainSite=mainSite)
else :
status=False
message="Failed alert!"
return render_template('link_index.html', error=False, message=message, method=request.method, identifier=identifier, status=status, site=site, mainSite=mainSite)
elif identifier in linkRegistered:
if identifier == "api":
return render_template('link_api.html', site=site, mainSite=mainSite)
else:
return "Soon..."
else:
get=collectionLink.find_one({"identifier":identifier})
if get != None:
# return get["url"]
return redirect(get["url"], code=302)
else:
message="Wrong link!"
return render_template('link_index.html', error=True, message=message, identifier=identifier, site=site, mainSite=mainSite)
if __name__ == '__main__':
connection = MongoClient(MONGODB_HOST, MONGODB_PORT)
collectionLink = connection[DB_NAME][COLLECTION_LINK]
# app.run(host='asrez.com', port=80, debug=False)
app.run(port=80)