Skip to content

Commit

Permalink
Merge pull request #137 from Nishchal-007/dev
Browse files Browse the repository at this point in the history
Auth and UI changes
  • Loading branch information
pradeeban authored Jun 17, 2021
2 parents ff3fce3 + bd6103c commit 5c95c98
Show file tree
Hide file tree
Showing 13 changed files with 1,464 additions and 392 deletions.
12 changes: 12 additions & 0 deletions modules/frontend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from flask import Flask
import os
from flask_sqlalchemy import SQLAlchemy
import warnings
warnings.filterwarnings("ignore")

PEOPLE_FOLDER = os.path.join('static','styles')
app = Flask(__name__)

app.config['SECRET_KEY'] = 'secret-key-goes-here'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
db = SQLAlchemy(app)
Binary file added modules/frontend/db.sqlite
Binary file not shown.
13 changes: 13 additions & 0 deletions modules/frontend/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __init__ import db
from flask import Flask
import os
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
import warnings
warnings.filterwarnings("ignore")

class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
email = db.Column(db.String(100), unique=True)
password = db.Column(db.String(100))
name = db.Column(db.String(1000))
6 changes: 6 additions & 0 deletions modules/frontend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
click==8.0.1
colorama==0.4.4
Flask==2.0.1
Flask-Login==0.5.0
Flask-SQLAlchemy==2.5.1
greenlet==1.1.0
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
numpy==1.20.3
pandas==1.2.4
Pillow==8.2.0
pydicom==2.1.2
pypng==0.0.20
python-dateutil==2.8.1
pytz==2021.1
schedule==1.1.0
six==1.16.0
SQLAlchemy==1.4.18
sqlparse==0.4.1
Werkzeug==2.0.1
92 changes: 87 additions & 5 deletions modules/frontend/server.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,88 @@
from flask import Flask, flash, request, redirect, url_for, render_template, send_file
import os
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
from flask_login import LoginManager, login_user, login_required, current_user, logout_user
import warnings
warnings.filterwarnings("ignore")

from werkzeug.security import generate_password_hash, check_password_hash
from __init__ import app, db
from models import User

PEOPLE_FOLDER = os.path.join('static','styles')
app = Flask(__name__)
# app = Flask(__name__)

login_manager = LoginManager(app)
login_manager.login_view = 'login'

@login_manager.user_loader
def load_user(user_id):
# since the user_id is just the primary key of our user table, use it in the query for the user
return User.query.get(int(user_id))

@app.route("/", methods=['GET'])
def index():
return render_template('home.html')

@app.route("/png-extraction", methods = ['GET'])
def PNG_Extraction():
return render_template('pngHome.html')
@app.route('/login', methods=['GET','POST'])
def login():
if request.method == 'POST':
email = request.form.get('email')
password = request.form.get('password')
remember = True if request.form.get('remember') else False

user = User.query.filter_by(email=email).first()

# check if the user actually exists
# take the user-supplied password, hash it, and compare it to the hashed password in the database
if not user or not check_password_hash(user.password, password):
flash('Please check your login details and try again.')
return render_template('login.html') # if the user doesn't exist or password is wrong, reload the page

# if the above check passes, then we know the user has the right credentials
login_user(user, remember=remember)
return render_template('home.html')
return render_template('login.html')

@app.route('/signup', methods=['GET','POST'])
def signup():
if request.method =='POST':
email = request.form.get('email')
name = request.form.get('name')
password = request.form.get('password')

user = User.query.filter_by(email=email).first() # if this returns a user, then the email already exists in database

if user: # if a user is found, we want to redirect back to signup page so user can try again
flash('Email address already exists')
return render_template('signup.html')

# create a new user with the form data. Hash the password so the plaintext version isn't saved.
new_user = User(email=email, name=name, password=generate_password_hash(password, method='sha256'))

# add the new user to the database
db.session.add(new_user)
db.session.commit()
return render_template('login.html')

return render_template('signup.html')

@app.route('/logout')
@login_required
def logout():
logout_user()
return render_template('home.html')

# @app.route("/png-extraction", methods = ['GET'])
# @login_required
# def PNG_Extraction():
# return render_template('pngHome.html')

config_values = {}

@app.route('/', methods=['POST'])
@app.route('/png-extraction', methods=['GET', 'POST'])
@login_required
def extract_png():
if request.method =='POST':
config_values["dcmFolder"] = request.form['DICOMFolder']
Expand All @@ -37,6 +105,20 @@ def extract_png():
return render_template('pngHome.html', logs = lt)
return render_template('pngHome.html')

@app.route('/cold-extraction', methods=['GET', 'POST'])
@login_required
def cold_extraction():
if request.method =='POST':
csv_file = request.files['csvFile']
if (csv_file):
import sys
import io

stream = io.StringIO(csv_file.stream.read().decode("UTF8"), newline=None)
sys.path.append("../cold-extraction/")
import ColdDataRetriever
x = ColdDataRetriever.read_csv(stream)
return render_template('cold_extraction.html')
#JUST DO IT!!!
if __name__=="__main__":
app.run(port="9000")
150 changes: 149 additions & 1 deletion modules/frontend/static/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ html {
height: 100%;
}

::-webkit-scrollbar {
width: 0; /* Remove scrollbar space */
background: transparent; /* Optional: just make scrollbar invisible */
}

.nav-item {
margin: 8px;
padding: 12px;
Expand Down Expand Up @@ -93,12 +98,13 @@ html {
/* PNG Extraction Styles */

.backdrop {
/* position: absolute; */
background-image: url("../images/img1.png");
height: 100%;
width: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: absolute;
}

.row {
Expand All @@ -109,3 +115,145 @@ html {
color: white;
font-size: 18px;
}

/* Login Styles */

.login_background {
background-color: #1a2226;
height: 100%;
width: 100%;
position: absolute;
}

.login-box {
margin-top: 75px;
height: auto;
background: #1a2226;
text-align: center;
padding: 25px;
border-radius: 15px;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.8), 10px 13px 15px rgba(0, 0, 0, 0.6);
}

.login-title {
margin-top: 15px;
text-align: center;
font-size: 30px;
letter-spacing: 2px;
margin-top: 15px;
font-weight: bold;
color: #ecf0f5;
}

.login-form {
margin-top: 25px;
text-align: left;
}

.login_background input[type="email"] {
background-color: #1a2226;
border: none;
border-bottom: 2px solid #0db8de;
border-top: 0px;
border-radius: 0px;
font-weight: bold;
outline: 0;
margin-bottom: 20px;
padding-left: 0px;
color: #ecf0f5;
}

.login_background input[type="text"] {
background-color: #1a2226;
border: none;
border-bottom: 2px solid #0db8de;
border-top: 0px;
border-radius: 0px;
font-weight: bold;
outline: 0;
margin-bottom: 20px;
padding-left: 0px;
color: #ecf0f5;
}

.login_background input[type="password"] {
background-color: #1a2226;
border: none;
border-bottom: 2px solid #0db8de;
border-top: 0px;
border-radius: 0px;
font-weight: bold;
outline: 0;
padding-left: 0px;
margin-bottom: 20px;
color: #ecf0f5;
}

.form-group {
margin-bottom: 40px;
outline: 0px;
}

.form-control:focus {
border-color: inherit;
-webkit-box-shadow: none;
box-shadow: none;
border-bottom: 2px solid #0db8de;
outline: 0;
background-color: #1a2226;
color: #ecf0f5;
}

.login_background input:focus {
outline: none;
box-shadow: 0 0 0;
}

.login_background label {
margin-bottom: 0px;
}

.form-control-label {
font-size: 10px;
color: #6c6c6c;
font-weight: bold;
letter-spacing: 1px;
}

.login_background .btn-outline-primary {
border-color: #0db8de;
color: #0db8de;
border-radius: 0px;
font-weight: bold;
letter-spacing: 1px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}

.login_background .btn-outline-primary:hover {
background-color: #0db8de;
right: 0px;
}

.login-btm {
float: left;
}

.login-button {
padding-right: 0px;
text-align: center;
margin-bottom: 25px;
}

.login-text {
background-color: red;
margin: 12px;
border-radius: 12px;
padding: 10px;
color: white;
text-align: center;
font-size: 22px;
}

.loginbttm {
padding: 25px;
}
Loading

0 comments on commit 5c95c98

Please sign in to comment.