(app.py) file: # Store this code in 'app.py' file   from flask import Flask, render_template, request, redirect, url_for, session from flask_mysqldb import MySQL import MySQLdb.cursors import re     app = Flask(__name__) if __name__ == "__main__":     app.run(debug=True)     app.secret_key = 'your secret key'   app.config['MYSQL_HOST'] = 'localhost' app.config['MYSQL_USER'] = 'root' app.config['MYSQL_PASSWORD'] = '' app.config['MYSQL_DB'] = '' mysql = MySQL(app)   @app.route('/') @app.route('/login', methods =['GET', 'POST']) def login():     msg = ''     if request.method == 'POST' and 'username' in request.form and 'password' in request.form:         username = request.form['username']         password = request.form['password']         cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)         cursor.execute('SELECT * FROM accounts WHERE username = % s AND password = % s', (username, password, ))         account = cursor.fetchone()         if account:                         msg = 'Logged in successfully !'             return render_template('index.html', msg = msg)         else:             msg = 'Incorrect username / password !'     return render_template('login.html', msg = msg)

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter11: Sql Server Databases
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question

Task question:

 

Step 1. You have been asked to add code in given template file “app.py” to enable login using employee table in test database. First

Create Data Base: test

Create table: employee

Table fields:

 

Id

Int

10(primary key) auto increment

username

Varchar

25

Password

Varchar

25

EmpMail

Varchar

25

 With 2 records

1

Manager

Manager123

manager@gmail.com

2

Teller

Teller123

teller@gmail.com

 

 

Login should have username and password field. You are asked to add SQL code to get successful login.

Step 2. you should also add error message if credentials are wrong-Validation step

Step 3:  Add code to login .html template file to create Login form using text and password fields.

Step 4. Add button to get sign-in action

Step 5: you should save the file in relevant locations to avoid path and output issues.

Step 6. You should have proper database connectivity to succeed in this lab worksheet. Successful connection to database also will be counted for marking.

 

Show your outputs through screenshots.

 

 

 

(app.py) file:

# Store this code in 'app.py' file
 
from flask import Flask, render_template, request, redirect, url_for, session
from flask_mysqldb import MySQL
import MySQLdb.cursors
import re
 
 
app = Flask(__name__)
if __name__ == "__main__":
    app.run(debug=True)
 
 
app.secret_key = 'your secret key'
 
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = ''
app.config['MYSQL_DB'] = ''
mysql = MySQL(app)
 
@app.route('/')
@app.route('/login', methods =['GET', 'POST'])
def login():
    msg = ''
    if request.method == 'POST' and 'username' in request.form and 'password' in request.form:
        username = request.form['username']
        password = request.form['password']
        cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
        cursor.execute('SELECT * FROM accounts WHERE username = % s AND password = % s', (username, password, ))
        account = cursor.fetchone()
        if account:
           
            msg = 'Logged in successfully !'
            return render_template('index.html', msg = msg)
        else:
            msg = 'Incorrect username / password !'
    return render_template('login.html', msg = msg)

Step 1. You have been asked to add code in given template file "app.py" to enable login using
employee table in test database. First
Create Data Base: test
Create table: employee
Table fields:
Id
username
Password
EmpMail
With 2 records
1
2
Int
Varchar
Varchar
Varchar
Manager
Teller
10(primary key) auto increment
25
25
25
Manager 123
Teller 123
manager@gmail.com
teller@gmail.com
Login should have username and password field. You are asked to add SQL code to get
successful login.
Step 2. you should also add error message if credentials are wrong-Validation step
Step 3: Add code to login .html template file to create Login form using text and password
fields.
Step 4. Add button to get sign-in action
Step 5: you should save the file in relevant locations to avoid path and output issues.
Transcribed Image Text:Step 1. You have been asked to add code in given template file "app.py" to enable login using employee table in test database. First Create Data Base: test Create table: employee Table fields: Id username Password EmpMail With 2 records 1 2 Int Varchar Varchar Varchar Manager Teller 10(primary key) auto increment 25 25 25 Manager 123 Teller 123 manager@gmail.com teller@gmail.com Login should have username and password field. You are asked to add SQL code to get successful login. Step 2. you should also add error message if credentials are wrong-Validation step Step 3: Add code to login .html template file to create Login form using text and password fields. Step 4. Add button to get sign-in action Step 5: you should save the file in relevant locations to avoid path and output issues.
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning