Exemple #1
0
def organisation_profile(request):
    try:
        organisation = request.user.organisation
    except Organisation.DoesNotExist:
        raise Http404()

    action = request.POST.get('action') if request.method == 'POST' else None

    if action == 'update_profile':
        profile_form = OrganisationProfileForm(request, request.POST, instance=organisation)
        if profile_form.is_valid():
            profile_form.update_profile(request, request.user, organisation)
            return redirect(reverse('organisation_profile'))
    else:
        profile_form = OrganisationProfileForm(request, instance=organisation)

    if action == 'change_password':
        password_form = ChangePasswordForm(organisation.user, request.POST)
        if password_form.is_valid():
            password_form.save()
            return redirect(reverse('organisation_profile'))
    else:
        password_form = ChangePasswordForm(organisation.user)

    return render(request, 'organisations/profile.html', {
        'profile_form': profile_form,
        'password_form': password_form,
        'current_menu_item': 'organisation:profile',
    })
Exemple #2
0
def volunteer_profile(request):
    try:
        volunteer = request.user.volunteer
    except Volunteer.DoesNotExist:
        raise Http404()

    action = request.POST.get('action') if request.method == 'POST' else None

    if action == 'update_profile':
        profile_form = VolunteerProfileForm(request, request.POST, instance=volunteer)
        if profile_form.is_valid():
            profile_form.update_profile(request, request.user, volunteer)
            return redirect(reverse('volunteer_profile'))
    else:
        profile_form = VolunteerProfileForm(request, instance=volunteer)

    if action == 'change_password':
        password_form = ChangePasswordForm(volunteer.user, request.POST)
        if password_form.is_valid():
            password_form.save()
            return redirect(reverse('volunteer_profile'))
    else:
        password_form = ChangePasswordForm(volunteer.user)

    return render(request, 'volunteers/profile.html', {
        'profile_form': profile_form,
        'password_form': password_form,
        'current_menu_item': 'volunteer:profile',
    })
Exemple #3
0
    def post(self, request):
        serializer = ChangePasswordInputSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        change_form_map = {
            'password1': 'new_password',
            'password2': 'new_password',
            'oldpassword': '******'
        }
        change_form_input = map_serializer_to_form(serializer.validated_data,
                                                   change_form_map)

        with transaction.atomic(), clear_messages(request):
            user = request.user
            if not user.has_usable_password():
                raise PermissionDenied(_("This account is disabled."))

            change_form = ChangePasswordForm(user=user, data=change_form_input)
            form_valid_or_raise(change_form, change_form_map)
            change_form.save()

            logout(request, all_tokens=True)  # logout all other sessions
            if allauth_settings.LOGOUT_ON_PASSWORD_CHANGE:
                # maybe logout current session too
                logout(request)
            logout_on_password_change(request, user)  # make allauth happy
            signals.password_changed.send(sender=user.__class__,
                                          request=request,
                                          user=user)
            return Response({})
Exemple #4
0
def get_or_process_password_form(request):
    form = ChangePasswordForm(data=request.POST or None, user=request.user)
    if form.is_valid():
        form.save()
        logout_on_password_change(request, form.user)
        get_adapter(request).add_message(
            request, messages.SUCCESS, 'account/messages/password_changed.txt')
    return form
Exemple #5
0
    def post(self, request):

        form = ChangePasswordForm(request.user, request.POST)
        if form.is_valid():
            form.save()
            return Response(status=status.HTTP_202_ACCEPTED)
        else:
            return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
def settings_password(request):
    if request.method == 'POST':
        form = ChangePasswordForm(request.user, request.POST)
        if form.is_valid():
            form.save()

            # Prevent user logout by Django when password changed
            logout_on_password_change(request, form.user)

            messages.success(request, _('Password is changed'))
            return redirect('users:settings_password')

    else:
        form = ChangePasswordForm(request.user)

    return render(request, 'users/settings_password.html', {'form': form})
Exemple #7
0
def settings_password(request):
    if request.method == 'POST':
        form = ChangePasswordForm(request.user, request.POST)
        if form.is_valid():
            form.save()

            # Prevent user logout by Django when password changed
            logout_on_password_change(request, form.user)

            messages.success(request, _('Password is changed'))
            return redirect('users:settings_password')

    else:
        form = ChangePasswordForm(request.user)

    return render(request, 'users/settings_password.html', {'form': form})
Exemple #8
0
def user_settings_view(request):
    # if this is a POST request we need to process the form data
    if 'edit_profile' in request.POST:
        # create a form instance and populate it with data from the request:
        edit_profile_form = EditProfileForm(data=request.POST,
                                            user=request.user)
        # check whether it's valid:
        if edit_profile_form.is_valid():
            edit_profile_form.save(request)
            messages.success(request,
                             "You've successfully updated your profile.")
            return HttpResponseRedirect('/')
    # if a GET (or any other method) we'll create a blank form
    else:
        edit_profile_form = EditProfileForm(user=request.user)

    if 'change_email' in request.POST:
        change_email_form = ChangeEmailForm(data=request.POST,
                                            user=request.user)
        if change_email_form.is_valid():
            change_email_form.save(request)
            messages.success(
                request, 'Your email address has been changed successfully.')
            return HttpResponseRedirect(
                reverse('account_email_verification_sent'))
    else:
        change_email_form = ChangeEmailForm(user=request.user)

    if 'change_password' in request.POST:
        change_password_form = ChangePasswordForm(data=request.POST,
                                                  user=request.user)
        if change_password_form.is_valid():
            change_password_form.save()
            messages.success(request,
                             'Your password has been changed successfully.')
            return HttpResponseRedirect('/')
    else:
        change_password_form = ChangePasswordForm(user=request.user)

    return render(
        request, 'account/user_settings.html', {
            'change_email_form': change_email_form,
            'change_profile_form': edit_profile_form,
            'change_password_form': change_password_form,
            'current_user': request.user,
        })
Exemple #9
0
def update_account(request):
    user = request.user

    if request.method == 'POST':
        submit_value = request.POST.get('submit')

        if submit_value not in ('email', 'resend', 'cancel', 'password'):
            raise Http404

        if submit_value == 'email':
            email_form = ChangeEmailForm(request.user, request.POST)
            if email_form.is_valid():
                email = email_form.cleaned_data['email']
                EmailAddress.objects.add_email(request, user, email, confirm=True)

                return HttpResponseRedirect(reverse('account_email_verification_sent'))

        else:
            email_form = ChangeEmailForm(request.user)

        if submit_value == 'resend':
            user.new_email.send_confirmation()

        if submit_value == 'cancel':
            user.new_email.delete()

        if submit_value == 'password':
            password_form = ChangePasswordForm(request.user, request.POST)
            if password_form.is_valid():
                password_form.save()

                # Prevent user logout by Django when password changed
                logout_on_password_change(request, password_form.user)

                messages.success(request, _('Password is changed'))
                return redirect('users:update_account')

        else:
            password_form = ChangePasswordForm(request.user)

    else:
        email_form = ChangeEmailForm(request.user, initial={'email': request.user.email})
        password_form = ChangePasswordForm(request.user)

    return render(request, 'users/account_update.html', {'email_form': email_form, 'password_form': password_form})
Exemple #10
0
def update(request, profile):
    form = ProfileUpdateForm(instance=profile)
    pwform = ChangePasswordForm()

    if request.method == 'POST':
        form = ProfileUpdateForm(request.POST, request.FILES, instance=profile)
        pwform = ChangePasswordForm()
        if form.is_valid():
            profile = form.save()
            pwform.save()
            return redirect(profile)

    return render(request, 'profiles/update.html',
                  dict(
                      profile=profile,
                      form=form,
                      pwform=pwform,
                  ))
Exemple #11
0
def artist_settings(request):
    # if this is a POST request we need to process the form data
    if 'artist_info' in request.POST:
        # create a form instance and populate it with data from the request:
        artist_info_form = ArtistInfoForm(data=request.POST,
                                          instance=request.user)
        # check whether it's valid:
        if artist_info_form.is_valid():
            artist_info_form.save(request)
            messages.success(request,
                             "You've successfully updated your profile.")
            return redirect('artist_dashboard:settings')
    # if a GET (or any other method) we'll create a blank form
    else:
        artist_info_form = ArtistInfoForm(instance=request.user)

    if 'change_email' in request.POST:
        change_email_form = user_forms.ChangeEmailForm(data=request.POST,
                                                       user=request.user)
        if change_email_form.is_valid():
            change_email_form.save(request)
            messages.success(
                request, 'Your email address has been changed successfully.')
            return redirect('account_email_verification_sent')
    else:
        change_email_form = user_forms.ChangeEmailForm(user=request.user)

    if 'change_password' in request.POST:
        change_password_form = ChangePasswordForm(data=request.POST,
                                                  user=request.user)
        if change_password_form.is_valid():
            change_password_form.save()
            messages.success(request,
                             'Your password has been changed successfully.')
            return redirect('artist_dashboard:settings')
    else:
        change_password_form = ChangePasswordForm(user=request.user)

    return render(
        request, 'artist_dashboard/settings.html', {
            'change_email_form': change_email_form,
            'artist_info_form': artist_info_form,
            'change_password_form': change_password_form,
        })
Exemple #12
0
def artist_settings(request):
    # if this is a POST request we need to process the form data
    if 'artist_info' in request.POST:
        # create a form instance and populate it with data from the request:
        artist_info_form = ArtistInfoForm(data=request.POST, instance=request.user)
        # check whether it's valid:
        if artist_info_form.is_valid():
            artist_info_form.save(request)
            messages.success(request, "You've successfully updated your profile.")
            return redirect('artist_dashboard:settings')
    # if a GET (or any other method) we'll create a blank form
    else:
        artist_info_form = ArtistInfoForm(instance=request.user)

    if 'change_email' in request.POST:
        change_email_form = user_forms.ChangeEmailForm(data=request.POST, user=request.user)
        if change_email_form.is_valid():
            change_email_form.save(request)
            messages.success(request, 'Your email address has been changed successfully.')
            return redirect('account_email_verification_sent')
    else:
        change_email_form = user_forms.ChangeEmailForm(user=request.user)

    if 'change_password' in request.POST:
        change_password_form = ChangePasswordForm(data=request.POST, user=request.user)
        if change_password_form.is_valid():
            change_password_form.save()
            messages.success(request, 'Your password has been changed successfully.')
            return redirect('artist_dashboard:settings')
    else:
        change_password_form = ChangePasswordForm(user=request.user)

    return render(request, 'artist_dashboard/settings.html', {
        'change_email_form': change_email_form,
        'artist_info_form': artist_info_form,
        'change_password_form': change_password_form,
    })
Exemple #13
0
def settings(request):
    """
    Page with user's setting with options for password changing.

    :param request:
    :return:
    """

    context_dict = {}

    if request.method == 'POST':
        form = ChangePasswordForm(user=request.user, data=request.POST)

        if form.is_valid():
            form.save()
            return redirect('account_login')
        else:
            context_dict['error'] = True
    else:
        form = ChangePasswordForm(user=request.user)

    context_dict['form'] = form

    return render(request, 'stashmarksApp/settings.html', context_dict)
Exemple #14
0
def user_settings_view_new(request):

    profile_updated = False
    # if this is a POST request we need to process the form data
    if 'edit_profile' in request.POST:
        # create a form instance and populate it with data from the request:
        edit_profile_form = EditProfileForm(data=request.POST,
                                            user=request.user)
        # check whether it's valid:
        if edit_profile_form.is_valid():
            edit_profile_form.save(request)
            messages.success(request,
                             "You've successfully updated your profile.")
            profile_updated = True
    # if a GET (or any other method) we'll create a blank form
    else:
        edit_profile_form = EditProfileForm(user=request.user)

    if 'edit_active_card' in request.POST:
        try:
            stripe_token = request.POST.get('stripe_token')
            customer, created = Customer.get_or_create(
                subscriber=subscriber_request_callback(request))
            update_active_card(customer, stripe_token)
        except stripe.StripeError as e:
            # add form error here
            return _ajax_response(
                request, JsonResponse({'error': e.args[0]}, status=500))

        messages.success(request,
                         'Your account card has been changed successfully.')
        profile_updated = True

    if 'change_email' in request.POST:
        change_email_form = ChangeEmailForm(data=request.POST,
                                            user=request.user)
        if change_email_form.is_valid():
            change_email_form.save(request)
            messages.success(
                request, 'Your email address has been changed successfully.')
            profile_updated = True
    else:
        change_email_form = ChangeEmailForm(user=request.user)

    if 'change_password' in request.POST:
        change_password_form = ChangePasswordForm(data=request.POST,
                                                  user=request.user)
        if change_password_form.is_valid():
            change_password_form.save()
            messages.success(request,
                             'Your password has been changed successfully.')
            profile_updated = True
    else:
        change_password_form = ChangePasswordForm(user=request.user)

    # if this is a POST request we need to process the form data
    if 'artist_info' in request.POST:
        # create a form instance and populate it with data from the request:
        artist_info_form = ArtistInfoForm(data=request.POST,
                                          instance=request.user)
        # check whether it's valid:
        if artist_info_form.is_valid():
            artist_info_form.save(request)
            messages.success(request,
                             "You've successfully updated your profile.")
            profile_updated = True
        else:
            assert False, artist_info_form.errors
    # if a GET (or any other method) we'll create a blank form
    else:
        artist_info_form = ArtistInfoForm(instance=request.user)

    if 'billing_info' in request.POST:
        billing_address_form = BillingAddressForm(None, request.user,
                                                  request.POST)
        if billing_address_form.is_valid():
            billing_address_form.save()
            profile_updated = True
        else:
            billing_address_form = BillingAddressForm(None, request.user, None)

    if profile_updated:
        return HttpResponseRedirect('/accounts/settings/')

    plan = None
    period_end = {}
    period_end['date'] = None

    customer_detail = None
    customer_charges = None
    user_archive_access_until = None
    monthly_pledge_in_dollars = None
    cancel_at = None
    billing_address = None

    show_email_confirmation = False

    try:
        customer = request.user.customer
    except:
        customer = None

    user_archive_access_until = None
    if request.user.has_archive_access:
        user_archive_access_until = request.user.get_archive_access_expiry_date(
        )

    if customer and customer.has_active_subscription():
        plan_id = request.user.customer.current_subscription.plan
        try:
            plan = stripe.Plan.retrieve(id=plan_id)
        except stripe.error.InvalidRequestError:
            plan = None

    customer_charges = request.user.get_donations().order_by('-date')
    charges_value = 0
    for charge in customer_charges:
        if charge.amount:
            charges_value = charges_value + charge.amount

        artist_info_form = ArtistInfoForm(instance=request.user)
    customer_detail = CustomerDetail.get(id=request.user.customer.stripe_id)

    if customer_detail and customer_detail.subscription:
        monthly_pledge_in_dollars = customer_detail.subscription.plan.amount / 100

    if customer_detail and customer_detail.subscription:
        period_end["date"] = datetime.fromtimestamp(
            customer_detail.subscription.current_period_end).strftime(
                "%d/%m/%y")
        period_end["due"] = datetime.fromtimestamp(
            customer_detail.subscription.current_period_end) <= datetime.now()

    if customer_detail and customer_detail.subscription and customer_detail.subscriptions.data:
        cancel_at = customer_detail.subscriptions.data[0][
            'cancel_at_period_end']
    else:
        cancel_at = False

    try:
        billing_address = request.user.addresses.get(
            is_default_for_billing=True)
    except UserAddress.DoesNotExist:
        try:
            billing_address = request.user.addresses.first()
        except UserAddress.DoesNotExist:
            billing_address = UserAddress()

    return render(
        request, 'account/user_settings_new.html', {
            'STRIPE_PUBLIC_KEY': settings.STRIPE_PUBLIC_KEY,
            'change_email_form': change_email_form,
            'change_profile_form': edit_profile_form,
            'change_password_form': change_password_form,
            'current_user': request.user,
            'artist_info_form': artist_info_form,
            'plan': plan,
            'donations': request.user.get_donations() or None,
            'customer_detail': customer_detail or '',
            'customer_charges': customer_charges or '',
            'charges_value': request.user.get_donation_amount or '0',
            'period_end': period_end,
            'user_archive_access_until': user_archive_access_until
            or 'unverified account',
            'monthly_pledge_in_dollars': monthly_pledge_in_dollars or 'no',
            'cancelled': cancel_at or '',
            'donate_url': reverse('donate'),
            'billing_address': billing_address or '',
            'show_email_confirmation_dialog': show_email_confirmation
        })