These are changes for issue #405, add email comment notification.

This commit is contained in:
Derek Moore
2012-03-15 16:38:56 -07:00
parent 20a3e278bc
commit 252eaf21d5
8 changed files with 133 additions and 19 deletions

View File

@@ -70,6 +70,11 @@ class EditAccountForm(wtforms.Form):
wtforms.validators.Length(min=6, max=30)],
id="password")
wants_comment_notification = wtforms.BooleanField(
_('Comment notification?'),
[wtforms.validators.Required()],
description=_("Check this box to be emailed when someone else comments on your media."))
class EditAttachmentsForm(wtforms.Form):
attachment_name = wtforms.TextField(

View File

@@ -188,29 +188,39 @@ def edit_account(request):
edit_username = request.GET.get('username')
user = request.user
form = forms.EditAccountForm(request.POST)
form = forms.EditAccountForm(request.POST,
wants_comment_notification=user.wants_comment_notification)
if request.method == 'POST' and form.validate():
password_matches = auth_lib.bcrypt_check_password(
request.POST['old_password'],
user.pw_hash)
if (request.POST['old_password'] or request.POST['new_password']) and not \
password_matches:
form.old_password.errors.append(_('Wrong password'))
return render_to_response(
request,
'mediagoblin/edit/edit_account.html',
{'user': user,
'form': form})
if password_matches:
user.pw_hash = auth_lib.bcrypt_gen_password_hash(
request.POST['new_password'])
if request.method == 'POST':
#save status of comment checkbox first, so user does not need to
#change their password as well.
user.wants_comment_notification = request.POST.get(
'wants_comment_notification', False) == u'y'
user.save()
#check remaining fields for validation
if form.validate():
password_matches = auth_lib.bcrypt_check_password(
request.POST['old_password'],
user.pw_hash)
if (request.POST['old_password'] or \
request.POST['new_password']) and not \
password_matches:
form.old_password.errors.append(_('Wrong password'))
return render_to_response(
request,
'mediagoblin/edit/edit_account.html',
{'user': user,
'form': form})
if password_matches:
user.pw_hash = auth_lib.bcrypt_gen_password_hash(
request.POST['new_password'])
user.save()
messages.add_message(request,
messages.SUCCESS,
_("Account settings saved"))