Commit cf71a084 authored by Krish Moodbidri's avatar Krish Moodbidri
Browse files

pre-populate user information in the form

parent 304c663b
......@@ -9,26 +9,48 @@ import uuid
from flask import Flask, redirect, url_for, request, render_template, flash, session
from flask_bootstrap import Bootstrap
import random
import os
import json
def create_app(config_name):
app = Flask(__name__) # initialization of the flask app
Bootstrap(app) # allowing app to use bootstrap
def get_authorized_user():
username_keys = list(filter(lambda key: (request.headers.get(key) is not None), vars.username_keys))
fullname_keys = list(filter(lambda key: (request.headers.get(key) is not None), vars.fullname_keys))
email_keys = list(filter(lambda key: (request.headers.get(key) is not None), vars.email_keys))
user = {
"username": (request.headers.get(username_keys[0]) if len(username_keys) > 0 else None),
"fullname": (request.headers.get(fullname_keys[0]) if len(fullname_keys) > 0 else None),
"email": (request.headers.get(email_keys[0]) if len(email_keys) > 0 else None),
}
return user
@app.route('/', methods=['GET', 'POST']) # initial route to display the reg page
def index():
if 'uid' not in session:
session['uid']=str(uuid.uuid4())
if 'user' not in session:
session["user"] = get_authorized_user()
if "redir" in request.args and 'return_url' not in session: # check for redir arg in url
session['return_url'] = request.args.get("redir")
elif "redir" not in request.args and 'return_url' not in session:
session['return_url'] = vars.default_referrer
else:
session['return_url'] = request.referrer
return render_template('auth/SignUp.html', room_id=session['uid'], referrer=session['return_url'])
return render_template('auth/SignUp.html', room_id=session['uid'],
username=session['user'].get('username'),
fullname=session['user'].get('fullname'), email=session['user'].get('email'),
referrer=session['return_url'], cancel_url=vars.default_referrer)
# misc page error catching
@app.errorhandler(403)
......
......@@ -14,3 +14,24 @@ function request_account() {
function refresh() {
document.location.reload(true);
}
function autofill_form(username, fullname, email) {
let username_input = document.getElementById("username");
let fullname_input = document.getElementById("fullname");
let email_input = document.getElementById("email");
if ((username.localeCompare("None")) !== 0) {
username_input.value = username;
username_input.disabled = "true";
}
if ((fullname.localeCompare("None")) !== 0) {
fullname_input.value = fullname;
fullname_input.disabled = "true";
}
if ((email.localeCompare("None")) !== 0) {
email_input.value = email;
email_input.disabled = "true";
}
}
......@@ -86,24 +86,32 @@
<!-- <h2>Hello, <span id="username">{{ user }}</span>!</h2> -->
<h2>Hi, </h2>
<div id="test">
<form action="." method="post" onsubmit="">
<div class="signUpContainer">
<label><b><label for="username">Blazer Id: </label><br></b></label>
<input class="form-control" id="bid" name="bid" placeholder="Enter BlazerId" required="" type="text">
<label><b><label for="email">Email Id: </label><br></b></label>
<input class="form-control" id="email" name="email" placeholder="Enter Email Id" required="" type="text" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" >
<label><b><label for="fullname">Full Name: </label><br></b></label>
<input class="form-control" id="fullname" name="fullname" placeholder="Enter Full Name" required="" type="text">
<label><b><label for="reason">Reason for Requesting Account: </label><br></b></label>
<textarea class="form-control" id="reason" name="reason" placeholder="Enter Reason for Account Request" required=""></textarea>
<div id="user-input">
<form id="signup" data-toggle="validator" role="form" action="." method="post" onsubmit="">
<div class="form-group">
<label for="username" class="control-label">Blazer Id:</label>&#9;<input id="username" class="form-control"
placeholder="Enter Username" required><br>
</div>
<div class="form-group">
<label for="fullname" class="control-label">Full Name:</label>&#9;<input id="fullname" class="form-control"
placeholder="Enter Full Name" required><br>
</div>
<div class="form-group">
<label for="email" class="control-label">Email:</label>&#9;<input id="email" class="form-control"
placeholder="Enter Email" required><br>
</div>
<div class="form-group">
<label for="reason" class="control-label">Reason for Requesting Account:</label><br>
<textarea class="form-control" id="reason" name="reason" placeholder="Enter Reason for Account Request" required></textarea>
</div>
<input class="btn btn-primary btn-block" id="submit" name="submit" type="button" value="Submit" onclick="request_account()">
<div>
<strong id="error" style="color: #be051b; text-align: center;"></strong>
</div>
</div>
</form>
</div>
</div>
......
......@@ -4,3 +4,6 @@ key = ''
broker_url = 'amqp://' + id + ':' + password + '@ohpc:5672/'
message_queue = broker_url + 'socketio'
default_referrer = "/pun/sys/dashboard"
username_keys = ["Remote-User"]
fullname_keys = ["HTTP_DISPLAYNAME"]
email_keys = ["HTTP_MAIL"]
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