mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
Web UI user section: validation
This commit is contained in:
parent
0353a8a1bc
commit
c947219f59
@ -73,12 +73,27 @@ def user_profile(uid, user):
|
|||||||
@me_or_uuid
|
@me_or_uuid
|
||||||
def update_clients(uid, user):
|
def update_clients(uid, user):
|
||||||
clients_opts = {}
|
clients_opts = {}
|
||||||
for client in set(map(lambda k: k.rsplit('_', 1)[0], request.form.keys())):
|
for key, value in request.form.iteritems():
|
||||||
clients_opts[client] = { k.rsplit('_', 1)[1]: v for k, v in filter(lambda (k, v): k.startswith(client), request.form.iteritems()) }
|
if '_' not in key:
|
||||||
|
continue
|
||||||
|
parts = key.split('_')
|
||||||
|
if len(parts) != 2:
|
||||||
|
continue
|
||||||
|
client, opt = parts
|
||||||
|
if not client or not opt:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if client not in clients_opts:
|
||||||
|
clients_opts[client] = { opt: value }
|
||||||
|
else:
|
||||||
|
clients_opts[client][opt] = value
|
||||||
app.logger.debug(clients_opts)
|
app.logger.debug(clients_opts)
|
||||||
|
|
||||||
for client, opts in clients_opts.iteritems():
|
for client, opts in clients_opts.iteritems():
|
||||||
prefs = store.get(ClientPrefs, (user.id, client))
|
prefs = store.get(ClientPrefs, (user.id, client))
|
||||||
|
if not prefs:
|
||||||
|
continue
|
||||||
|
|
||||||
if 'delete' in opts and opts['delete'] in [ 'on', 'true', 'checked', 'selected', '1' ]:
|
if 'delete' in opts and opts['delete'] in [ 'on', 'true', 'checked', 'selected', '1' ]:
|
||||||
store.remove(prefs)
|
store.remove(prefs)
|
||||||
continue
|
continue
|
||||||
@ -95,6 +110,7 @@ def update_clients(uid, user):
|
|||||||
def change_username_form(uid):
|
def change_username_form(uid):
|
||||||
code, user = UserManager.get(store, uid)
|
code, user = UserManager.get(store, uid)
|
||||||
if code != UserManager.SUCCESS:
|
if code != UserManager.SUCCESS:
|
||||||
|
flash(UserManager.error_str(code))
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
return render_template('change_username.html', user = user)
|
return render_template('change_username.html', user = user)
|
||||||
@ -110,6 +126,10 @@ def change_username_post(uid):
|
|||||||
if username in ('', None):
|
if username in ('', None):
|
||||||
flash('The username is required')
|
flash('The username is required')
|
||||||
return render_template('change_username.html', user = user)
|
return render_template('change_username.html', user = user)
|
||||||
|
if user.name != username and store.find(User, User.name == username).one():
|
||||||
|
flash('This name is already taken')
|
||||||
|
return render_template('change_username.html', user = user)
|
||||||
|
|
||||||
if request.form.get('admin') is None:
|
if request.form.get('admin') is None:
|
||||||
admin = False
|
admin = False
|
||||||
else:
|
else:
|
||||||
@ -290,7 +310,7 @@ def lastfm_unreg(uid, user):
|
|||||||
lfm = LastFm(user, app.logger)
|
lfm = LastFm(user, app.logger)
|
||||||
lfm.unlink_account()
|
lfm.unlink_account()
|
||||||
store.commit()
|
store.commit()
|
||||||
flash('Unliked LastFM account')
|
flash('Unlinked LastFM account')
|
||||||
return redirect(url_for('user_profile', uid = uid))
|
return redirect(url_for('user_profile', uid = uid))
|
||||||
|
|
||||||
@app.route('/user/login', methods = [ 'GET', 'POST'])
|
@app.route('/user/login', methods = [ 'GET', 'POST'])
|
||||||
|
Loading…
Reference in New Issue
Block a user