diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index 8f840db..29f1b02 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -10,6 +10,7 @@ from PIL import Image from bleach.sanitizer import Cleaner from . import models, old_models +from .. import settings #custom_error = lambda x: ValidationError(dict(non_field_errors=x)) @@ -303,6 +304,14 @@ class UserSerializer(serializers.ModelSerializer): depth = 1 +def request_from_protospace(request): + whitelist = ['24.66.110.96', '205.233.15.76', '205.233.15.69'] + + # set (not appended) directly by nginx so we can trust it + real_ip = request.META.get('HTTP_X_REAL_IP', False) + + return real_ip in whitelist + class RegistrationSerializer(RegisterSerializer): first_name = serializers.CharField(max_length=32) @@ -312,6 +321,12 @@ class RegistrationSerializer(RegisterSerializer): def custom_signup(self, request, user): data = request.data + is_test_signup = bool(settings.DEBUG and data['last_name'] == 'tester') + + if not request_from_protospace(request) and not is_test_signup: + user.delete() + raise ValidationError(dict(non_field_errors='Can only register from Protospace.')) + if data['existing_member'] == 'true': old_members = old_models.Members.objects.using('old_portal') try: diff --git a/webclient/src/LoginSignup.js b/webclient/src/LoginSignup.js index bf7578c..d0c9d7b 100644 --- a/webclient/src/LoginSignup.js +++ b/webclient/src/LoginSignup.js @@ -18,6 +18,7 @@ export function LoginForm(props) { .then(res => { setError({}); props.setTokenCache(res.key); + window.scrollTo(0, 0); }) .catch(err => { setLoading(false); @@ -72,6 +73,7 @@ export function SignupForm(props) { .then(res => { setError({}); props.setTokenCache(res.key); + window.scrollTo(0, 0); }) .catch(err => { setLoading(false); @@ -82,7 +84,7 @@ export function SignupForm(props) { return (