Create edit_account.html

This commit is contained in:
Jef van Schendel 2012-01-05 00:17:45 +01:00
parent 9c196287ad
commit c8071fa591
4 changed files with 92 additions and 21 deletions

View File

@ -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):

View File

@ -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")
]

View File

@ -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})

View File

@ -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 <http://www.gnu.org/licenses/>.
#}
{% extends "mediagoblin/base.html" %}
{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
{% block mediagoblin_head %}
<script type="text/javascript"
src="{{ request.staticdirect('/js/show_password.js') }}"></script>
{% endblock mediagoblin_head %}
{% block mediagoblin_content %}
<form action="{{ request.urlgen('mediagoblin.edit.account') }}?username={{
user.username }}"
method="POST" enctype="multipart/form-data">
<div class="grid_8 prefix_1 suffix_1 edit_box form_box">
<h1>
{%- trans username=user.username -%}
Changing {{ username }}'s account settings
{%- endtrans %}
</h1>
{{ wtforms_util.render_divs(form) }}
<div class="form_submit_buttons">
<input type="submit" value="{% trans %}Save changes{% endtrans %}" class="button_form" />
{{ csrf_token }}
</div>
</div>
</form>
{% endblock %}