From: Jef van Schendel Date: Wed, 4 Jan 2012 23:17:45 +0000 (+0100) Subject: Create edit_account.html X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c8071fa591ad148fbffdabc4d6dd71f5666c2172;p=mediagoblin.git Create edit_account.html --- diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index 406de3f8..df219011 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -37,7 +37,7 @@ class EditForm(wtforms.Form): _('Slug'), [wtforms.validators.Required(message=_("The slug can't be empty"))], description=_( - "The title part of this media's URL. " + "The title part of this media's address. " "You usually don't need to change this.")) @@ -52,20 +52,19 @@ class EditProfileForm(wtforms.Form): url = wtforms.TextField( _('Website'), [wtforms.validators.Optional(), - wtforms.validators.URL(message='Improperly formed URL')]) + wtforms.validators.URL(message="""This address contains errors""")]) + + +class EditAccountForm(wtforms.Form): old_password = wtforms.PasswordField( _('Old password'), - [wtforms.validators.Optional()]) + [wtforms.validators.Required()], + description=_( + "Enter your old password to prove you own this account.")) new_password = wtforms.PasswordField( - _('New Password'), - [wtforms.validators.Optional(), - wtforms.validators.Length(min=6, max=30), - wtforms.validators.EqualTo( - 'confirm_password', - 'Passwords must match.')]) - confirm_password = wtforms.PasswordField( - 'Confirm password', - [wtforms.validators.Optional()]) + _('New password'), + [wtforms.validators.Required(), + wtforms.validators.Length(min=6, max=30)]) class EditAttachmentsForm(wtforms.Form): diff --git a/mediagoblin/edit/routing.py b/mediagoblin/edit/routing.py index 34e9fd80..5216f7ca 100644 --- a/mediagoblin/edit/routing.py +++ b/mediagoblin/edit/routing.py @@ -20,4 +20,7 @@ from routes.route import Route edit_routes = [ # Media editing view handled in user_pages/routing.py Route('mediagoblin.edit.profile', '/profile/', - controller="mediagoblin.edit.views:edit_profile")] + controller="mediagoblin.edit.views:edit_profile"), + Route('mediagoblin.edit.account', '/account/', + controller="mediagoblin.edit.views:edit_account") + ] diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 4cb98c15..bae85c5d 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -161,6 +161,35 @@ def edit_profile(request): url=user.get('url'), bio=user.get('bio')) + if request.method == 'POST' and form.validate(): + user.url = unicode(request.POST['url']) + user.bio = unicode(request.POST['bio']) + + user.bio_html = cleaned_markdown_conversion(user['bio']) + + user.save() + + messages.add_message(request, + messages.SUCCESS, + _("Profile changes saved")) + return redirect(request, + 'mediagoblin.user_pages.user_home', + user=user['username']) + + return render_to_response( + request, + 'mediagoblin/edit/edit_profile.html', + {'user': user, + 'form': form}) + + +@require_active_login +def edit_account(request): + edit_username = request.GET.get('username') + user = request.user + + form = forms.EditAccountForm(request.POST) + if request.method == 'POST' and form.validate(): password_matches = auth_lib.bcrypt_check_password( request.POST['old_password'], @@ -172,30 +201,25 @@ def edit_profile(request): return render_to_response( request, - 'mediagoblin/edit/edit_profile.html', + 'mediagoblin/edit/edit_account.html', {'user': user, 'form': form}) - user.url = unicode(request.POST['url']) - user.bio = unicode(request.POST['bio']) - if password_matches: user['pw_hash'] = auth_lib.bcrypt_gen_password_hash( request.POST['new_password']) - user.bio_html = cleaned_markdown_conversion(user['bio']) - user.save() messages.add_message(request, messages.SUCCESS, - _("Profile edited!")) + _("Account settings saved")) return redirect(request, 'mediagoblin.user_pages.user_home', user=user['username']) return render_to_response( request, - 'mediagoblin/edit/edit_profile.html', + 'mediagoblin/edit/edit_account.html', {'user': user, 'form': form}) diff --git a/mediagoblin/templates/mediagoblin/edit/edit_account.html b/mediagoblin/templates/mediagoblin/edit/edit_account.html new file mode 100644 index 00000000..0a564161 --- /dev/null +++ b/mediagoblin/templates/mediagoblin/edit/edit_account.html @@ -0,0 +1,45 @@ +{# +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +#} +{% extends "mediagoblin/base.html" %} + +{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} + +{% block mediagoblin_head %} + +{% endblock mediagoblin_head %} + +{% block mediagoblin_content %} + +
+
+

+ {%- trans username=user.username -%} + Changing {{ username }}'s account settings + {%- endtrans %} +

+ {{ wtforms_util.render_divs(form) }} +
+ + {{ csrf_token }} +
+
+
+{% endblock %}