Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
go
Commits
4d1f7df1
Commit
4d1f7df1
authored
Nov 08, 2013
by
Jean Michel Rouly
Browse files
Introduced separate login page.
parent
295a05a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
wsgi/index.py
View file @
4d1f7df1
...
...
@@ -7,53 +7,17 @@ import goconfig
def
application
(
environ
,
start_response
):
## This application should display two the user one of two
## screens, depending on the situation.
##
## Given an unverified user, display the login screen.
## On login, authenticate the user's credentials. If the credentials
## are good, then consider the user logged in.
##
## Given a logged in user, display the URL register screen. On
## submission, transfer control to the url-register script and
## allow it to verify submission content. If the url-register script
## sends the user back here, the user should remain logged in and
## have no issues travelling back and forth.
# Construct the default body, along with its header/footer wrapper.
if
(
not
library
.
user_logged_in
(
environ
)
):
status
=
'303 See other'
response_headers
=
[(
'Location'
,
'/login'
)]
start_response
(
status
,
response_headers
)
return
[
'Redirecting to login . . .'
]
body
=
[]
f
=
open
(
goconfig
.
doc_root
+
"/site_data/top.part"
,
"r"
)
top_part
=
f
.
read
()
f
.
close
()
f
=
open
(
goconfig
.
doc_root
+
"/site_data/bottom.part"
,
"r"
)
bottom_part
=
f
.
read
()
f
.
close
()
login_form
=
"""
<h3>~Login~</h3>
<form action="/exec/lg" method="post">
<label for="usr">username</label>
<br /><br />
<input type="text" id="usr" name="usr" value="" />
<br /><br />
<label for="pass">password</label>
<br /><br />
<input type="password" id="pass" name="pass" value="" />
<br /><br />
<input type="submit" name="submit" value="LOGIN" />
<p>
<br />
You must be <a href="/signup">registered</a> in
order to use this service.
<br /><br />
</p>
</form>
"""
#body.append( login_form )
url_form
=
"""
<h3>~Shorten URL~</h3>
<form action="/
exec/rg
" method="post" target="_self">
<form action="/
register-url
" method="post" target="_self">
<label for="long-url">Long URL</label>
<br /><br />
<input type="text" id="long-url" name="long-url" value="http://" />
...
...
@@ -78,16 +42,19 @@ def application(environ, start_response):
<br /><br />
</form>
"""
#body.append( url_form )
if
(
library
.
user_logged_in
(
environ
)
):
body
.
append
(
url_form
)
else
:
body
.
append
(
login_form
)
body
.
append
(
url_form
)
f
=
open
(
goconfig
.
doc_root
+
"/site_data/top.part"
,
"r"
)
top
=
f
.
read
()
f
.
close
()
f
=
open
(
goconfig
.
doc_root
+
"/site_data/bottom.part"
,
"r"
)
bottom
=
f
.
read
()
f
.
close
()
body
=
''
.
join
(
body
)
response
=
top
_part
+
body
+
bottom
_part
response
=
top
+
body
+
bottom
status
=
'200 OK'
response_headers
=
[(
'Content-type'
,
'text/html'
),
(
'Content-Length'
,
str
(
len
(
response
)))]
...
...
wsgi/login.py
0 → 100644
View file @
4d1f7df1
import
ldap
import
site
site
.
addsitedir
(
'/srv/http/go/wsgi'
)
import
library
import
goconfig
def
application
(
environ
,
start_response
):
if
(
library
.
user_logged_in
(
environ
)
):
status
=
'303 See other'
response_headers
=
[(
'Location'
,
'/'
)]
start_response
(
status
,
response_headers
)
return
[
'Redirecting to index . . .'
]
body
=
[]
login_form
=
"""
<h3>~Login~</h3>
<form action="/authenticate" method="post">
<label for="usr">username</label>
<br /><br />
<input type="text" id="usr" name="usr" value="" />
<br /><br />
<label for="pass">password</label>
<br /><br />
<input type="password" id="pass" name="pass" value="" />
<br /><br />
<input type="submit" name="submit" value="LOGIN" />
<p>
<br />
You must be <a href="/signup">registered</a> in
order to use this service.
<br /><br />
</p>
</form>
"""
body
.
append
(
login_form
)
f
=
open
(
goconfig
.
doc_root
+
"/site_data/top.part"
,
"r"
)
top
=
f
.
read
()
f
.
close
()
f
=
open
(
goconfig
.
doc_root
+
"/site_data/bottom.part"
,
"r"
)
bottom
=
f
.
read
()
f
.
close
()
body
=
''
.
join
(
body
)
response
=
top
+
body
+
bottom
status
=
'200 OK'
response_headers
=
[(
'Content-type'
,
'text/html'
),
(
'Content-Length'
,
str
(
len
(
response
)))]
start_response
(
status
,
response_headers
)
return
[
response
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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