mirror of
https://github.com/moepman/bk-dss
synced 2024-12-22 18:24:27 +01:00
Refactor function names according to PEP8.
This commit is contained in:
parent
8d7b72bf07
commit
c1cd8bded1
50
dss.py
50
dss.py
@ -53,23 +53,23 @@ class LoginForm(FlaskForm):
|
|||||||
submit = SubmitField('Login')
|
submit = SubmitField('Login')
|
||||||
|
|
||||||
|
|
||||||
def makeSecret(password):
|
def make_secret(password):
|
||||||
return ldap_salted_sha1.encrypt(password)
|
return ldap_salted_sha1.encrypt(password)
|
||||||
|
|
||||||
|
|
||||||
def isAdmin():
|
def is_admin():
|
||||||
return isLoggedin() and rdb.hget(session['uuid'], 'user') in app.config.get('ADMINS', [])
|
return is_loggedin() and rdb.hget(session['uuid'], 'user') in app.config.get('ADMINS', [])
|
||||||
|
|
||||||
|
|
||||||
def isLoggedin():
|
def is_loggedin():
|
||||||
return 'uuid' in session and rdb.exists(session['uuid'])
|
return 'uuid' in session and rdb.exists(session['uuid'])
|
||||||
|
|
||||||
|
|
||||||
def buildNav():
|
def build_nav():
|
||||||
nav = []
|
nav = []
|
||||||
if isLoggedin():
|
if is_loggedin():
|
||||||
nav.append(('Edit own Account', 'edit'))
|
nav.append(('Edit own Account', 'edit'))
|
||||||
if isAdmin():
|
if is_admin():
|
||||||
nav.append(('List Accounts', 'list_users'))
|
nav.append(('List Accounts', 'list_users'))
|
||||||
nav.append(('Create Account', 'create'))
|
nav.append(('Create Account', 'create'))
|
||||||
nav.append(('Logout', 'logout'))
|
nav.append(('Logout', 'logout'))
|
||||||
@ -80,13 +80,13 @@ def buildNav():
|
|||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html', nav=buildNav())
|
return render_template('index.html', nav=build_nav())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/create', methods=['GET', 'POST'])
|
@app.route('/create', methods=['GET', 'POST'])
|
||||||
def create():
|
def create():
|
||||||
if not isLoggedin():
|
if not is_loggedin():
|
||||||
return render_template('error.html', message="You are not logged in. Please log in first.", nav=buildNav())
|
return render_template('error.html', message="You are not logged in. Please log in first.", nav=build_nav())
|
||||||
|
|
||||||
form = CreateForm()
|
form = CreateForm()
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ def create():
|
|||||||
'uid': form.uid.data,
|
'uid': form.uid.data,
|
||||||
'gn': form.gn.data,
|
'gn': form.gn.data,
|
||||||
'sn': form.sn.data,
|
'sn': form.sn.data,
|
||||||
'pass': makeSecret(form.pwd1.data)
|
'pass': make_secret(form.pwd1.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
# add user
|
# add user
|
||||||
@ -125,18 +125,18 @@ def create():
|
|||||||
message = message + " " + e.message['desc']
|
message = message + " " + e.message['desc']
|
||||||
if 'info' in e.message:
|
if 'info' in e.message:
|
||||||
message = message + ": " + e.message['info']
|
message = message + ": " + e.message['info']
|
||||||
return render_template('error.html', message=message, nav=buildNav())
|
return render_template('error.html', message=message, nav=build_nav())
|
||||||
else:
|
else:
|
||||||
l.unbind_s()
|
l.unbind_s()
|
||||||
return render_template('success.html', message="User successfully created.", nav=buildNav())
|
return render_template('success.html', message="User successfully created.", nav=build_nav())
|
||||||
|
|
||||||
return render_template('create.html', form=form, nav=buildNav())
|
return render_template('create.html', form=form, nav=build_nav())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/edit', methods=['GET', 'POST'])
|
@app.route('/edit', methods=['GET', 'POST'])
|
||||||
def edit():
|
def edit():
|
||||||
if not isLoggedin():
|
if not is_loggedin():
|
||||||
return render_template('error.html', message="You are not logged in. Please log in first.", nav=buildNav())
|
return render_template('error.html', message="You are not logged in. Please log in first.", nav=build_nav())
|
||||||
|
|
||||||
form = EditForm()
|
form = EditForm()
|
||||||
creds = rdb.hgetall(session['uuid'])
|
creds = rdb.hgetall(session['uuid'])
|
||||||
@ -150,25 +150,25 @@ def edit():
|
|||||||
except ldap.INVALID_CREDENTIALS as e:
|
except ldap.INVALID_CREDENTIALS as e:
|
||||||
form.user.errors.append(e.message['desc'])
|
form.user.errors.append(e.message['desc'])
|
||||||
l.unbind_s()
|
l.unbind_s()
|
||||||
return render_template('edit.html', form=form, nav=buildNav())
|
return render_template('edit.html', form=form, nav=build_nav())
|
||||||
else:
|
else:
|
||||||
rdb.hset(session['uuid'], 'pswd', npwd)
|
rdb.hset(session['uuid'], 'pswd', npwd)
|
||||||
l.unbind_s()
|
l.unbind_s()
|
||||||
return render_template('success.html', message="User successfully edited.", nav=buildNav())
|
return render_template('success.html', message="User successfully edited.", nav=build_nav())
|
||||||
|
|
||||||
form.user.data = creds['user']
|
form.user.data = creds['user']
|
||||||
return render_template('edit.html', form=form, nav=buildNav())
|
return render_template('edit.html', form=form, nav=build_nav())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/list')
|
@app.route('/list')
|
||||||
def list_users():
|
def list_users():
|
||||||
if not isLoggedin():
|
if not is_loggedin():
|
||||||
return render_template('error.html', message="You are not logged in. Please log in first.", nav=buildNav())
|
return render_template('error.html', message="You are not logged in. Please log in first.", nav=build_nav())
|
||||||
|
|
||||||
l = ldap.initialize(app.config.get('LDAP_URI', 'ldaps://127.0.0.1'))
|
l = ldap.initialize(app.config.get('LDAP_URI', 'ldaps://127.0.0.1'))
|
||||||
l.simple_bind_s(rdb.hget(session['uuid'], 'user'), rdb.hget(session['uuid'], 'pswd'))
|
l.simple_bind_s(rdb.hget(session['uuid'], 'user'), rdb.hget(session['uuid'], 'pswd'))
|
||||||
sr = l.search_s(app.config.get('LDAP_BASE'), ldap.SCOPE_SUBTREE, '(objectClass=posixAccount)', ['cn'])
|
sr = l.search_s(app.config.get('LDAP_BASE'), ldap.SCOPE_SUBTREE, '(objectClass=posixAccount)', ['cn'])
|
||||||
return render_template('list.html', users=sr, nav=buildNav())
|
return render_template('list.html', users=sr, nav=build_nav())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/login', methods=['GET', 'POST'])
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
@ -184,10 +184,10 @@ def login():
|
|||||||
l = ldap.initialize(app.config.get('LDAP_URI', 'ldaps://127.0.0.1'))
|
l = ldap.initialize(app.config.get('LDAP_URI', 'ldaps://127.0.0.1'))
|
||||||
try:
|
try:
|
||||||
l.simple_bind_s(user, pswd)
|
l.simple_bind_s(user, pswd)
|
||||||
except ldap.INVALID_CREDENTIALS as e:
|
except ldap.INVALID_CREDENTIALS:
|
||||||
form.pswd.errors.append('Invalid Credentials')
|
form.pswd.errors.append('Invalid Credentials')
|
||||||
l.unbind_s()
|
l.unbind_s()
|
||||||
return render_template('login.html', form=form, nav=buildNav())
|
return render_template('login.html', form=form, nav=build_nav())
|
||||||
l.unbind_s()
|
l.unbind_s()
|
||||||
|
|
||||||
session['uuid'] = str(uuid.uuid4())
|
session['uuid'] = str(uuid.uuid4())
|
||||||
@ -197,7 +197,7 @@ def login():
|
|||||||
rdb.expire(session['uuid'], app.config.get('SESSION_TIMEOUT', 3600))
|
rdb.expire(session['uuid'], app.config.get('SESSION_TIMEOUT', 3600))
|
||||||
|
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
return render_template('login.html', form=form, nav=buildNav())
|
return render_template('login.html', form=form, nav=build_nav())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
|
Loading…
Reference in New Issue
Block a user