Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
database3.db.sqbpro
Binary file removed __pycache__/app.cpython-37.pyc
Binary file not shown.
96 changes: 61 additions & 35 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,21 @@ def __init__(self,name,email,phone,password,score,nextq):

class Quiz(db.Model):
id=db.Column('id',db.Integer,primary_key=True)
q=db.Column('questions',db.String(1000))
q=db.Column('questions',db.String(1000))
a=db.Column('answer',db.String(200))
o=db.Column('options',db.String(400))

def __init__(self,q,a):
self.q=q
self.a=a
def __init__(self,q,o,a):
self.q=q
self.a=a
self.o=o


def user_already_exists(users, email):
for user in users:
if user.email == email:
return True
return False


@app.route('/',methods=['GET','POST'])
Expand All @@ -62,57 +69,68 @@ def home():
def register():

error=''
status = ''
users = User.query.all()

if request.method=='POST':
name=request.form['name']
email=request.form['email']
phone=request.form['phone']
password=request.form['password']
confirmpassword=request.form['confirmpassword']


if password==confirmpassword:
score=0
nextq=0
pw_hash=bcrypt.generate_password_hash(password)
new_user=User(name,email,phone,pw_hash,score,nextq)
db.session.add(new_user)
db.session.commit()
return redirect(url_for('login'))
if user_already_exists(users, email):
status = 'show'
error = 'User already exists'
else:
error="Password didn't match"
return render_template('register.html',error=error)
if password==confirmpassword:
score=0
nextq=0
pw_hash=bcrypt.generate_password_hash(password)
new_user=User(name,email,phone,pw_hash,score,nextq)
db.session.add(new_user)
db.session.commit()
return redirect(url_for('login'))
else:
status = 'show'
error="Password didn't match"
return render_template('register.html', status=status, error=error)

return render_template('register.html')
return render_template('register.html', status=status, error=error)


@app.route('/login',methods=['GET','POST'])
def login():
def login():

users=[]
error=''
status = ''
users= User.query.all()
if request.method=='POST':
session.pop('user_id',None)

email=request.form['email']
password=request.form['password']
user=''
user=None
#user= [x for x in users if x.email==email ][0]
for x in users:
if x.email==email:
user=x
else:
user=None
if user and bcrypt.check_password_hash(user.password,password) :
if x.email == email:
user = x
break

if user and bcrypt.check_password_hash(user.password,password):
session['user_id']=user.id
session["log"]=True
flash('You were successfully logged in')
flash('You were successfully logged in', "message")
return redirect(url_for('profile'))
elif user == None:
status = 'show'
error="Incorrect credentials or user does not exist. Please Register"
else:
status = 'show'
error = 'Incorrect email address or password'

elif user==None:
error="Incorrect credentials. Please enter valid credential"

return render_template('login.html',error=error)
return render_template('login.html')
return render_template('login.html', status=status, error=error)
return render_template('login.html', status=status, error=error)

@app.route('/logout')
def logout():
Expand Down Expand Up @@ -147,8 +165,10 @@ def quiz():
current_question=ques

score=int(u.score)
opt=str(current_question.o)
opt=opt.split(',')

return render_template('quiz.html',current_question=current_question,score=score,done=done)
return render_template('quiz.html',current_question=current_question,score=score,opt=opt,done=done)

@app.route('/process/<current_question>',methods=['POST'])
def process(current_question):
Expand All @@ -160,20 +180,26 @@ def process(current_question):

answer=request.form['ans']

if answer.lower()==ques.a:
if str(answer)==str(ques.a):
score+=int(1)
question_num+=int(1)


else:
flash('Wrong answer')
flash('Previous answer was Wrong. Answer carefully')

question_num+=int(1)
u.score=score
u.nextq=question_num
db.session.commit()

return redirect(url_for('quiz'))


@app.route('/about')
def about():
return render_template('about.html')

if __name__=='__main__':
app.debug=True
# app.debug=True
app.secret_key="efrwwseq4sfcwasdr3142qwdsf24wsd"
app.run()
Binary file modified database3.db
Binary file not shown.
1 change: 0 additions & 1 deletion database3.db.sqbpro

This file was deleted.

7 changes: 7 additions & 0 deletions templates/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "layout.html" %}
{% block body %}
<div>
<p> About UCSP Research Group
#descreption about group# </p>
</div>
{% endblock %}
13 changes: 4 additions & 9 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">About Us</a>
<a class="navbar-brand" href="/about">About Us</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
Expand All @@ -33,14 +33,6 @@
<a class="nav-link" href="/login">Log in</a>
</li>
{% endif %}








<!-- <li class="nav-item dropdown"> -->
<!-- <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
Expand Down Expand Up @@ -73,5 +65,8 @@
{% endwith %}
{% block body %}
{%endblock %}
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
56 changes: 36 additions & 20 deletions templates/login.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
{% extends "layout.html" %}
{% block body %}
<div class="continer">
<form action="" method="POST">

<div class="app-title">
<h1>Log in</h1>
</div>
<div class="form-group">
<input type="email" class="form-control" value="" placeholder="Email" name="email" required>
</div>
<div class="form-group">
<input type="password" class="form-control" value="" placeholder="Password" name="password" required>
</div>
<input type="submit" value="Log in" class="btn btn-primary " >
</form>
{% extends "layout.html" %} {% block body %}
<div class="container">
<form action="" method="POST">
<div class="app-title">
<h1>Log in</h1>
</div>
<p>
<h4>{{error}}</h4>
</p>
{% endblock %}
<div class="form-group">
<input
type="email"
class="form-control"
value=""
placeholder="Email"
name="email"
required
/>
</div>
<div class="form-group">
<input
type="password"
class="form-control"
value=""
placeholder="Password"
name="password"
required
/>
</div>
<input type="submit" value="Log in" class="btn btn-primary" />
</form>
<br>
<div class="alert alert-danger alert-dismissible fade {{ status }}" role="alert">
{{ error }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
</div>
{% endblock %}
8 changes: 5 additions & 3 deletions templates/profile.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% extends "layout.html" %}
{% block body %}
<h1> Are you ready to play {{g.user.name}}? If yes enter now! </h1>
<h2> Hello {{g.user.name}}! </h2>
<br/>
<div>
<p><a type="button" class="btn btn-link" href="{{url_for('quiz')}}"><button>Enter</button></a></p>
<p><a href="{{url_for('quiz')}}" class="btn btn-primary" role="button">Next</a></p>
</div>
{% endblock %}
{% endblock %}

11 changes: 7 additions & 4 deletions templates/quiz.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ <h3>Your Score:{{ score }}</h3>
<p>
<b>{{ current_question.id }}:{{ current_question.q }}</b>
</p>
<ul>
<input type="text" name="ans" value="" />
</ul>
<ul style="list-style: none;">
{% for option in opt %}
<li style="display: inline-block;"><input type="radio" name="ans" value="{{ option }}" /></li>
{{ option }} {% endfor %}
</ul>

<input type="submit" value="Next" class="btn btn-primary " >

</form>
{% else %}
<h3>Thank You for Playing</h3>
{% endif %}
{% endblock %}
{% endblock %}
Loading