def temp(user): if request.method == 'POST': data = request.values if data['age_in_weeks'] == '1' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 1 ") data = flaskdbcur.fetchall() if flaskdbcur.rowcount<0: feedback = flaskdbcur.fetchone() global temper temper= feedback[7] flaskdbcur = flaskdb.cursor() flaskdbcur.execute('INSERT INTO temperature(age_in_weeks,temperature) VALUES( %s, %s)',(data['age_in_weeks'],temper,)) flaskdb.commit() return redirect ('/temp/user') return render_template( 'temperature.html', data = data) elif data['age_in_weeks'] == '2' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 1 ") data = flaskdbcur.fetchall() if flaskdbcur.rowcount<0: feedback = flaskdbcur.fetchone() global temper temper= feedback[7] - 3 flaskdbcur = flaskdb.cursor() flaskdbcur.execute('INSERT INTO temperature(age_in_weeks,temperature) VALUES( %s, %s)',(data['age_in_weeks'],temper,)) flaskdb.commit() return redirect ('/temp/user') return render_template( 'temperature.html', data = data) elif data['age_in_weeks'] == '3' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 1 ") data = flaskdbcur.fetchall() if flaskdbcur.rowcount<0: global temper temper= feedback[7] - 6 flaskdbcur = flaskdb.cursor() flaskdbcur.execute('INSERT INTO temperature(age_in_weeks,temperature) VALUES( %s, %s)',(data['age_in_weeks'],temper,)) flaskdb.commit() return redirect ('/temp/user') return render_template( 'temperature.html', data = data) return render_template( 'temperature.html', user = user , title = 'Temperature')
def login(): #We use post http request to check if request.method == 'POST': data = request.values #Ensure the user name and data is not empty if data['username'] == ''or data['pwd'] == '' : return redirect(url_for('login')) #If username and data is there the we check in the db else: #We pick from the dbc script flaskdb = dbconnect('aftermath','root','') #Run the cursor command flaskdbcur = flaskdb.cursor() #Execute the cursor command to select the db flaskdbcur.execute('SELECT * FROM users WHERE username = %s',(data['username'],)) #Ensure the database is not blank and fetch one print ('usernama done') if flaskdbcur.rowcount < 0: print ('username brought back') users = flaskdbcur.fetchone() #Once fectched we compare if the value input is same as the databse input if users[2] == data['pwd']: global username username = users[1] #if the value is the same it executes this return redirect ('/home/' + users[1]) #if not it executes this and one is redirected back to his login page else: return redirect('/login') else: return redirect ('login') else: return render_template('login.html', title = 'Login')
def login(): #We use post http request to check if request.method == 'POST': data = request.values #Ensure the user name and data is not empty if data['user'] == '' or data['pwd'] == '': return redirect('/login') #If username and data is there the we check in the db else: #We pick from the dbc script flaskdb = dbconnect('flaskdb', 'david', 'root') flaskdbcur = flaskdb.cursor() flaskdbcur.execute('SELECT * FROM users WHERE name = %s', (data['user'], )) if flaskdbcur.rowcount > 0: users = flaskdbcur.fetchone() if users[2] == data['pwd']: global username username = users[1] return redirect('/home/' + users[1]) else: return redirect('/login') else: return redirect('/login') else: return render_template('login.html')
def deletepass(): if request.method == 'POST': data = request.values flaskdb = dbconnect('flaskdb', 'david', 'root') flaskdbcur = flaskdb.cursor() flaskdbcur.execute('DELETE FROM users WHERE name =%s ', (username, )) flaskdb.commit() return redirect('/login') #If username and data is there the we check in the db else: #We pick from the dbc script return render_template('updatepass.html')
def register(): if request.method == 'POST': data = request.values if data['user'] == '' or data['pwd'] == '' or data['pwd2'] == '': return redirect('/register') elif data['pwd'] != data['pwd2']: return redirect('/register') else: flaskdb = dbconnect('flaskdb', 'david', 'root') flaskdbcur = flaskdb.cursor() flaskdbcur.execute( 'INSERT INTO users(name, password) VALUES(%s, %s)', (data['user'], data['pwd'])) flaskdb.commit() return redirect('/login') else: return render_template('register.html')
def register(): if request.method == 'POST': #Ensure not a single field is blank data = request.values if data['name'] == '' or data['pwd'] == '' or data['pwd2'] == '' or data['email'] == '' or data['firstname'] == '' or data['lastname'] == '': return redirect('/register') #To ensure the password is the same elif data['pwd'] != data['pwd2']: return redirect ('/register' ) else : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() flaskdbcur.execute('INSERT INTO users(username, password, email, firstname, lastname) VALUES(%s, %s, %s,%s, %s)',(data['name'],data['pwd'],data['email'],data['firstname'],data['lastname'])) flaskdb.commit() return redirect ('/login') else: return render_template('register.html',title = 'Registration')
def updatepass(): if request.method == 'POST': data = request.values #Ensure the user name and data is not empty if data['pwd'] == '' or data['npwd'] == '': return redirect('/updatepass') #If username and data is there the we check in the db else: #We pick from the dbc script flaskdb = dbconnect('flaskdb', 'david', 'root') flaskdbcur = flaskdb.cursor() flaskdbcur.execute( 'UPDATE users SET password = %s WHERE name = %s', (data['npwd'], username)) flaskdb.commit() return redirect('/product') else: return render_template('updatepass.html')
def vaccine(user): if request.method == 'POST': data = request.values if data['age_in_day'] == '1' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO vaccines(age_in_days,comments) VALUES( %s, %s)',(data['age_in_day'],data['comments'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 1 ") data = flaskdbcur.fetchall() return render_template( 'vaccine.html', data = data) elif data['age_in_day'] == '14' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO vaccines(age_in_days,comments) VALUES( %s, %s)',(data['age_in_day'],data['comments'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 2 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'vaccine.html', data = data) elif data['age_in_day'] == '21' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO vaccines(age_in_days,comments) VALUES( %s, %s)',(data['age_in_day'],data['comments'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 3 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'vaccine.html', data = data) elif data['age_in_day'] == '24' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO vaccines(age_in_days,comments) VALUES( %s, %s)',(data['age_in_day'],data['comments'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 4 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'vaccine.html', data = data) elif data['age_in_day'] == '42' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO vaccines(age_in_days,comments) VALUES( %s, %s)',(data['age_in_day'],data['comments'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 5 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'vaccine.html', data = data) elif data['age_in_day'] == '56' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO vaccines(age_in_days,comments) VALUES( %s, %s)',(data['age_in_day'],data['comments'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 6 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'vaccine.html', data = data) elif data['age_in_day'] == '126' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO vaccines(age_in_days,comments) VALUES( %s, %s)',(data['age_in_day'],data['comments'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 7 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'vaccine.html', data = data) elif data['age_in_day'] == '133' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username fflaskdbcur.execute('INSERT INTO vaccines(age_in_days,comments) VALUES( %s, %s)',(data['age_in_day'],data['comments'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 8 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'vaccine.html', data = data) elif data['age_in_day'] == '' or data['age_in_day'] != "" : return render_template( 'vaccine.html', data = data) else: flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO vaccines(age_in_days,comments) VALUES( %s, %s)',(data['age_in_day'],data['comments'],)) flaskdb.commit() return redirect('/home/<user>') return render_template( 'vaccine.html', user = user , title = 'Vaccine')
def home(user): if request.method == 'POST': data = request.values if data['no_of_weeks'] <= '1' : print ('user back') flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO feed(age_in_weeks,type_of_feed, intake_per_day) VALUES( %s, %s, %s)',(data['no_of_weeks'],data['type_of_feed'],data['intake_per_day'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 1 ") data = flaskdbcur.fetchall() return render_template( 'homepage.html', data = data) elif data['no_of_weeks'] <= '2' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username #flaskdbcur.execute('INSERT INTO feed(age_in_weeks,type_of_feed, intake_per_day) VALUES( %s, %s, %s)',(data['no_of_weeks'],data['type_of_feed'],data['intake_per_day'],)) #flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 2 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'homepage.html', data = data) elif data['no_of_weeks'] <= '3' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO feed(age_in_weeks,type_of_feed, intake_per_day) VALUES( %s, %s, %s)',(data['no_of_weeks'],data['type_of_feed'],data['intake_per_day'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 3 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'homepage.html', data = data) elif data['no_of_weeks'] <= '4' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO feed(age_in_weeks,type_of_feed, intake_per_day) VALUES( %s, %s, %s)',(data['no_of_weeks'],data['type_of_feed'],data['intake_per_day'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 4 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'homepage.html', data = data) elif data['no_of_weeks'] <= '5' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO feed(age_in_weeks,type_of_feed, intake_per_day) VALUES( %s, %s, %s)',(data['no_of_weeks'],data['type_of_feed'],data['intake_per_day'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 5 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'homepage.html', data = data) elif data['no_of_weeks'] <= '6' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO feed(age_in_weeks,type_of_feed, intake_per_day) VALUES( %s, %s, %s)',(data['no_of_weeks'],data['type_of_feed'],data['intake_per_day'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 6 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'homepage.html', data = data) elif data['no_of_weeks'] <= '7' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO feed(age_in_weeks,type_of_feed, intake_per_day) VALUES( %s, %s, %s)',(data['no_of_weeks'],data['type_of_feed'],data['intake_per_day'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 7 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'homepage.html', data = data) elif data['no_of_weeks'] <= '8' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO feed(age_in_weeks,type_of_feed, intake_per_day) VALUES( %s, %s, %s)',(data['no_of_weeks'],data['type_of_feed'],data['intake_per_day'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 8 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'homepage.html', data = data) elif data['no_of_weeks'] <= '9' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO feed(age_in_weeks,type_of_feed, intake_per_day) VALUES( %s, %s, %s)',(data['no_of_weeks'],data['type_of_feed'],data['intake_per_day'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 9 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'homepage.html', data = data) elif data['no_of_weeks'] <= '10' : flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO feed(age_in_weeks,type_of_feed, intake_per_day) VALUES( %s, %s, %s)',(data['no_of_weeks'],data['type_of_feed'],data['intake_per_day'],)) flaskdb.commit() flaskdbcur.execute("SELECT * FROM feedback WHERE id = 10 ORDER BY id DESC") data = flaskdbcur.fetchall() return render_template( 'homepage.html', data = data) else: flaskdb = dbconnect('aftermath','root','') flaskdbcur = flaskdb.cursor() global username flaskdbcur.execute('INSERT INTO feed(age_in_weeks,type_of_feed, intake_per_day) VALUES( %s, %s, %s)',(data['no_of_weeks'],data['type_of_feed'],data['intake_per_day'],)) flaskdb.commit() return redirect('/home/<user>') return render_template('homepage.html', title = 'Feeds', user = user )