__init__.py 1.8 KB
Newer Older
1
2
# app/__init__.py

3
4
5
6
7
8
# local imports
from __future__ import print_function

import os
import sys

9
10
11
# third-party imports
from flask import Flask, redirect, url_for, request
from flask import render_template
12
from flask_bootstrap import Bootstrap
13
14
15
16
17


def create_app(config_name):

    app = Flask(__name__)
18
19
20
    Bootstrap(app)
    global return_url
    return_url = ''
21

22
23
24
25
26
27
28
29
30
31
    @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)
32
33
34
35

    @app.route('/', methods=['GET'])
    def index():

36
37
38
39
40
41
42
43
        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'])
44
    def SignUp():
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

        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)
60
61
62
63
64
65
66
67
68
69
70
71
72
73

    @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