def post(self, request, *args, **kwargs): # Getting the data from the request data = json.loads(request.body.decode('utf-8')) user = auth.get_user_model() if GetUser.get_user_by_email(email=data.get('email')) != None: return JsonResponse({'AddUserStatus': False}) # Making the new user object new_user = user.objects.create(first_name=data.get('full_name'), email=data.get('email'), username=self.CreateShortcode(user)) # Setting the password for the new user new_user.set_password(data.get('password')) # Saving the new user new_user.save() # Making the person object and adding the details to the person object new_person = person() new_person.user = new_user new_person.mobile_number = data.get('mobile_number') # Saving the person object new_person.save() # Logging in the new user auth.login(request, new_user) # Returning a response return JsonResponse({'AddUserStatus': True, 'Login': True})
def get(self, request, username, *args, **kwargs): # Checking if the username is empty if not username == '': # Getting the user with the current username user = GetUser.get_user_by_username(username=username) # Checking the user exits with the current username if user == None: # Returning the response with no username return JsonResponse({'PersonStatus': False}) primary_user = None if request.user.username == username: primary_user = True else: primary_user = False # Querying for the personal details of the user qs = person.objects.filter(user=user) # Checking if query results is equal to one if qs.count() == 1: # Retuning the response with the query results return JsonResponse({ 'Person': PersonSerializer(qs[0]).data, 'PrimaryUser': primary_user, 'PersonStatus': True }) else: # Returning the response with no user return JsonResponse({ 'PrimaryUser': primary_user, 'PersonStatus': False }) else: # Retuning the response with no user return JsonResponse({'PersonStatus': False})
def get(self, request, *args, **kwargs): # Getting the data from the request if request.user.is_authenticated(): subscription = SubscriptionController.GetSubscriptions( User=request.user) if subscription.count() > 0: # Getting the topics from the interests reviewers = subscription.values_list('reviewer', flat=True) subscription = [] # Looping through the topics received for reveiwer_id in reviewers: # Getting the topic from ID user = GetUser.get_user_by_id(ID=reveiwer_id) # Checking if the topic is empty if user is not None: # Appending the topic name to the interest subscription.append({ 'name': user.first_name, 'username': user.username }) else: subscription = [] return JsonResponse({ 'SubscriptionList': subscription, 'UserAuthenticated': True }) return JsonResponse({'UserAuthenticated': False})
def post(self, request, username, *args, **kwargs): # Getting the data from the request data = json.loads(request.body.decode('utf-8')) print(data) if request.user.is_authenticated(): if data.get('update_subscription_status'): if SubscriptionController.AddSubscription( Observer=request.user, Reviewer=GetUser.get_user_by_username(username=username)): return JsonResponse( { 'SubscriptionStatus': True, 'UpdateSubscriptionStatus': True, 'UserAuthenticated': True }) else: qs = SubscriptionController.GetSubscription( Observer=request.user, Reviewer=GetUser.get_user_by_username(username=username)) if qs.count() == 1: return JsonResponse( { 'SubscriptionStatus': True, 'UpdateSubscriptionStatus': False, 'UserAuthenticated': True }) else: return JsonResponse( { 'SubscriptionStatus': False, 'UpdateSubscriptionStatus': False, 'UserAuthenticated': True }) else: SubscriptionController.DeleteSubscription( Observer=request.user, Reviewer=GetUser.get_user_by_username(username=username)) return JsonResponse( { 'SubscriptionStatus': False, 'UpdateSubscriptionStatus': True, 'UserAuthenticated': True })
def get(self, request, username, *args, **kwargs): # Getting the data from the request if request.user.is_authenticated(): if request.user.username == username: return JsonResponse({'PrimaryUser': True, 'SubscriptionStatus': False, 'UserAuthenticated': True}) qs=SubscriptionController.GetSubscription( Observer=request.user, Reviewer=GetUser.get_user_by_username(username=username)) if qs.count() == 1: return JsonResponse({'SubscriptionStatus': True, 'UserAuthenticated': True}) else: return JsonResponse({'SubscriptionStatus': False, 'UserAuthenticated': True}) return JsonResponse({'UserAuthenticated': False})
def post(self, request, *args, **kwargs): # Getting the data from the request data = json.loads(request.body.decode('utf-8')) print(data) user_list = [] # Getting the users from the controller and appending it to the list for item in GetUser.get_users(Name=data.get('search_text')): user_list.append(item) topic_list = [] # Getting the topics from the controller and appending it to the list for item in TopicController.GetTopics(Name=data.get('search_text')): topic_list.append(item) return JsonResponse({ 'SearchingFor': data.get('search_text'), 'TopicList': topic_list, 'UserList': user_list })
def post(self, request, username, *args, **kwargs): try: # Getting the data from the request data = json.loads(request.body.decode('utf-8')) except: data = {} # Checking if the username is empty if request.user.username == username: # Querying for the user user = GetUser.get_user_by_username(username=username) # Checking if the query results is empty if user == None: # Returning the user status return JsonResponse({'UpdateStatus': False}) # Querying for the person qs = person.objects.filter(user=user) # Checking if the query results is equal to one if qs.count() == 1: # Updating the user data with the data from the request if data.get('full_name') != None: user.first_name = data.get('full_name') if data.get('email') != None: if GetUser.get_user_by_email( email=data.get('email')) != None: return JsonResponse({'UpdateStatus': False}) user.email = data.get('email') print('Email Changed.') if data.get('password') != None: user.set_password(data.get('password')) print('Password Changed.') # Saving the user details user.save() current_person = user.person print(current_person) if data.get('mobile_number') != None: current_person.mobile_number = data.get('mobile_number') if data.get('bio') != None: current_person.bio = data.get('bio') # Procedure for storing images if request.FILES.get('pic') != None: pic = request.FILES.get('pic') fs = FileSystemStorage() filename = fs.save( 'profile/' + str(uuid.uuid4()) + '.' + pic.name.split('.')[-1], pic) uploaded_file_url = fs.url(filename) current_person.pic = uploaded_file_url[7:] # Saving the person details current_person.save() # Returning the response with update status of the user return JsonResponse({'UpdateStatus': True}) else: # Returning the response with unable update status of the user return JsonResponse({'UpdateStatus': False}) else: # Returning the response with no user return JsonResponse({'UpdateStatus': False})
def get(self, request, username, *args, **kwargs): # Checking if the user is authenticated if request.user.is_authenticated(): # Returning the response with reviews for the current logged in user return JsonResponse({'ReviewsList': ReviewController.GetReviewsByUser(User=GetUser.get_user_by_username(username=username)), 'MaxRating': 5, 'User': UserSerializer(request.user).data, 'PrimaryUser': True}) else: # Returning the response with no reviews return JsonResponse({'ReviewsList': ReviewController.GetReviewsByUser(User=GetUser.get_user_by_username(username=username)), 'MaxRating': 5, 'User': UserSerializer(request.user).data, 'PrimaryUser': False})