def post(self, request, format=None): serializer = CustomSignupSerializer(data=request.data) if serializer.is_valid(): email = serializer.data['email'] password = serializer.data['password'] first_name = serializer.data['first_name'] last_name = serializer.data['last_name'] phone = serializer.data['phone'] must_validate_email = getattr(settings, "AUTH_EMAIL_VERIFICATION", True) try: user = get_user_model().objects.get(email=email) if user.is_verified: content = { 'detail': _('User with this Email address already exists.'), 'key': 'user_already_exists' } return Response(content, status=status.HTTP_400_BAD_REQUEST) try: # Delete old signup codes signup_code = SignupCode.objects.get(user=user) signup_code.delete() except SignupCode.DoesNotExist: pass except get_user_model().DoesNotExist: user = get_user_model().objects.create_user(email=email) # Set user fields provided user.set_password(password) user.first_name = first_name user.last_name = last_name user.phone = phone if not must_validate_email: user.is_verified = True send_multi_format_email('welcome_email', { 'email': user.email, }, target_email=user.email) user.save() if must_validate_email: # Create and associate signup code ipaddr = self.request.META.get('REMOTE_ADDR', '0.0.0.0') signup_code = SignupCode.objects.create_signup_code( user, ipaddr) AccountMailSender(user=user, request=request).send_signup_code_email( signup_code.code) return Response(UserSerializer(user).data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): serializer = self.serializer_class(data=request.data) if serializer.is_valid(): email = serializer.data['email'] password = serializer.data['password'] first_name = serializer.data['first_name'] last_name = serializer.data['last_name'] federative_unit = serializer.data['federative_unit'] must_validate_email = getattr(settings, "AUTH_EMAIL_VERIFICATION", True) try: user = get_user_model().objects.get(email=email) if user.is_verified: content = {'detail': _('Email address already taken.')} return Response(content, status=status.HTTP_400_BAD_REQUEST) try: # Delete old signup codes signup_code = SignupCode.objects.get(user=user) signup_code.delete() except SignupCode.DoesNotExist: pass except get_user_model().DoesNotExist: user = get_user_model().objects.create_user(email=email) # Set user fields provided user.set_password(password) user.first_name = first_name user.last_name = last_name user.federative_unit = federative_unit if not must_validate_email: user.is_verified = True send_multi_format_email('welcome_email', { 'email': user.email, }, target_email=user.email) user.save() if must_validate_email: # Create and associate signup code ipaddr = self.request.META.get('REMOTE_ADDR', '0.0.0.0') signup_code = SignupCode.objects.create_signup_code( user, ipaddr) signup_code.send_signup_email() content = { 'email': email, 'first_name': first_name, 'last_name': last_name } return Response(content, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): serializer = self.serializer_class(data=request.data) if serializer.is_valid(): email = serializer.data['email'] password = serializer.data['password'] first_name = serializer.data['first_name'] last_name = serializer.data['last_name'] must_validate_email = getattr(settings, "AUTH_EMAIL_VERIFICATION", True) try: user = get_user_model().objects.get(email=email) if user.is_verified: content = {'detail': _('User with this Email address already exists.')} return Response(content, status=status.HTTP_400_BAD_REQUEST) try: # Delete old signup codes signup_code = SignupCode.objects.get(user=user) signup_code.delete() except SignupCode.DoesNotExist: pass except get_user_model().DoesNotExist: user = get_user_model().objects.create_user(email=email) # Set user fields provided user.set_password(password) user.first_name = first_name user.last_name = last_name if not must_validate_email: user.is_verified = True send_multi_format_email('welcome_email', {'email': user.email,}, target_email=user.email) user.save() if must_validate_email: # Create and associate signup code ipaddr = self.request.META.get('REMOTE_ADDR', '0.0.0.0') signup_code = SignupCode.objects.create_signup_code(user, ipaddr) signup_code.send_signup_email() content = {'email': email, 'first_name': first_name, 'last_name': last_name} return Response(content, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): serializer = self.serializer_class(data=request.data) if serializer.is_valid(): email = serializer.data['email'] username = serializer.data['username'] password = serializer.data['password'] first_name = serializer.data['first_name'] last_name = serializer.data['last_name'] must_validate_email = getattr(settings, "AUTH_EMAIL_VERIFICATION", True) try: user = get_user_model().objects.get(email=email) if user.is_verified: content = { 'detail': _('User with this Email address already exists.') } return Response(content, status=status.HTTP_400_BAD_REQUEST) except get_user_model().DoesNotExist: user = get_user_model().objects.create_user(email=email) # Set user fields provided user.set_password(password) user.first_name = first_name user.last_name = last_name user.username = username user.is_verified = True send_multi_format_email('welcome_email', { 'email': user.email, }, target_email=user.email) user.save() for user in User.objects.all(): Token.objects.get_or_create(user=user) token, created = Token.objects.get_or_create(user=user) return Response({'token': token.key}, status=status.HTTP_200_OK) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): serializer = self.serializer_class(data=request.data) if serializer.is_valid(): email = serializer.data.get('email') password = serializer.data.get('password') first_name = serializer.data.get('first_name') last_name = serializer.data.get('last_name') user, response = self.get_user(email, serializer) if response is not None: return response # Set user fields provided user.set_password(password) user.first_name = first_name user.last_name = last_name if not must_validate_email: user.is_verified = True send_multi_format_email('welcome_email', {'email': user.email, }, target_email=user.email, request=request) self.save(user, serializer) if must_validate_email: # Create and associate signup code ipaddr = self.request.META.get('REMOTE_ADDR', '0.0.0.0') signup_code = SignupCode.objects.create_signup_code(user, ipaddr) signup_code.send_signup_email(request=request) content = { 'email': email, 'first_name': first_name, 'last_name': last_name, **self.get_response_extra(user), } if not must_validate_email: content.update(token=get_auth_token(user)) return Response(content, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): serializer = self.serializer_class(data=request.data) # check unique user name user_name = request.data['user_name'] UserModel = get_user_model() try: existing_user = UserModel.objects.get(user_name=user_name) # print("checking %s exists? %s" % (user_name, existing_user)) content = {'detail': _('User name already exist, try a different one.')} return Response(content, status=status.HTTP_400_BAD_REQUEST) except: #good to go pass if serializer.is_valid(): email = serializer.data['email'] password = serializer.data['password'] first_name = serializer.data['first_name'] last_name = serializer.data['last_name'] user_name = serializer.data['user_name'] must_validate_email = getattr(settings, "AUTH_EMAIL_VERIFICATION", True) try: user = get_user_model().objects.get(email=email) if user.is_verified: content = {'detail': _('User with this Email address already exists.')} return Response(content, status=status.HTTP_400_BAD_REQUEST) try: # Delete old signup codes signup_code = SignupCode.objects.get(user=user) signup_code.delete() except SignupCode.DoesNotExist: pass except get_user_model().DoesNotExist: user = get_user_model().objects.create_user(email=email) # Set user fields provided user.set_password(password) user.first_name = first_name user.last_name = last_name user.user_name = user_name if not must_validate_email: user.is_verified = True send_multi_format_email('welcome_email', {'email': user.email,}, target_email=user.email) user.save() if must_validate_email: # Create and associate signup code ipaddr = self.request.META.get('REMOTE_ADDR', '0.0.0.0') signup_code = SignupCode.objects.create_signup_code(user, ipaddr) signup_code.send_signup_email() content = {'email': email, 'first_name': first_name, 'last_name': last_name, 'user_name': user_name} return Response(content, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)