Newer
Older
# app/__init__.py
Mitchell Moore
committed
# local imports
from __future__ import print_function
import os
import sys
# third-party imports
from flask import Flask, redirect, url_for, request
from flask import render_template
Mitchell Moore
committed
from flask_bootstrap import Bootstrap
def create_app(config_name):
app = Flask(__name__)
Mitchell Moore
committed
Bootstrap(app)
global return_url
return_url = ''
Mitchell Moore
committed
@app.route('/success/<name>/<username>')
def success(username, name):
global return_url
print(username, name, return_url, file=sys.stdout)
# Deliver arguments to script.
tempString = 'sudo user_create ' + username + " " + name
os.system("ssh ohpc " + tempString)
return redirect(return_url, 302)
@app.route('/', methods=['GET'])
def index():
Mitchell Moore
committed
global return_url
return_url = request.args.get("redir")
user = request.remote_user
return render_template("auth/SignUp.html", user=user, url=return_url)
@app.route('/', methods=['GET', 'POST'])
def SignUp():
Mitchell Moore
committed
name = request.form['name']
user = request.remote_user
if request.method == 'GET':
return render_template("auth/SignUp.html", user=user)
if request.method == 'POST' and name != "":
return redirect(url_for('success', username=str(user), name=name))
else:
return render_template("auth/SignUp.html", user=user)
@app.errorhandler(403)
def forbidden(error):
return render_template('errors/403.html', title='Forbidden'), 403
@app.errorhandler(404)
def page_not_found(error):
return render_template('errors/404.html', title='Page Not Found'), 404
@app.errorhandler(500)
def internal_server_error(error):
return render_template('errors/500.html', title='Server Error'), 500
return app