def put(self, request, format=None): code = get_value_or_404(request.data, 'code') redirect_uri = get_value_or_404(request.data, 'redirect_uri') try: token = utils.get_or_create_user_from_linkedin(code=code, redirect_uri=redirect_uri) context = {'token': token} return Response(context, status=status.HTTP_200_OK) except ValueError as ve: errors = create_error_object(str(ve)) return Response(errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, format=None): print(request.data) google_data = get_value_or_404(request.data, 'google_data') try: token = utils.get_or_create_user_from_google(data=google_data) context = {'token': token} return Response(context, status=status.HTTP_200_OK) except ValueError as ve: errors = create_error_object(str(ve)) return Response(errors, status=status.HTTP_400_BAD_REQUEST)
def get_cities(request): try: obj = models.City.get_cities() cities = serializers.CitySerializer(obj['cities'], many=True).data context = {'cities': cities, 'count': obj['count']} return Response(context, status=status.HTTP_200_OK) except ValueError as ve: errors = create_error_object(str(ve)) return Response(errors, status=status.HTTP_400_BAD_REQUEST) except Exception as e: errors = str(e) return Response(errors, status=status.HTTP_400_BAD_REQUEST)
def post_newsletter_subscriber(request): email = get_value_or_404(request.data, 'email') try: models.NewsletterSubscriber.create(email=email) context = {'message': 'success'} return Response(context, status=status.HTTP_200_OK) except ValueError as ve: errors = create_error_object(str(ve)) return Response(errors, status=status.HTTP_400_BAD_REQUEST) except Exception as e: errors = str(e) return Response(errors, status=status.HTTP_400_BAD_REQUEST)
def get_otp(request): try: email = get_value_or_default(request.GET, 'email', None) phone = get_value_or_default(request.GET, 'phone', None) context = utils.get_otp(email=email, phone=phone) return Response(context, status=status.HTTP_200_OK) except ValueError as ve: errors = create_error_object(str(ve)) return Response(errors, status=status.HTTP_400_BAD_REQUEST) except Exception as e: errors = str(e) return Response(errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request, format=None): email = get_value_or_default(request.GET, 'email', None) phone = get_value_or_default(request.GET, 'phone') try: context = utils.auth_verification(email=email, phone=phone) return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: errors = create_error_object(str(ve)) return Response(errors, status=status.HTTP_400_BAD_REQUEST) except Exception as e: errors = str(e) return Response(errors, status=status.HTTP_400_BAD_REQUEST)
def post_contact_query(request): email = get_value_or_404(request.data, 'email') name = get_value_or_404(request.data, 'name') subject = get_value_or_404(request.data, 'subject') message = get_value_or_404(request.data, 'message') try: models.ContactQuery.create(email=email, name=name, subject=subject, message=message) context = {'message': 'success'} return Response(context, status=status.HTTP_200_OK) except ValueError as ve: errors = create_error_object(str(ve)) return Response(errors, status=status.HTTP_400_BAD_REQUEST) except Exception as e: errors = str(e) return Response(errors, status=status.HTTP_400_BAD_REQUEST)
def linkedin_auth_mobile(request): user_id = get_value_or_404(request.data, 'user_id') email = get_value_or_404(request.data, 'email') first_name = get_value_or_404(request.data, 'first_name') last_name = get_value_or_404(request.data, 'last_name') profile_image = get_value_or_default(request.data, 'profile_image', None) try: token = utils.get_or_create_user_from_linkedin_mob( user_id=user_id, email=email, first_name=first_name, last_name=last_name, profile_image=profile_image) context = {'token': token} return Response(context, status=status.HTTP_200_OK) except ValueError as ve: errors = create_error_object(str(ve)) return Response(errors, status=status.HTTP_400_BAD_REQUEST) except Exception as e: errors = str(e) return Response(errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, format=None): email = get_value_or_404(request.data, 'email') password1 = get_value_or_404(request.data, 'password1') password2 = get_value_or_404(request.data, 'password2') phone = get_value_or_default(request.data, 'phone') first_name = get_value_or_default(request.data, 'first_name', None) last_name = get_value_or_default(request.data, 'last_name', None) username = get_value_or_default(request.data, 'username', None) otp = get_value_or_default(request.data, 'otp', None) try: context = utils.create_user_from_email(username=username, email=email, first_name=first_name, last_name=last_name, password1=password1, password2=password2, otp=otp, phone=phone) return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: errors = create_error_object(str(ve)) return Response(errors, status=status.HTTP_400_BAD_REQUEST) except Exception as e: errors = str(e) return Response(errors, status=status.HTTP_400_BAD_REQUEST)