Beispiel #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',
    })
Beispiel #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',
    })
Beispiel #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({})
Beispiel #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
Beispiel #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})
Beispiel #7
0
def user_profile_sittings (request  ) :
    change_password=ChangePasswordForm()
    user=request.user
    user_ads=get_user_ads(user)
    user_favoret=get_object_or_404(user_details , user=user).favoret_ads.all()
    context={'user_ads':user_ads , 'user_favoret':user_favoret , 'change_password':change_password  }
    return render(request , 'user_profile_sittings.html' , context)
Beispiel #8
0
def my_profile(request):

    try:
        getattr(request.user, 'agent')       

        table = CommandeDriverTable(Commandes.objects.filter(driver=request.user).order_by('created_at')[:10])
    except AttributeError:
        table = CommandeClientTable(Commandes.objects.filter(colis__client=request.user).order_by('created_at')[:10])


    context = {
            'form' : UserForm(instance=request.user),
            'form_person' : PersonForm(instance=request.user.person),
            'form_password' : ChangePasswordForm(request.user),
            'table' : table
        }
    if request.method == 'POST':
        form = UserForm(request.POST, request.FILES, instance=request.user)
        form_person = PersonForm(request.POST,  instance=request.user.person)


        if form.is_valid() and form_person.is_valid():
            form.save()
            form_person.save()
            messages.success(request, ('Votre profile a été mis à jour.'))
            return HttpResponseRedirect("/users/profile")
        else:
            messages.error(request, ('Certaines données sont incorecttes'))


    return render(request, 'utilisateurs/my_profile.html', context)
Beispiel #9
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data()
        context['passwordchangeform'] = ChangePasswordForm()
        user_id = self.kwargs['pk']
        context['schedule_cnt'] = TravelSchedule.objects.filter(owner=user_id).count()
        context['travelbookmark_cnt'] = TravelBookmark.objects.filter(owner=user_id).count()
        context['schedulebookmark_cnt'] = ScheduleBookmark.objects.filter(owner=user_id).count()

        return context
Beispiel #10
0
    def get_context_data(self, **kwargs):
        u"""
        Seta váriaveis para o contexto
        """
        context = super(SpeakerProfileTemplateView,
                        self).get_context_data(**kwargs)
        context['basic_information_form'] = SpeakerBasicInformationForm(
            instance=self.request.user)
        context['contact_list'] = KindContact.objects.filter(
            speaker=self.request.user)

        context['password_form'] = ChangePasswordForm(user=self.request.user)

        return context
Beispiel #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,
    })
Beispiel #12
0
def account_page(request, page):
    try:
        data = {}

        profile = request.user.userprofile

        template = 'account/settings/' + page + '.html'

        if page == 'password':
            if request.method == 'POST':
                form = ChangePasswordForm(request.POST)

                if form.is_valid():
                    print('trying to change password')
                    print('password changed')
                else:
                    print(form.errors)

                return redirect('core:account')
        elif page == 'orders':
            orders = Order.objects.filter(user=request.user, ordered=True)

            data['orders'] = orders
        elif page == 'deliveries':
            orders = Order.objects.filter(driver=request.user.id,
                                          ordered=True,
                                          being_delivered=True,
                                          delivered=False)

            data['orders'] = orders

        if profile.vendor_owner:
            data['vendor'] = get_vendors(profile)

        return render(request, template, data)
    except:
        return redirect('core:account')
Beispiel #13
0
 def _render(self, request, user_form, profile_formset, attendance_formset):
     password_form = ChangePasswordForm(user=request.user) if request.user.has_usable_password() else SetPasswordForm(user=request.user)
     steam_account = request.user.socialaccount_set.first()  # This condition breaks down if we support multiple social accounts.
     if steam_account:
         steam_account = steam_account.uid.replace('openid/id', 'profiles')  # This is heavily steam specific
     context = {
         'user_form': user_form,
         'password_form': password_form,
         'profile_formset': profile_formset,
         'attendance_formset': attendance_formset,
         'steam_account': steam_account,
     }
     return TemplateResponse(
         request,
         'accounts/profile_edit.html',
         context=context,
     )
Beispiel #14
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})
Beispiel #15
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,
        })
Beispiel #16
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,
        })
Beispiel #17
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})
Beispiel #18
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,
                  ))
Beispiel #19
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)
Beispiel #20
0
def changePassword(request):
    form = ChangePasswordForm()
    return render(request, 'registration/changepassword.html', {'form': form})
Beispiel #21
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
        })
Beispiel #22
0
 def setup_template_context(self):
     return {'form': ChangePasswordForm(instance=self.user)}
Beispiel #23
0
     else:
         lform = LocationForm()
         mform = UserSettingsForm(request.POST)
         mform.user = request.user
         if mform.is_valid():
             if mform.cleaned_data['email'] != user.email:
                 set_mail(user, mform.cleaned_data['email'])
             if mform.cleaned_data['displayname'] != profile.displayname:
                 profile.displayname = mform.cleaned_data['displayname']
                 profile.save()
             user.save()
 else:
     lform = LocationForm()
     mform = UserSettingsForm()
 if user.password != "":
     passform = ChangePasswordForm()
 else:
     passform = SetPasswordForm()
 context.update({
     "apps": apps,
     "accountlist": accountlist,
     'profile': profile,
     'lform': lform,
     'mform': mform,
     'passform': passform
 })
 map, showmap = create_map(profile.location)
 context["map"] = map
 context["showmap"] = showmap
 return render_to_response('users/usersettings.html', context,
                           RequestContext(request))
Beispiel #24
0
def profile(req):
    form = ChangePasswordForm()
    user = req.user
    # user_profile = user.user_profile.all()[0]
    user_profile = user.user_profile
    if user_profile:
        data = {
            'gender': user_profile.gender,
            'firstname': user.first_name,
            'lastname': user.last_name,
            'telephone': user_profile.telephone,
            'email': user.email
        }
    else:
        data = {}
    if req.method == 'POST':
        if req.POST.get("picture"):
            image = ImageForm(req.POST, req.FILES)
            if image.is_valid():
                image = image.save()
                if user_profile:
                    user_profile.profile_picture = image
                    user_profile.save()
                else:
                    user_profile = UserProfile()
                    user_profile.user = user
                    user_profile.profile_picture = image
                    user_profile.save()
                messages.success(req, "Image uploaded successfully")
                image = ImageForm()
            else:
                messages.error(req, image.errors)

            userprofile = UserProfileForm(initial=data)
        elif req.POST.get("infos"):
            userprofile = UserProfileForm(req.POST)
            if userprofile.is_valid():
                user.first_name = userprofile.cleaned_data['firstname']
                user.last_name = userprofile.cleaned_data['lastname']
                user.email = userprofile.cleaned_data['email']
                user.save()
                if user_profile:
                    user_profile.gender = userprofile.cleaned_data['gender']
                    user_profile.telephone = userprofile.cleaned_data[
                        'telephone']
                    user_profile.save()
                else:
                    user_profile = UserProfile()
                    user_profile.user = user
                    user_profile.gender = userprofile.cleaned_data['gender']
                    user_profile.telephone = userprofile.cleaned_data[
                        'telephone']
                    user_profile.save()
                messages.success(req,
                                 "Personal information uploaded successfully")
            else:
                messages.error(req, "Error in form")

            image = ImageForm()
    else:
        userprofile = UserProfileForm(initial=data)
        image = ImageForm()

    context = {
        "form": form,
        "userprofile": userprofile,
        "image": image,
    }
    return render(req, "customer-account.html", context)