Merge remote-tracking branch 'refs/remotes/spaetz/521_license_preference' into mergetest

This commit is contained in:
Christopher Allan Webber
2013-01-22 13:43:02 -06:00
6 changed files with 62 additions and 36 deletions

View File

@@ -65,8 +65,19 @@ class EditAccountForm(wtforms.Form):
"Enter your old password to prove you own this account."))
new_password = wtforms.PasswordField(
_('New password'),
[wtforms.validators.Length(min=6, max=30)],
[
wtforms.validators.Optional(),
wtforms.validators.Length(min=6, max=30)
],
id="password")
license_preference = wtforms.SelectField(
_('License preference'),
[
wtforms.validators.Optional(),
wtforms.validators.AnyOf([lic[0] for lic in licenses_as_choices()]),
],
choices=licenses_as_choices(),
description=_('This will be your default license on upload forms.'))
wants_comment_notification = wtforms.BooleanField(
label=_("Email me when others comment on my media"))

View File

@@ -218,45 +218,42 @@ def edit_profile(request, url_user=None):
def edit_account(request):
user = request.user
form = forms.EditAccountForm(request.form,
wants_comment_notification=user.get('wants_comment_notification'))
wants_comment_notification=user.get('wants_comment_notification'),
license_preference=user.get('license_preference'))
if request.method == 'POST':
form_validated = form.validate()
#if the user has not filled in the new or old password fields
if not form.new_password.data and not form.old_password.data:
if form.wants_comment_notification.validate(form):
user.wants_comment_notification = \
form.wants_comment_notification.data
user.save()
messages.add_message(request,
messages.SUCCESS,
_("Account settings saved"))
return redirect(request,
'mediagoblin.user_pages.user_home',
user=user.username)
if form_validated and \
form.wants_comment_notification.validate(form):
user.wants_comment_notification = \
form.wants_comment_notification.data
#so the user has filled in one or both of the password fields
else:
if form_validated:
password_matches = auth_lib.bcrypt_check_password(
form.old_password.data,
user.pw_hash)
if password_matches:
#the entire form validates and the password matches
user.pw_hash = auth_lib.bcrypt_gen_password_hash(
form.new_password.data)
user.wants_comment_notification = \
form.wants_comment_notification.data
user.save()
messages.add_message(request,
messages.SUCCESS,
_("Account settings saved"))
return redirect(request,
'mediagoblin.user_pages.user_home',
user=user.username)
else:
form.old_password.errors.append(_('Wrong password'))
if form_validated and \
form.new_password.data or form.old_password.data:
password_matches = auth_lib.bcrypt_check_password(
form.old_password.data,
user.pw_hash)
if password_matches:
#the entire form validates and the password matches
user.pw_hash = auth_lib.bcrypt_gen_password_hash(
form.new_password.data)
else:
form.old_password.errors.append(_('Wrong password'))
if form_validated and \
form.license_preference.validate(form):
user.license_preference = \
form.license_preference.data
if form_validated and not form.errors:
user.save()
messages.add_message(request,
messages.SUCCESS,
_("Account settings saved"))
return redirect(request,
'mediagoblin.user_pages.user_home',
user=user.username)
return render_to_response(
request,