Commit 4d1f7df1 authored by Jean Michel Rouly's avatar Jean Michel Rouly
Browse files

Introduced separate login page.

parent 295a05a2
......@@ -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)))]
......
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]
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