SDEV 300 University of Maryland Wk 7 Programming Environment in a Python Code program

User Generated

xnuybja

Programming

sdev 300

University of Maryland Global Campus

SDEV

Description

I need lab 7. I do have some of the stuff that I can provide for guidance. i attached some solution files that could be helpful for doing lab 7.

Unformatted Attachment Preview

Week 7 Deliverables Overview: This week, you studied additional Flask functionality for creating a secure login form and associated files for a web site. The Lab for this week demonstrates your knowledge of this additional Python functionality. Be sure to use the examples in the textbook reading along with the associate libraries, functions and processes when completing the assignments for this week. Submission requirements for this project includes multiple files. (Zipping them into one file is acceptable and encouraged):   Python Web Page Code (Python code, Templates, CSS and other associated files) Word or PDF file containing your test and pylint results Python Applications for this lab: (total 100 points): 1. (80 points) This exercise uses your programming environment to enhance the Web site you created last week with additional functionality to include images, tables and a Form using Python flask. Specifically, you will add two (2) additional routes allowing a user to register and login to a web site. Additional security considerations include other routes (beyond the register route) will not be accessible until a successful login has occurred. In addition to the requirements list above the following functionality should be found within your web site on one or more web pages.      Add at least 4 different images. The images should be local in your environment. For example, they should be saved in your environment and referenced similar to this syntax: A Table with at least 4 rows and 3 columns. A user registration form A user login form A password complexity should be enforced to include at least 12 characters in length, and include at least 1 uppercase character, 1 lowercase character, 1 number and 1 special character. The content and topic of the new images, and tables are up to you. How much is required for the user registration is up to you as well. However, the registration and associated login should contain at least a login name and password. Hints: 1. 2. 3. 4. 5. Start early. This will take you longer than you think. Test all aspects of the forms from input to output on your environment. Use comments to document your code Test with many combinations. Use pylint to verify the code style – the goal is a 10! 2. (20 points) Document your testing results using your programming environment. You should also include and discuss your pylint results for the application. The test document should include a test table 1 that includes the input values, the expected results and the actual results. A screen capture should be included that shows the actual test results of running each test case found in the test table. Be sure to include multiple test cases to provide full coverage for all code and for each function you develop and test. Any submissions that do not represent work originating from the student will be submitted to the Dean’s office and evaluated for possible academic integrity violations and sanctions. 2 app.py from datetime import date from flask import Flask, render_template app = Flask(__name__) @app.route('/') @app.route('/index.html') def home(): return render_template('index.html', date = date.today() ) @app.route('/page2.html') def page2(): return render_template('page2.html', date = date.today() ) @app.route('/page3.html') def page3(): return render_template('page3.html', date = date.today() ) if __name__ == '__main__': app.run(debug = True) index.html Index Page Page 1 Heading 2 Heading 3 One Two One Two Today is {{date}} Visit Site1 Visit Site2 Visit Site3 Page 2 Page 3 Document img{ height:300px; width:300px; } table,td{ border: 1px solid black; } form{ display:flex; flex-direction:column; } button{ width:200px; } .login-form{ width:300px; } input{ margin:5px; padding:10px; } function isStrongPwd(password){ var regExp = /(?=.*\d)(?=.*[a-z])(?=.*[!@#$%&*()]).{12,}/; var validPassword = regExp.test(password) return validPassword; } Images section Table section row1column1 row1column2 row1column3 row2column1 row2column2 row2column3 row3column1 row3column2 row3column3 row4column1 row4column2 row4column3 User Registration form Register Please fill in this form to create an account. Email Password Repeat Password Register Login form pythonlogin.py #pip install flask #pip install mysql from flask import Flask import mysql.connector from flask import render_template,url_for,flash,redirect from forms import LoginForm #render_template function is used to render the html file #url-for is used to get the url of the page by taking parameter #redirect is used to rediret from one page to another page app = Flask(__name__) # Change this to your secret key (can be anything, it's for extra protection) app.secret_key = 'your-secret-key' #initializing MySQL database mydb = mysql.connector.connect( host="localhost", user="your-username", passwd="your-password", port='3306' ) cursor = mydb.cursor() cursor.execute("USE new") #paths for the login function #get and post are form methods #GET used for getting data from form #POST used for posting the data to the page @app.route('/',methods=['GET','POST']) @app.route('/login',methods=['GET','POST']) def login(): #initializing form form = LoginForm() #True when form is submitted if form.validate_on_submit(): #get data from form username = form.email.data password = form.password.data print(username,password) #execute the query with username and password entered cursor.execute("SELECT * FROM logindb WHERE username = %s and password = %s", (username, password)) #Fetch one record and return result data = cursor.fetchone() #excute if data has somevalue if data: #flash is used for sending messages to the page flash('Login successful','success') #redirects the page to 'home' page return redirect(url_for('home')) else: #if details are invalid - unsuccessful flash('Login unsuccessful','danger') #renders this templete when the url is used #we can send values to the page-- ex:- title is variable , 'Login' is value return render_template('login.html',title='Login',form=form) @app.route('/home') def home(): #renders this templete when the '/home' is used return render_template('home.html') forms.py #installation #pip install flask_wtf from flask_wtf import FlaskForm from wtforms import StringField, PasswordField, SubmitField from wtforms.validators import InputRequired, Email class LoginForm(FlaskForm): #field functions are used to specify input types email = StringField('Email',validators=[InputRequired()]) password = PasswordField('Password',validators=[InputRequired()]) submit = SubmitField('Login') login.html {% block content %} {{ form.hidden_tag() }} {{ form.csrf_token }} LogIn {{ form.email.label(class="form-control-label") }} {% if form.email.errors %} {{ form.email(class="form-control form-control-lg is-invalid") }} {% for errors in form.email.errors %} {{ error }} {% endfor %} {% else %} {{ form.email(class="form-control form-control-lg") }} {% endif %} {{ form.password.label(class="form-control-label") }} {% if form.password.errors %} {{ form.password(class="form-control form-control-lg is-invalid") }} {% for errors in form.password.errors %} {{ error }} {% endfor %} {% else %} {{ form.password(class="form-control form-control-lg") }} {% endif %} {{ form.submit(class='btn btn-outline-info') }} {% endblock %} home.html {% if title %} integrate - {{ title }} {% else %} integrate {% endif %} {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} {% for category, message in messages %} {{ message }} {% endfor %} {% endif %} {% endwith %} {% block content %} {% endblock %} MySQL database query steps:1. use present database with command USE 2. create a table to store data (username, password) - CREATE TABLE pythonlogin(username VARCHAR(30), password VARCHAR(50)) 3. insert tuples into table - INSERT INTO pythonlogin values("name1", "password") 4. using WHERE clause to check if user exists - SELECT * FROM pythonlogin WHERE username = "username-data" and password = "passworddata"; Flask looks automatically templates folder for html pages. executing steps: 1. install the requirements( see in the comments) 2. use command - set FLASK_APP = pythonlogin.py for windows 3. use command - export FLASK_APP = pythonlogin.py for linux and mac 4. flask run 5. open the url (localhost:5000) in browser 6. localhost:5000/login or localhost:5000/ for login page 7. localhost:5000/home is for home page 8. it redirects to home page when credentials match SDEV 300 Lab 7 Task 1 Fall 2019 Nevery Berry Task: This week’s task was to enhance the webpage that I created last week with additional functionality to include images, tables, and a form using Python flask:  is ar stu ed d vi y re aC s o ou urc rs e eH w er as o. co m  At least images 1 form allowing a user to enter at submit data for 2 textfields, 1 textarea, and one select (drop down) component. The form should have a submit and reset button The code I used is included in this assignment (NeveryW6.py, NeveryB.html and result.html) 1) When ran in the AWS Cloud9 environment, the initial output looks like this: sh Th 2) When I opened the browser and browsed to the webpage the AWS output looks like this: This study source was downloaded by 100000762283598 from CourseHero.com on 04-29-2021 13:41:31 GMT -05:00 https://www.coursehero.com/file/52455008/Lab-7-Document-Reportdocx/ sh Th is ar stu ed d vi y re aC s o ou urc rs e eH w er as o. co m 3) When I open a browser to http://3.90.233.230:8080/NeveryB the following two page screenshots show what is presented: This study source was downloaded by 100000762283598 from CourseHero.com on 04-29-2021 13:41:31 GMT -05:00 https://www.coursehero.com/file/52455008/Lab-7-Document-Reportdocx/ is ar stu ed d vi y re aC s o ou urc rs e eH w er as o. co m sh Th 4) After I fill out the form on my webpage, I receive the following output This study source was downloaded by 100000762283598 from CourseHero.com on 04-29-2021 13:41:31 GMT -05:00 https://www.coursehero.com/file/52455008/Lab-7-Document-Reportdocx/ Powered by TCPDF (www.tcpdf.org)
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

View attached ex...


Anonymous
Really great stuff, couldn't ask for more.

Studypool
4.7
Indeed
4.5
Sitejabber
4.4

Related Tags