Exemple #1
0
 def test_at_in_username(self):
     u = user(username='******', save=True)
     form = AuthenticationForm(data={
         'username': u.username,
         'password': '******'
     })
     assert form.is_valid()
Exemple #2
0
    def test_only_active(self):
        # Verify with active user
        form = AuthenticationForm(data={"username": self.active_user.username, "password": "******"})
        assert form.is_valid()

        # Verify with inactive user
        form = AuthenticationForm(data={"username": self.inactive_user.username, "password": "******"})
        assert not form.is_valid()
Exemple #3
0
    def test_only_active(self):
        # Verify with active user
        form = AuthenticationForm(data={'username': self.active_user.username,
                                        'password': '******'})
        assert form.is_valid()

        # Verify with inactive user
        form = AuthenticationForm(data={
            'username': self.inactive_user.username,
            'password': '******'})
        assert not form.is_valid()
Exemple #4
0
def handle_login(request, only_active=True):
    auth.logout(request)

    if request.method == 'POST':
        form = AuthenticationForm(data=request.POST, only_active=only_active)
        if form.is_valid():
            auth.login(request, form.get_user())
            statsd.incr('user.login')

            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()

        return form

    request.session.set_test_cookie()
    return AuthenticationForm()
Exemple #5
0
def handle_login(request, only_active=True):
    auth.logout(request)

    if request.method == 'POST':
        form = AuthenticationForm(data=request.POST, only_active=only_active)
        if form.is_valid():
            auth.login(request, form.get_user())
            statsd.incr('user.login')

            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()

        return form

    request.session.set_test_cookie()
    return AuthenticationForm()
Exemple #6
0
def activate(request, template, activation_key, user_id=None):
    """Activate a User account."""
    activation_key = activation_key.lower()

    if user_id:
        user = get_object_or_404(User, id=user_id)
    else:
        user = RegistrationProfile.objects.get_user(activation_key)

    if user and user.is_active:
        messages.add_message(
            request, messages.INFO,
            _(u'Your account is already activated, log in below.'))
        return HttpResponseRedirect(reverse('users.login'))

    account = RegistrationProfile.objects.activate_user(activation_key,
                                                        request)
    my_questions = None
    form = AuthenticationForm()
    if account:
        # Claim anonymous watches belonging to this email
        statsd.incr('user.activate')
        claim_watches.delay(account)

        my_questions = Question.uncached.filter(creator=account)

        # Update created time to current time
        for q in my_questions:
            q.created = datetime.now()
            q.save(update=True)

    return render(request, template, {
        'account': account, 'questions': my_questions,
        'form': form})
Exemple #7
0
def password_reset_complete(request, template):
    """Password reset complete.

    Based on django.contrib.auth.views. Show a success message.

    """
    form = AuthenticationForm()
    return render(request, template, {'form': form})
Exemple #8
0
def handle403(request):
    """A 403 message that looks nicer than the normal Apache forbidden page"""
    no_cookies = False
    referer = request.META.get('HTTP_REFERER')
    if referer:
        no_cookies = (referer.endswith(reverse('users.login')))

    return render(request, 'handlers/403.html', {
        'form': AuthenticationForm(),
        'no_cookies': no_cookies},
        status=403)
Exemple #9
0
    def test_only_active(self):
        # Verify with active user
        form = AuthenticationForm(data={'username': self.active_user.username,
                                        'password': '******'})
        assert form.is_valid()

        # Verify with inactive user
        form = AuthenticationForm(data={
            'username': self.inactive_user.username,
            'password': '******'})
        assert not form.is_valid()
Exemple #10
0
def user_auth(request, contributor=False, register_form=None, login_form=None):
    """Try to log the user in, or register a user.

    POSTs from these forms do not come back to this view, but instead go to the
    login and register views, which may redirect back to this in case of error.
    """
    next_url = get_next_url(request) or reverse('home')

    if login_form is None:
        login_form = AuthenticationForm()
    if register_form is None:
        register_form = RegisterForm()

    return render(request, 'users/auth.html', {
        'login_form': login_form,
        'register_form': register_form,
        'contributor': contributor,
        'next_url': next_url})
Exemple #11
0
def user_auth(request, login_form=None, notification=None):
    """
    Show user authorization page which includes a link for
    FXA sign-up/login and the legacy login form
    """
    next_url = get_next_url(request) or reverse('home')

    if login_form is None:
        login_form = AuthenticationForm()

    # on load, decide whether legacy or FXA form is visible
    legacy_form_visible = bool(login_form.errors)

    return render(
        request, 'users/auth.html', {
            'login_form': login_form,
            'next_url': next_url,
            'notification': notification,
            'legacy_form_visible': legacy_form_visible,
        })
Exemple #12
0
 def test_at_in_username(self):
     u = UserFactory(username='******')
     form = AuthenticationForm(data={'username': u.username,
                                     'password': '******'})
     assert form.is_valid()