Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

ldap auth #46

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. nodoctest

.. This README does not explain how to handle installation into versions
of Sage which do not yet ship the flask notebook, as the packaging of
the notebook's dependencies is still in flux. Please see
Expand Down
4 changes: 2 additions & 2 deletions flask_version/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def lookup_current_user():
def login(template_dict={}):
from sagenb.misc.misc import SAGE_VERSION
template_dict.update({'accounts': g.notebook.user_manager().get_accounts(),
'default_user': g.notebook.user_manager().default_user(),
'recovery': g.notebook.conf()['email'],
'next': request.values.get('next', ''),
'sage_version': SAGE_VERSION,
Expand Down Expand Up @@ -94,6 +93,8 @@ def logout():
@authentication.route('/register', methods = ['GET','POST'])
@with_lock
def register():
if not g.notebook.user_manager().get_accounts():
return redirect(url_for('base.index'))
from sagenb.notebook.misc import is_valid_username, is_valid_password, \
is_valid_email, do_passwords_match
from sagenb.notebook.challenge import challenge
Expand Down Expand Up @@ -243,7 +244,6 @@ def register():
# Go to the login page.
from sagenb.misc.misc import SAGE_VERSION
template_dict = {'accounts': g.notebook.user_manager().get_accounts(),
'default_user': g.notebook.user_manager().default_user(),
'welcome_user': username,
'recovery': g.notebook.conf()['email'],
'sage_version': SAGE_VERSION}
Expand Down
40 changes: 20 additions & 20 deletions flask_version/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ def __init__(self, *args, **kwds):

self.root_path = SAGENB_ROOT

self.add_static_path('/css', os.path.join(DATA, "sage", "css"))
self.add_static_path('/css', os.path.join(DATA, "sage", "css"))
self.add_static_path('/images', os.path.join(DATA, "sage", "images"))
self.add_static_path('/javascript', DATA)
self.add_static_path('/static', DATA)
self.add_static_path('/java', DATA)
self.add_static_path('/java/jmol', os.path.join(os.environ["SAGE_ROOT"],"local","share","jmol"))
import mimetypes
import mimetypes
mimetypes.add_type('text/plain','.jmol')


#######
# Doc #
#######
#These "should" be in doc.py
DOC = os.path.join(SAGE_DOC, 'output', 'html', 'en')
self.add_static_path('/pdf', os.path.join(SAGE_DOC, 'output', 'pdf'))
self.add_static_path('/doc/static', DOC)
self.add_static_path('/doc/static', DOC)
#self.add_static_path('/doc/static/reference', os.path.join(SAGE_DOC, 'reference'))

def create_jinja_environment(self):
Expand Down Expand Up @@ -108,14 +108,14 @@ def index():
response.set_cookie('nb_session_%s'%g.notebook.port)
response.set_cookie('cookie_test_%s'%g.notebook.port, expires=1)
return response

from authentication import login

if current_app.startup_token is not None and 'startup_token' in request.args:
if request.args['startup_token'] == current_app.startup_token:
g.username = session['username'] = 'admin'
g.username = session['username'] = 'admin'
session.modified = True
current_app.startup_token = -1
current_app.startup_token = None
return index()

return login()
Expand Down Expand Up @@ -192,7 +192,7 @@ def keyboard_js(browser_os):
###############
@base.route('/css/main.css')
def main_css():
from sagenb.notebook.css import css
from sagenb.notebook.css import css
data,datahash = css()
if request.environ.get('HTTP_IF_NONE_MATCH', None) == datahash:
response = make_response('',304)
Expand Down Expand Up @@ -260,7 +260,7 @@ def create_or_login(resp):
session['username'] = g.username = username
session.modified = True
except KeyError:
session['openid_response'] = resp
session['openid_response'] = resp
session.modified = True
return redirect(url_for('set_profiles'))
return redirect(request.values.get('next', url_for('base.index')))
Expand All @@ -272,7 +272,7 @@ def set_profiles():

from sagenb.notebook.challenge import challenge


show_challenge=g.notebook.conf()['challenge']
if show_challenge:
chal = challenge(g.notebook.conf(),
Expand Down Expand Up @@ -326,14 +326,14 @@ def set_profiles():

if not is_valid_username(username):
parse_dict['username_invalid'] = True
raise ValueError
raise ValueError
if g.notebook.user_manager().user_exists(username):
parse_dict['username_taken'] = True
raise ValueError
raise ValueError
if not is_valid_email(request.form.get('email')):
parse_dict['email_invalid'] = True
raise ValueError
try:
try:
new_user = User(username, '', email = resp.email, account_type='user')
g.notebook.user_manager().add_user_object(new_user)
except ValueError:
Expand All @@ -357,7 +357,7 @@ def set_profiles():
def init_updates():
global save_interval, idle_interval, last_save_time, last_idle_time
from sagenb.misc.misc import walltime

save_interval = notebook.conf()['save_interval']
idle_interval = notebook.conf()['idle_check_interval']
last_save_time = walltime()
Expand Down Expand Up @@ -410,7 +410,7 @@ def create_app(path_to_notebook, *args, **kwds):
"""
global notebook
startup_token = kwds.pop('startup_token', None)

#############
# OLD STUFF #
#############
Expand All @@ -436,15 +436,15 @@ def set_notebook_object():
####################################
babel = Babel(app, default_locale=notebook.conf()['default_language'],
default_timezone='UTC',
date_formats=None, configure_jinja=True)
date_formats=None, configure_jinja=True)

########################
# Register the modules #
########################
app.register_blueprint(base)

from worksheet_listing import worksheet_listing
app.register_blueprint(worksheet_listing)
app.register_blueprint(worksheet_listing)

from admin import admin
app.register_blueprint(admin)
Expand Down Expand Up @@ -473,10 +473,10 @@ def autoindex(path='.'):
if os.path.isfile(filename):
from cgi import escape
src = escape(open(filename).read().decode('utf-8','ignore'))
if (os.path.splitext(filename)[1] in
if (os.path.splitext(filename)[1] in
['.py','.c','.cc','.h','.hh','.pyx','.pxd']):
return render_template(os.path.join('html', 'source_code.html'),
src_filename=path,
src_filename=path,
src=src, username = g.username)
return src
return idx.render_autoindex(path)
Expand Down
15 changes: 5 additions & 10 deletions flask_version/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@ def login_required(f):
@wraps(f)
def wrapper(*args, **kwds):
if 'username' not in session:
if not g.notebook.conf()['require_login']:
g.username = session['username'] = 'admin'
session.modified = True
#XXX: Do we have to specify this for the publised
#worksheets here?
if request.path.startswith('/home/_sage_/'):
g.username = 'guest'
return f(*args, **kwds)
else:
#XXX: Do we have to specify this for the publised
#worksheets here?
if request.path.startswith('/home/_sage_/'):
g.username = 'guest'
return f(*args, **kwds)
else:
return redirect(url_for('base.index', next=request.url))
return redirect(url_for('base.index', next=request.url))
else:
g.username = session['username']
return f(*args, **kwds)
Expand Down
1 change: 1 addition & 0 deletions flask_version/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def settings_page():
td['email_confirmed'] = 'Not confirmed'

td['admin'] = nu.is_admin()
td['form_email'] = nu.may_change_email()

return render_template(os.path.join('html', 'settings', 'account_settings.html'), **td)

22 changes: 1 addition & 21 deletions flask_version/worksheet_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,11 @@ def render_worksheet_list(args, pub, username):

from sagenb.notebook.notebook import sort_worksheet_list
from sagenb.misc.misc import unicode_str, SAGE_VERSION
from sagenb.notebook.pagination import Paginator


typ = args['typ'] if 'typ' in args else 'active'
search = unicode_str(args['search']) if 'search' in args else None
sort = args['sort'] if 'sort' in args else 'last_edited'
reverse = (args['reverse'] == 'True') if 'reverse' in args else False
page = 1
if 'page' in args:
try:
page = int(args['page'])
except ValueError as E:
print "Error improper page input", E

try:
if not pub:
Expand All @@ -56,19 +49,6 @@ def render_worksheet_list(args, pub, username):
print "Error displaying worksheet listing: ", E
return current_app.message(_("Error displaying worksheet listing."))

paginator = Paginator(worksheets, 25) #25 is number of items per page, change this value to change the number of objects per page.

try:
pages = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
pages = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
pages = paginator.page(paginator.num_pages)

worksheets = pages.object_list

worksheet_filenames = [x.filename() for x in worksheets]

if pub and (not username or username == tuple([])):
Expand Down
2 changes: 1 addition & 1 deletion sagenb/data/sage/html/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h2>Sign into the Sage Notebook v{{ sage_version }}</h2>
<form method="POST" action="/login" id="sign-in-form">
<div>
<label for="email">{{ gettext('Username') }}</label>
<input type="text" name="email" value="{{ default_user }}" size="15" />
<input type="text" name="email" size="15" />
{% if username_error %}
<span style="color:red">{{ gettext('Error') }}: </span>{{ gettext('Username is not in the system') }}
{% endif %}
Expand Down
43 changes: 43 additions & 0 deletions sagenb/data/sage/html/notebook/worksheet_share.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
{% set select = "share" %}

{% block after_sharebar %}
<script type="text/javascript">
function add_collab(u) {
var col = document.getElementById('collaborators');
if (col.value != "") {
col.value+= ", ";
}
col.value+=u;
}
</script>

{% if not (notebook.user_manager().user_is_admin(username) or username == worksheet.owner()) %}
{{ gettext('Only the owner of a worksheet is allowed to share it. You can do whatever you want if you <a href="copy">make your own copy</a>.') }}
{% else %}
Expand All @@ -23,5 +33,38 @@
<textarea name="collaborators" rows=5 cols=70 class="edit" id="collaborators" style="display:block; margin-bottom:1em;">{{ worksheet.collaborators()|join(', ') }}</textarea>
<input type="submit" title="{{ gettext('Give access to your worksheet to the above collaborators') }}" value="{{ gettext('Invite Collaborators') }}" />
</form>

<hr class="usercontrol" />
{% if lookup %}
<div>
<p>{{ gettext('Search results:') }} {% if lookup_result %}
{% for u in lookup_result %}
<span class="users">
<a href="javascript:add_collab('{{ u }}');" class="users">{{ u }}</a>
</span>
{% endfor %}
{% else %} {{ gettext('sorry, no match found') }}
{% endif %}</p>
</div>
{% else %}
{{ gettext('Search Users') }}
{% endif %}
<form width=70% method="post" action="search_collab" style="margin-bottom:1em">
<input type="text" class="edit" id="lookup" name="lookup" value="{{ lookup if lookup else '' }}" />
<input type="submit" value="Search" />
</form>

{% if other_users %}
<hr class="usercontrol" />
<p>
<span class="username">{{ gettext('Known Sage Users:') }}</span>
{% for u in other_users %}
<span class="users">
<a href="javascript:add_collab('{{ u }}');" class="users">{{ u }}</a>
</span>
{% endfor %}
</p>
{% endif %}

{% endif %}
{% endblock %}
12 changes: 10 additions & 2 deletions sagenb/data/sage/html/settings/account_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ <h2>{{ gettext('Change Auto-Save Interval') }}</h2>
</select>
</div>
</div>
{% if form_password %}
<div class="section">
<h2>{{ gettext('Change Password') }}</h2>
<div id="passwd">
Expand All @@ -40,11 +41,12 @@ <h2>{{ gettext('Change Password') }}</h2>
</div>
</div>
</div>
{% endif %}

{% if true %}
{% if form_email %}
<div class="section">
<h2>{{ gettext('Change E-mail Address') }}</h2>

<div>
<div>
<label>{{ gettext('Current e-mail') }}</label>
Expand All @@ -56,6 +58,12 @@ <h2>{{ gettext('Change E-mail Address') }}</h2>
</div>
</div>
</div>
{% else %}
<div class="section">
<div>
{{ gettext('Your Email') }}: {{ email_address }}
</div>
</div>
{% endif %}

{%- if auto_table %}
Expand Down
Loading