CSE3035 LAB DA2: Submitted By: Abhishek Kandel (19BCE2629)
CSE3035 LAB DA2: Submitted By: Abhishek Kandel (19BCE2629)
Configure a Nested Virtual Machine (Container under another VM) in Local Machine
1. Building an Image
Docker login:
Dockerfile:
App.py
2. Running an app in the image (with container IP address)
App.py
from flask import Flask, render_template, request, redirect, url_for,
session
from flask_mysqldb import MySQL
import MySQLdb.cursors
import re
app = Flask(__name__)
app.secret_key = '1234321'
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = 'welcome123'
app.config['MYSQL_DB'] = 'pythonlogin'
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:
session['loggedin'] = True
session['id'] = account['id']
session['username'] = account['username']
msg = 'Logged in successfully !'
return render_template('index.html', msg = msg)
else:
msg = 'Incorrect username / password !'
return render_template('login.html', msg = msg)
@app.route('/logout')
def logout():
session.pop('loggedin', None)
session.pop('id', None)
session.pop('username', None)
return redirect(url_for('login'))
Index.html
<html>
<head>
<meta charset="UTF-8">
</head>
<body></br></br></br></br></br>
<div align="center">
<div class="header">
<h1 class="word">Index</h1>
</div></br></br></br>
<h1 class="bottom">
</h1></br></br></br>
<a href="{{ url_for('logout') }}" class="btn">Logout</a>
</div>
</div>
</body>
</html>
Login.html
<html>
<head>
<meta charset="UTF-8">
<title> Login </title>
<link rel="stylesheet" href="{{ url_for('static',
filename='style.css') }}">
</head>
<body></br></br></br></br></br>
<div align="center">
<div align="center" class="border">
<div class="header">
<h1 class="word">Login</h1>
</div></br></br></br>
<h2 class="word">
<form action="{{ url_for('login') }}" method="post">
<div class="ABHISHEK 19BCE2629">{{ msg }}</div>
<input id="username" name="username" type="text"
placeholder="Enter Your Username" class="textbox"/></br></br>
<input id="password" name="password" type="password"
placeholder="Enter Your Password" class="textbox"/></br></br></br>
<input type="submit" class="btn" value="Sign
In"></br></br>
</form>
</h2>
<p class="bottom">Dont't have an account? <a class="bottom"
href="{{url_for('register')}}"> Sign Up here</a></p>
</div>
</div>
</body>
</html>
Register.html
<html>
<head>
<meta charset="UTF-8">
<title> Register </title>
<link rel="stylesheet" href="{{ url_for('static',
filename='style.css') }}">
</head>
<body></br></br></br></br></br>
<div align="center">
<div align="center" class="border">
<div class="header">
<h1 class="word">Register</h1>
</div></br></br></br>
<h2 class="word">
<form action="{{ url_for('register') }}" method="post">
<div class="ABHISHEK 19BCE2629">{{ msg }}</div>
<input id="username" name="username" type="text"
placeholder="Enter Your Username" class="textbox"/></br></br>
<input id="password" name="password" type="password"
placeholder="Enter Your Password" class="textbox"/></br></br>
<input id="email" name="email" type="text"
placeholder="Enter Your Email ID" class="textbox"/></br></br>
<input type="submit" class="btn" value="Sign Up"></br>
</form>
</h2>
<p class="bottom">Already have an account? <a class="bottom"
href="{{url_for('login')}}"> Sign In here</a></p>
</div>
</div>
</body>
</html>
https://drive.google.com/drive/folders/1ROtQJqG3UYf-Yl2qJunlGsgan7f0npK8?usp=sharing
THANK YOU!!!