from mediagoblin import messages
from mediagoblin import mg_globals
-from mediagoblin.auth import lib as auth_lib
+from mediagoblin import auth
from mediagoblin.edit import forms
from mediagoblin.edit.lib import may_edit_media
from mediagoblin.decorators import (require_active_login, active_user_from_url,
get_media_entry_by_id,
user_may_alter_collection, get_user_collection)
-from mediagoblin.tools.response import render_to_response, redirect
+from mediagoblin.tools.response import render_to_response, \
+ redirect, redirect_obj
from mediagoblin.tools.translate import pass_to_ugettext as _
from mediagoblin.tools.text import (
convert_to_tag_list_of_dicts, media_tags_as_string)
media.slug = slug
media.save()
- return redirect(request,
- location=media.url_for_self(request.urlgen))
+ return redirect_obj(request, media)
if request.user.is_admin \
and media.uploader != request.user.id \
user.wants_comment_notification = \
form.wants_comment_notification.data
- 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 = \
if request.method == 'POST' and form.validate():
# Make sure there isn't already a Collection with such a slug
# and userid.
- slug_used = check_collection_slug_used(request.db, collection.creator,
+ slug_used = check_collection_slug_used(collection.creator,
form.slug.data, collection.id)
# Make sure there isn't already a Collection with this title
collection.save()
- return redirect(request, "mediagoblin.user_pages.user_collection",
- user=collection.get_creator.username,
- collection=collection.slug)
+ return redirect_obj(request, collection)
if request.user.is_admin \
and collection.creator != request.user.id \
'mediagoblin/edit/edit_collection.html',
{'collection': collection,
'form': form})
+
+
+@require_active_login
+def change_pass(request):
+ form = forms.ChangePassForm(request.form)
+ user = request.user
+
+ if request.method == 'POST' and form.validate():
+
+ if not auth_lib.bcrypt_check_password(
+ form.old_password.data, user.pw_hash):
+ form.old_password.errors.append(
+ _('Wrong password'))
+
+ return render_to_response(
+ request,
+ 'mediagoblin/edit/change_pass.html',
+ {'form': form,
+ 'user': user})
+
+ # Password matches
+ user.pw_hash = auth_lib.bcrypt_gen_password_hash(
+ form.new_password.data)
+ user.save()
+
+ messages.add_message(
+ request, messages.SUCCESS,
+ _('Your password was changed successfully'))
+
+ return redirect(request, 'mediagoblin.edit.account')
+
+ return render_to_response(
+ request,
+ 'mediagoblin/edit/change_pass.html',
+ {'form': form,
+ 'user': user})