Example #1
0
def settings(request):
    form = AccountSettingsForm(request.user,
                               request.POST or None,
                               initial={
                                   'email': request.user.email,
                                   'username': request.user.username,
                                   'name': request.user.name,
                               })
    if form.is_valid():
        old_email = request.user.email
        user = form.save()
        if user.email != old_email:
            UserEmail.objects.get(user=request.user, email=old_email).delete()
            try:
                with transaction.atomic():
                    user_email = UserEmail.objects.create(user=user,
                                                          email=user.email)
            except IntegrityError:
                pass
            else:
                user_email.set_hash()
                user_email.save()
            user.send_confirm_emails()
        messages.add_message(request, messages.SUCCESS,
                             'Your settings were saved.')
        return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'form': form,
        'page': 'settings',
        'has_2fa': Authenticator.objects.user_has_2fa(request.user),
        'AUTH_PROVIDERS': get_auth_providers(),
    })
    return render_to_response('sentry/account/settings.html', context, request)
Example #2
0
def settings(request):
    form = AccountSettingsForm(request.user, request.POST or None, initial={
        'email': request.user.email,
        'username': request.user.username,
        'name': request.user.name,
    })
    if form.is_valid():
        old_email = request.user.email
        user = form.save()
        if user.email != old_email:
            UserEmail.objects.get(user=request.user, email=old_email).delete()
            try:
                with transaction.atomic():
                    user_email = UserEmail.objects.create(user=user, email=user.email)
            except IntegrityError:
                pass
            else:
                user_email.set_hash()
                user_email.save()
            user.send_confirm_emails()
        messages.add_message(request, messages.SUCCESS, 'Your settings were saved.')
        return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'form': form,
        'page': 'settings',
        'has_2fa': Authenticator.objects.user_has_2fa(request.user),
        'AUTH_PROVIDERS': get_auth_providers(),
    })
    return render_to_response('sentry/account/settings.html', context, request)
Example #3
0
def settings(request):
    form = AccountSettingsForm(request.user,
                               request.POST or None,
                               initial={
                                   'email': request.user.email,
                                   'first_name': request.user.first_name,
                                   'language': request.LANGUAGE_CODE,
                               })
    if form.is_valid():
        form.save()
        response = HttpResponseRedirect(
            reverse('sentry-account-settings') + '?success=1')
        if hasattr(request, 'session'):
            request.session['django_language'] = form.cleaned_data['language']
        else:
            response.set_cookie(dj_settings.LANGUAGE_COOKIE_NAME,
                                form.cleaned_data['language'])
        return response

    context = csrf(request)
    context.update({
        'form': form,
        'page': 'settings',
    })
    return render_to_response('sentry/account/settings.html', context, request)
Example #4
0
def account_settings(request):
    user = request.user

    form = AccountSettingsForm(
        user, request, request.POST or None,
        initial={
            'email': UserEmail.get_primary_email(user).email,
            'username': user.username,
            'name': user.name,
        },
    )

    if form.is_valid():
        old_email = user.email

        form.save()

        # remove previously valid email address
        # TODO(dcramer): we should maintain validation here when we support
        # multiple email addresses
        if request.user.email != old_email:
            UserEmail.objects.filter(user=user, email=old_email).delete()
            try:
                with transaction.atomic():
                    user_email = UserEmail.objects.create(
                        user=user,
                        email=user.email,
                    )
            except IntegrityError:
                pass
            else:
                user_email.set_hash()
                user_email.save()
                user.send_confirm_email_singular(user_email)
                msg = _('A confirmation email has been sent to %s.') % user_email.email
                messages.add_message(
                    request,
                    messages.SUCCESS,
                    msg)

        messages.add_message(
            request, messages.SUCCESS, _('Your settings were saved.'))
        return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'form': form,
        'page': 'settings',
        'has_2fa': Authenticator.objects.user_has_2fa(request.user),
        'AUTH_PROVIDERS': auth.get_auth_providers(),
        'email': UserEmail.get_primary_email(user),
        'has_newsletters': newsletter.is_enabled,
    })
    return render_to_response('sentry/account/settings.html', context, request)
Example #5
0
def settings(request):
    form = AccountSettingsForm(
        request.user, request.POST or None, initial={"email": request.user.email, "first_name": request.user.first_name}
    )
    if form.is_valid():
        form.save()
        messages.add_message(request, messages.SUCCESS, "Your settings were saved.")
        return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({"form": form, "page": "settings"})
    return render_to_response("sentry/account/settings.html", context, request)
Example #6
0
def settings(request):
    form = AccountSettingsForm(request.user, request.POST or None, initial={
        'email': request.user.email,
        'first_name': request.user.first_name,
    })
    if form.is_valid():
        form.save()
        messages.add_message(request, messages.SUCCESS, 'Your settings were saved.')
        return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'form': form,
        'page': 'settings',
    })
    return render_to_response('sentry/account/settings.html', context, request)
Example #7
0
def settings(request):
    form = AccountSettingsForm(request.user, request.POST or None, initial={
        'email': request.user.email,
        'first_name': request.user.first_name,
    })
    if form.is_valid():
        form.save()
        messages.add_message(request, messages.SUCCESS, 'Your settings were saved.')
        return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'form': form,
        'page': 'settings',
    })
    return render_to_response('sentry/account/settings.html', context, request)
Example #8
0
def settings(request):
    form = AccountSettingsForm(
        request.user,
        request.POST or None,
        initial={"email": request.user.email, "first_name": request.user.first_name, "language": request.LANGUAGE_CODE},
    )
    if form.is_valid():
        form.save()
        response = HttpResponseRedirect(reverse("sentry-account-settings") + "?success=1")
        if hasattr(request, "session"):
            request.session["django_language"] = form.cleaned_data["language"]
        else:
            response.set_cookie(dj_settings.LANGUAGE_COOKIE_NAME, form.cleaned_data["language"])
        return response

    context = csrf(request)
    context.update({"form": form, "page": "settings"})
    return render_to_response("sentry/account/settings.html", context, request)
Example #9
0
def settings(request):
    form = AccountSettingsForm(request.user, request.POST or None, initial={
        'email': request.user.email,
        'username': request.user.username,
        'name': request.user.name,
    })
    if form.is_valid():
        form.save()
        messages.add_message(request, messages.SUCCESS, 'Your settings were saved.')
        return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'form': form,
        'page': 'settings',
        'has_2fa': Authenticator.objects.user_has_2fa(request.user),
        'AUTH_PROVIDERS': get_auth_providers(),
    })
    return render_to_response('sentry/account/settings.html', context, request)
Example #10
0
def settings(request):
    form = AccountSettingsForm(request.user, request.POST or None, initial={
        'email': request.user.email,
        'username': request.user.username,
        'name': request.user.name,
    })
    if form.is_valid():
        form.save()
        messages.add_message(request, messages.SUCCESS, 'Your settings were saved.')
        return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'form': form,
        'page': 'settings',
        'has_2fa': Authenticator.objects.user_has_2fa(request.user),
        'AUTH_PROVIDERS': get_auth_providers(),
    })
    return render_to_response('sentry/account/settings.html', context, request)
Example #11
0
def settings(request):
    form = AccountSettingsForm(request.user, request.POST or None, initial={
        'email': request.user.email,
        'first_name': request.user.first_name,
        'language': request.LANGUAGE_CODE,
    })
    if form.is_valid():
        form.save()
        response = HttpResponseRedirect(reverse('sentry-account-settings') + '?success=1')
        if hasattr(request, 'session'):
            request.session['django_language'] = form.cleaned_data['language']
        else:
            response.set_cookie(dj_settings.LANGUAGE_COOKIE_NAME, form.cleaned_data['language'])
        return response

    context = csrf(request)
    context.update({
        'form': form,
        'page': 'settings',
    })
    return render_to_response('sentry/account/settings.html', context, request)
Example #12
0
 def test_removes_password_on_empty_password_types(self):
     user = User(password='******')
     form = AccountSettingsForm(user=user)
     self.assertNotIn('old_password', form.fields)
Example #13
0
 def test_requires_username_if_not_matches_email(self):
     user = User(username='******', email='*****@*****.**')
     form = AccountSettingsForm(user=user)
     assert 'username' in form.fields
Example #14
0
 def test_requires_password_on_valid_accounts(self):
     user = User()
     user.set_password('foo')
     form = AccountSettingsForm(user=user)
     self.assertIn('old_password', form.fields)