-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
221 lines (194 loc) Β· 8.74 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
from flask import Flask, render_template,url_for,redirect,flash, request, redirect,session
from bson import ObjectId
from hashlib import md5
#from wtforms import Form, BooleanField, TextField, PasswordField, validators
from pymongo import MongoClient
from flask.wrappers import Response
import re
import os
import bcrypt
app=Flask(__name__)
client=MongoClient("mongodb://127.0.0.1:27017")
db=client.studentscorner
usersdb=db.users
edu=db.Education
exp=db.Experience
certify=db.Certifications
project=db.Projects
volunteership=db.Volunteership
contactss=db.Contacts
@app.route('/')
def index():
return render_template('index.html')
@app.route('/main')
def main():
educationlist=edu.find()
experiencelist=exp.find()
certificatelist=certify.find()
projectlist=project.find()
volunteerlist=volunteership.find()
contactlist=contactss.find()
return render_template('main.html',educationlist=educationlist,experiencelist=experiencelist,certificatelist=certificatelist,projectlist=projectlist,volunteerlist=volunteerlist,contactlist=contactlist)
@app.route('/login',methods=["GET","POST"])
def login():
message = 'Please login to your account'
if "username" in session:
return redirect(url_for("main"))
if request.method == "POST":
username= request.form.get("username")
password = request.form.get("psw")
username_found = usersdb.find_one({"username": username})
if username_found:
username_val = username_found['username']
passwordcheck = username_found['password']
if bcrypt.checkpw(password.encode('utf-8'), passwordcheck):
session["username"] = username_val
return redirect(url_for('main'))
else:
if "username" in session:
return redirect(url_for("main"))
message = 'Wrong password'
return render_template('login.html', message=message)
else:
message = 'Email not found'
return render_template('login.html', message=message)
return render_template('login.html', message=message)
@app.route('/register',methods=["GET","POST"])
def register():
if request.method == 'POST':
existing_user = usersdb.find_one({'username' : request.form['username']})
email = usersdb.find_one({'email' : request.form['email']})
if existing_user is None:
hashpass = bcrypt.hashpw(request.form['psw'].encode('utf-8'), bcrypt.gensalt())
usersdb.insert_one({'username' : request.form['username'], 'password' : hashpass,'email':request.form['email']})
session['username'] = request.form['username']
return render_template('login.html')
return 'That username already exists!'
return render_template('register.html')
@app.route('/logout', methods = ['GET'])
def logout():
session.pop('username')
return redirect(url_for('index'))
@app.route('/education',methods=['get','post'])
def education():
if request.method=='GET':
return render_template("main.html")
elif request.method=='POST':
educationtitle=request.values.get('educationtitle')
specializationtitle=request.values.get('specializationtitle')
edujoinmonth=request.values.get('edujoinmonth')
edujoinyears=request.values.get('edujoinyears')
eduendmonth=request.values.get('eduendmonth')
eduendyear=request.values.get('eduendyear')
collegetitle=request.values.get('collegetitle')
cgpaselect=request.values.get('cgpaselect')
cgpaname=request.values.get('cgpaname')
edu.insert_one({'educationtitle':educationtitle,'specializationtitle':specializationtitle,'edujoinmonth':edujoinmonth,'edujoinyears':edujoinyears,'eduendmonth':eduendmonth,'eduendyear':eduendyear,'collegetitle':collegetitle,'cgpaselect':cgpaselect,'cgpaname':cgpaname})
return redirect(url_for('main'))
@app.route('/delete')
def delete():
edu.delete_one({})
return redirect(url_for('main'))
@app.route("/experience",methods=['GET','POST'])
def experience():
if request.method=='GET':
return render_template('main.html')
elif(request.method=='POST'):
exptitle=request.values.get("exptitle")
comptitle=request.values.get("comptitle")
emptitle=request.values.get("emptitle")
expjoinmonth=request.values.get("expjoinmonth")
expjoinyear=request.values.get("expjoinyear")
expendmonth=request.values.get("expendmonth")
expendyear=request.values.get("expendyear")
expdescription=request.values.get("expdescription")
expdrivelink=request.values.get("expdrivelink")
exp.insert_one({'exptitle':exptitle,'comptitle':comptitle,'emptitle':emptitle,'expjoinmonth':expjoinmonth,'expjoinyear':expjoinyear,'expendmonth':expendmonth,
'expendyear':expendyear,'expdescription':expdescription,'expdrivelink':expdrivelink})
return redirect(url_for('main'))
@app.route('/deleteexperience')
def deleteexp():
exp.delete_one({})
return redirect(url_for('main'))
@app.route("/certification",methods=['GET','POST'])
def certification():
if request.method=='GET':
return render_template('main.html')
elif(request.method=='POST'):
certifytitle=request.values.get("certifytitle")
certorgtitle=request.values.get("certorgtitle")
certjoinmonth=request.values.get("certjoinmonth")
certjoinyear=request.values.get("certjoinyear")
certendmonth=request.values.get("certendmonth")
certendyear=request.values.get("certendyear")
certurl=request.values.get("certurl")
certify.insert_one({'certifytitle':certifytitle,'certorgtitle':certorgtitle,'certjoinmonth':certjoinmonth,'certjoinyear':certjoinyear,'certendyear':certendyear,
'certendmonth':certendmonth,'certurl':certurl})
return redirect(url_for('main'))
@app.route('/deletecertification')
def deletecertify():
certify.delete_one({})
return redirect(url_for('main'))
@app.route("/project",methods=['get','post'])
def projects():
if request.method=='GET':
return render_template('main.html')
else:
protitle=request.values.get("protitle")
prostartmonth=request.values.get("prostartmonth")
prostartyear=request.values.get("prostartyear")
proendmonth=request.values.get("proendmonth")
proendyear=request.values.get("proendyear")
prourl=request.values.get("prourl")
prodescription=request.values.get("prodescription")
project.insert_one({'protitle':protitle,'prostartmonth':prostartmonth,'prostartyear':prostartyear,'proendmonth':proendmonth,
'proendyear':proendyear,'prourl':prourl,'prodescription':prodescription})
return redirect(url_for("main"))
@app.route('/deleteproject')
def deleteproject():
project.delete_one({})
return redirect(url_for('main'))
@app.route("/volunteership",methods=['get','post'])
def volunteer():
if request.method=='GET':
return render_template('main.html')
else:
voltitle=request.values.get("voltitle")
volorgtitle=request.values.get("volorgtitle")
volstartmonth=request.values.get("volstartmonth")
volstartyear=request.values.get("volstartyear")
volendmonth=request.values.get("volendmonth")
volendyear=request.values.get("volendyear")
voldescription=request.values.get("voldescription")
volurl=request.values.get("volurl")
volunteership.insert_one({'voltitle':voltitle,'volorgtitle':volorgtitle,'volstartmonth':volstartmonth,'volstartyear':volstartyear,'volendmonth':volendmonth,
'volendyear':volendyear,'volurl':volurl,'voldescription':voldescription})
return redirect(url_for("main"))
@app.route('/deletevolunteership')
def deletevolunteer():
volunteership.delete_one({})
return redirect(url_for('main'))
@app.route("/contact",methods=['get','post'])
def contacts():
if request.method=='GET':
return render_template('main.html')
else:
website=request.values.get("website")
emailtitle=request.values.get("emailtitle")
phno=request.values.get("phno")
addresstitle=request.values.get("addresstitle")
contactss.insert_one({'website':website,'emailtitle':emailtitle,'phno':phno,'addresstitle':addresstitle})
return redirect(url_for("main"))
@app.route('/deletecontact')
def deletecontact():
contactss.delete_one({})
return redirect(url_for('main'))
@app.route('/search',methods=["GET","post"])
def searchuser():
exuname= usersdb.find_one({'username' :request.values.get('unname')})
if exuname is not None:
return render_template('usersprofile.html')
return "not exist"
if __name__=='__main__':
app.secret_key = 'super secret key'
app.run(debug=True)