Create edit_account.html
authorJef van Schendel <mail@jefvanschendel.nl>
Wed, 4 Jan 2012 23:17:45 +0000 (00:17 +0100)
committerJef van Schendel <mail@jefvanschendel.nl>
Wed, 4 Jan 2012 23:17:45 +0000 (00:17 +0100)
mediagoblin/edit/forms.py
mediagoblin/edit/routing.py
mediagoblin/edit/views.py
mediagoblin/templates/mediagoblin/edit/edit_account.html [new file with mode: 0644]

index 406de3f8428bc920b1479877528ccf3b4468124b..df2190110aa4d2608dc73e8aecd950a37377b08a 100644 (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):
index 34e9fd809d331ca545b9fd1c028995a789f50c8f..5216f7caab4e0305b82ac24df7ea2d15332ba79e 100644 (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")
+    ]
index 4cb98c15933f07a3f36bcb77676629535749ad6f..bae85c5d3a8a529b98514c4d994b08fb5b9d3ece 100644 (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})
diff --git a/mediagoblin/templates/mediagoblin/edit/edit_account.html b/mediagoblin/templates/mediagoblin/edit/edit_account.html
new file mode 100644 (file)
index 0000000..0a56416
--- /dev/null
@@ -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 %}