def change_password(request): """ Handles POST requests to change a users password """ context = _create_preference_context(request) account = get_account(request) if account.is_default_account(): return direct_to_template(request, 'useradmin/not-logged-in.html', {}) if request.method == 'POST': password_form = ChangePasswordForm(request.POST, my_account=account) if password_form.is_valid(): account.set_password(password_form.cleaned_data['new_password1']) account.save() new_message(request, 'Your password has been changed.', type=Messages.SUCCESS) else: context['password_form'] = password_form return direct_to_template( request, 'webfront/preferences.html', context ) return HttpResponseRedirect(reverse('webfront-preferences'))
def _create_preference_context(request): """ Creates a context used by different views for the multiform preference page """ account = get_account(request) if account.ext_sync: password_form = None else: password_form = ChangePasswordForm() context = { 'navpath': [('Home', '/'), ('Preferences', None)], 'title': 'Personal NAV preferences', 'password_form': password_form, 'columns_form': ColumnsForm(initial={'num_columns': get_widget_columns(account)}), 'account': account, 'tool': { 'name': 'My account', 'description': 'Edit my personal NAV account settings' }, 'navbar_formset': NavbarLinkFormSet(queryset=NavbarLink.objects.filter(account=account)), } return context