Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
rc
self-reg-form
Commits
cf71a084
Commit
cf71a084
authored
Oct 02, 2020
by
Krish Moodbidri
Browse files
pre-populate user information in the form
parent
304c663b
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/__init__.py
View file @
cf71a084
...
...
@@ -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
)
...
...
app/static/scripts/function.js
View file @
cf71a084
...
...
@@ -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
"
;
}
}
app/templates/auth/SignUp.html
View file @
cf71a084
...
...
@@ -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>
<input
class=
"btn btn-primary btn-block"
id=
"submit"
name=
"submit"
type=
"button"
value=
"Submit"
onclick=
"request_account()"
>
<div>
<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>
	
<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>
	
<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>
	
<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>
...
...
vars.py
View file @
cf71a084
...
...
@@ -3,4 +3,7 @@ password = ''
key
=
''
broker_url
=
'amqp://'
+
id
+
':'
+
password
+
'@ohpc:5672/'
message_queue
=
broker_url
+
'socketio'
default_referrer
=
"/pun/sys/dashboard"
default_referrer
=
"/pun/sys/dashboard"
username_keys
=
[
"Remote-User"
]
fullname_keys
=
[
"HTTP_DISPLAYNAME"
]
email_keys
=
[
"HTTP_MAIL"
]
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment