def get_last_opened_info(request): try: start = datetime.create_datetime_from_iso(get_value_or_default(request.data, 'start', None), 'Asia/Kolkata') end = datetime.create_datetime_from_iso(get_value_or_default(request.data, 'end', None), 'Asia/Kolkata') count = analytics.get_last_opened_info(start=start, end=end) context = {"count": count} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def post(self, request): email = get_value_or_default(request.data, 'email', None) phone = get_value_or_default(request.data, 'phone', None) password = get_value_or_404(request.data, 'password') try: context = utils.auth_signin(email=email, phone=phone, password=password) return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), 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 forgot_password(request): try: email_otp = get_value_or_default(request.data, 'email_otp', None) phone_otp = get_value_or_default(request.data, 'phone_otp', None) password1 = get_value_or_404(request.data, 'password1') password2 = get_value_or_404(request.data, 'password2') utils.forgot_password(user=request.user, password1=password1, password2=password2, email_otp=email_otp, phone_otp=phone_otp) context = {'message': 'Password successfully changed'} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def put(self, request, format=None): phone = get_value_or_404(request.data, 'phone_number') password1 = get_value_or_404(request.data, 'password1') password2 = get_value_or_404(request.data, 'password2') email = get_value_or_default(request.data, 'email', None) 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') try: context = utils.create_user_from_phone(phone=phone, username=username, email=email, first_name=first_name, last_name=last_name, password1=password1, password2=password2, otp=otp) return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def add_message(request, chat_id): try: message = get_value_or_404(request.data, 'message') reference_type = get_value_or_default(request.data, 'reference_type', None) reference_id = get_value_or_default(request.data, 'reference_id', None) data = models.Chat.add_message(chat_id=chat_id, from_user=request.user, message=message, reference_id=reference_id, reference_type=reference_type) message = serializers.MessageSerializer(data['message']).data print(message) context = { 'message': message, 'total_messages_count': data['message'].message_number } return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def get_chat_list(request): try: offset = int(get_value_or_default(request.GET, 'offset', 0)) data = models.Chat.get_chats(user=request.user, offset=offset) chats = serializers.ChatMiniSerializer(data['chats'], many=True, context={ 'user': request.user }).data context = {'chats': chats, 'count': data['count']} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), 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 registration(request): try: operation = get_value_or_404(request.data, 'operation') phone = get_value_or_404(request.data, 'phone') OTP = get_value_or_default(request.data, 'OTP', None) email = get_value_or_default(request.data, 'email', None) password = get_value_or_default(request.data, 'password', None) 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) context = utils.registration(operation=operation, phone=phone, OTP=OTP, first_name=first_name, last_name=last_name, email=email, password=password) return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def put(self, request, format=None): password1 = get_value_or_404(request.data, 'password1') password2 = get_value_or_404(request.data, 'password2') email = get_value_or_default(request.data, 'email', None) 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) phone_otp = get_value_or_default(request.data, 'phone_otp', None) email_otp = get_value_or_default(request.data, 'email_otp', None) try: context = utils.auth_signup(username=username, email=email, phone=phone, first_name=first_name, last_name=last_name, password1=password1, password2=password2, phone_otp=phone_otp, email_otp=email_otp) 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)