VNOI-Admin / OJ

A modern open-source online judge and contest platform system.
https://oj.vnoi.info
GNU Affero General Public License v3.0
153 stars 67 forks source link

IP address-based authentication #395

Closed magnified103 closed 1 month ago

magnified103 commented 2 months ago

Description

Type of change: new feature

What

Added field ip_auth to the Profile object. The backend compares search for the user with the specified ip_auth. The middleware checks the header REMOTE_ADDR (by default) for the IP address.

In order to use the middleware, add judge.middleware.IPBasedAuthMiddleware right after django.contrib.auth.middleware.AuthenticationMiddleware, e.g.

MIDDLEWARE = (
    'judge.middleware.ShortCircuitMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'judge.middleware.APIMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'judge.middleware.IPBasedAuthMiddleware',
    'judge.middleware.MiscConfigMiddleware',
    'judge.middleware.DMOJLoginMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'judge.user_log.LogUserAccessMiddleware',
    'judge.timezone.TimezoneMiddleware',
    'impersonate.middleware.ImpersonateMiddleware',
    'judge.middleware.DMOJImpersonationMiddleware',
    'judge.middleware.ContestMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
    'judge.social_auth.SocialAuthExceptionMiddleware',
    'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
)

Modify the setting IP_BASED_AUTHENTICATION_HEADER in case another HTTP header is used for the IP address.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

By submitting this pull request, I confirm that my contribution is made under the terms of the AGPL-3.0 License.