Commit 4e0b7c18 authored by Bruno Martin's avatar Bruno Martin
Browse files

change fields needed for signup

parent f4db243f
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import get_user_model
from django.conf import settings
from rest_framework import serializers
from rest_auth.registration.serializers import SocialLoginSerializer, RegisterSerializer
from allauth.account.adapter import get_adapter
......@@ -9,6 +10,8 @@ from allauth.socialaccount.helpers import complete_social_login
from requests.exceptions import HTTPError
from cities_light.models import City, Region
import requests
from .models import PoliticalFront, ActivismSchoolWorkplace, CtbRole
User = get_user_model()
......@@ -34,11 +37,11 @@ class RegistrationSerializer(RegisterSerializer):
name = serializers.CharField(max_length=255, required=False)
captcha = serializers.CharField(max_length=2048)
city = serializers.PrimaryKeyRelatedField(queryset=City.objects.all(),
allow_null=True)
state = serializers.PrimaryKeyRelatedField(queryset=Region.objects.all(),
allow_null=True)
phone_number = serializers.CharField(max_length=255, allow_null=True)
# city = serializers.PrimaryKeyRelatedField(queryset=City.objects.all(),
# allow_null=True)
# state = serializers.PrimaryKeyRelatedField(queryset=Region.objects.all(),
# allow_null=True)
# phone_number = serializers.CharField(max_length=255, allow_null=True)
origin = serializers.CharField(max_length=30, required=False, allow_blank=True)
def get_cleaned_data(self):
......@@ -47,9 +50,9 @@ class RegistrationSerializer(RegisterSerializer):
'username': self.validated_data.get('username', ''),
'password1': self.validated_data.get('password1', ''),
'email': self.validated_data.get('email', ''),
'city': self.validated_data.get('city', None),
'state': self.validated_data.get('state', None),
'phone_number': self.validated_data.get('phone_number', ''),
# 'city': self.validated_data.get('city', None),
# 'state': self.validated_data.get('state', None),
# 'phone_number': self.validated_data.get('phone_number', ''),
'origin': self.validated_data.get('origin', 'signup')
}
......@@ -60,14 +63,16 @@ class RegistrationSerializer(RegisterSerializer):
'response': attr
})
captcha_resp = captcha_req.json()
print(settings.RECAPTCHA_SECRET_KEY)
print(captcha_resp)
if not captcha_resp['success']:
raise serializers.ValidationError(_('Invalid CAPTCHA.'))
def custom_signup(self, request, user):
user.name = self.cleaned_data['name']
user.phone_number = self.cleaned_data['phone_number']
user.city = self.cleaned_data['city']
user.state = self.cleaned_data['state']
# user.phone_number = self.cleaned_data['phone_number']
# user.city = self.cleaned_data['city']
# user.state = self.cleaned_data['state']
user.origin = self.cleaned_data['origin']
user.save()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment