diff --git a/app/__init__.py b/app/__init__.py index e8e7526a326e732efa83b19dd6e22ebc597dce68..8093b849cd4ace66363e0e389335e6320ddc9d44 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -7,14 +7,11 @@ import os import os.path import sys import time - import datetime import subprocess # third-party imports from flask import Flask, redirect, url_for, request, render_template, flash -from flask_wtf import FlaskForm from flask_bootstrap import Bootstrap -from wtforms import StringField, SubmitField, validators def create_app(config_name): @@ -25,27 +22,20 @@ def create_app(config_name): global return_url return_url = '' - class MainForm(FlaskForm): - fullname = StringField('Full Name: ', [validators.DataRequired(), ]) - submit = SubmitField('Submit') - @app.route('/', methods=['GET', 'POST']) def index(): - global return_url + user = request.remote_user if "redir" in request.args and return_url == "": return_url = request.args.get("redir") or "/pun/sys/dashboard" - username = False - form = MainForm() - if form.is_submitted(): - username = form.fullname.data - form.fullname.data = '' + if name != "": - 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>') def success(username, fullname): @@ -58,17 +48,23 @@ def create_app(config_name): print(tempString, file=sys.stdout) try: - time_stamp = time.strftime("%Y%m%d-%H%M%S") - blazer_path = "/var/www/ood/register/flask_user_reg" - complete_file_name = os.path.join(blazer_path, time_stamp+".txt") + # function to write out a flatdb with the name of the file being a timestamp and the content + # of the file beieng blazerID the user submitted from the flask form (fullname) + 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.write(fullname) file.close() return redirect(return_url, 302) except: - flash("Registration Failed. Please try again.") - return redirect(url_for('index')) + flash("Registration Failed") + return redirect(return_url) @app.errorhandler(403) def forbidden(error):