Commit 267fde3a authored by Ishan Patel's avatar Ishan Patel Committed by Mitchell Moore
Browse files

Created temp dir for fb to store user data info. Fixed timestamp format

- Created temp_path for db
- Code cleanup- fixed whitespaces
- Fixed time_stamp format
- Added-mkdir-function
parent c9fec8d8
...@@ -7,14 +7,11 @@ import os ...@@ -7,14 +7,11 @@ import os
import os.path import os.path
import sys import sys
import time import time
import datetime import datetime
import subprocess import subprocess
# third-party imports # third-party imports
from flask import Flask, redirect, url_for, request, render_template, flash from flask import Flask, redirect, url_for, request, render_template, flash
from flask_wtf import FlaskForm
from flask_bootstrap import Bootstrap from flask_bootstrap import Bootstrap
from wtforms import StringField, SubmitField, validators
def create_app(config_name): def create_app(config_name):
...@@ -25,27 +22,20 @@ def create_app(config_name): ...@@ -25,27 +22,20 @@ def create_app(config_name):
global return_url global return_url
return_url = '' return_url = ''
class MainForm(FlaskForm):
fullname = StringField('Full Name: ', [validators.DataRequired(), ])
submit = SubmitField('Submit')
@app.route('/', methods=['GET', 'POST']) @app.route('/', methods=['GET', 'POST'])
def index(): def index():
global return_url
user = request.remote_user user = request.remote_user
if "redir" in request.args and return_url == "": if "redir" in request.args and return_url == "":
return_url = request.args.get("redir") or "/pun/sys/dashboard" return_url = request.args.get("redir") or "/pun/sys/dashboard"
username = False if name != "":
form = MainForm()
if form.is_submitted():
username = form.fullname.data
form.fullname.data = ''
return redirect(url_for('success', username=str(user), fullname=username)) return redirect(url_for('success', username=str(user), fullname=name))
return render_template('auth/SignUp.html', form=form, user=user) else:
return render_template("auth/SignUp.html", user=user)
@app.route('/success/<username>/<fullname>') @app.route('/success/<username>/<fullname>')
def success(username, fullname): def success(username, fullname):
...@@ -58,17 +48,23 @@ def create_app(config_name): ...@@ -58,17 +48,23 @@ def create_app(config_name):
print(tempString, file=sys.stdout) print(tempString, file=sys.stdout)
try: try:
time_stamp = time.strftime("%Y%m%d-%H%M%S") # function to write out a flatdb with the name of the file being a timestamp and the content
blazer_path = "/var/www/ood/register/flask_user_reg" # of the file beieng blazerID the user submitted from the flask form (fullname)
complete_file_name = os.path.join(blazer_path, time_stamp+".txt") time_stamp = time.strftime("%m-%d-%Y_%H:%M:%S")
directory = "/var/www/ood/register/flask_user_reg/app/flat_db"
complete_file_name = os.path.join(directory, time_stamp + ".txt")
if not os.path.exists(directory):
os.makedirs(directory)
file = open(complete_file_name, "w") file = open(complete_file_name, "w")
file.write(fullname) file.write(fullname)
file.close() file.close()
return redirect(return_url, 302) return redirect(return_url, 302)
except: except:
flash("Registration Failed. Please try again.") flash("Registration Failed")
return redirect(url_for('index')) return redirect(return_url)
@app.errorhandler(403) @app.errorhandler(403)
def forbidden(error): def forbidden(error):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment