コード例 #1
0
 def get(self, request):
     if check_authentication(request):
         user = get_user(request)
         try:
             currentIndex = int(request.GET.get('currentIndex'))
         except ValueError:
             currentIndex = 0
         noti_type = ['status-a', 'status-b']
         notis = Notification.objects.filter(
             user=user, noti_type__in=noti_type).order_by(
                 '-time')[currentIndex:currentIndex + 10]
         unread_noti = len(
             Notification.objects.filter(user=user,
                                         read=False,
                                         noti_type__in=noti_type))
         data = {
             'data': notification_serialize(notis),
             'unread': unread_noti,
             'status_code': 'ok'
         }
         response = JsonResponse(data)
         set_response_header(response)
         return response
     else:
         data = {'status_code': 'error'}
         response = JsonResponse(data)
         set_response_header(response)
         return response
コード例 #2
0
 def post(self, request):
     if check_authentication(request):
         user = get_user(request)
         post_data = request.POST
         fullname = post_data.get('fullname')
         born_year = post_data.get('bornYear')
         image_id = post_data.get('imageId')
         country_code = post_data.get('countryCode')
         sex = post_data.get('sex')
         if user and fullname and born_year and image_id and sex and country_code:
             image = Image.objects.get(pk = image_id)
             try:
                 NetworkAccount.objects.create(user = user, fullname = fullname, birthYear = born_year, nationality = country_code, sex = sex, profile_picture = image)
             except IntegrityError:
                 data = {
                     'status_code': 'error'
                 }
                 response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
                 return response
             data = {
                 'status_code': 'ok'
             }
             response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
             return response
         data = {
             'status_code': 'error'
         }
         response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
         set_response_header(response)
         return response
コード例 #3
0
    def post(self, request):
        if check_authentication(request):
            # the person who upload image
            user = get_user(request)
            
            # the real file
            upload_file = request.FILES['image']

            # the type of image
            image_type = request.POST.get('imageType')
            if image_type and image_type != '':
                pass
            else:
                image_type = 'post_status'

            pillow_image = handle_image_pillow(upload_file)
            final_image = InMemoryUploadedFile(pillow_image, None, 'base.jpg', 'image/jpeg', pillow_image.tell, None)
            final_pillow_image = Image.open(final_image)

            img_model = ImageModel.objects.create(user = user, image_type = image_type, image_width = final_pillow_image.width, image_height = final_pillow_image.height, image_id = uuid.uuid4().hex)
            img_model.image = final_image
            img_model.save()
            data = {
                    'status_type': 'ok',
                    'photo_id': img_model.id,
                    'photo_url': img_model.image.url
                }
            response = JsonResponse(data)
            set_response_header(response)
            return response
        else:
            response = JsonResponse({'status_type':'error'})
            set_response_header(response)
            return response
コード例 #4
0
 def get(self, request):
     user = NetworkAccount.objects.get(network_id = request.COOKIES.get('nu'))
     timeout = time.time() + 50 # 10 seconds
     while True:
         time.sleep(2)
         if time.time() > timeout:
             break
         m = NetworkChatUser.objects.filter(user = user, fetch = False)
         for i in m:
             i.fetch = True
             i.read = True
             i.save()
         if len(m) > 0:
             data = {
             'data': pull_message_serialize(m),
             'status_code': 'ok',
             'on': True
             }
             response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
             set_response_header(response)
             return response
     data = {
     'status_code': 'ok',
     'on': False
     }
     response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
     set_response_header(response)
     return response
コード例 #5
0
 def get(self, request):
     action = request.GET.get('action')
     # return all topics that match key search
     if action == 'topic':
         key = request.GET.get('search')
         result = NetworkChatroomTopic.objects.filter(name__icontains = key)[0:10]
         data = {
         'status_code': 'ok',
         'data': topic_serialize(result)
         }
     # return all rooms of this topic
     elif action == 'topic_room':
         topic_url = request.GET.get('topic_url')
         try:
             topic = NetworkChatroomTopic.objects.get(url = topic_url)
             chatroom = NetworkChatroom.objects.filter(tag_topic = topic)
             data = {
             'status_code': 'ok',
             'topic': topic_serialize(topic),
             'data': network_chatroom_serialize(chatroom)
             }
         except:
             data = {
             'status_code': 'error'
             }
     else:
         data = {
         'status_code': 'error'
         }
     response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
     set_response_header(response)
     return response
コード例 #6
0
 def post(self, request):
     nu = request.COOKIES.get('nu')
     text = request.POST.get('text')
     frame_id = request.POST.get('frameId')
     try:
         user = NetworkAccount.objects.get(network_id = nu)
         frame = NetworkChatFrame.objects.get(id = int(frame_id))
     except:
         data = {
         'status_code': 'error'
         }
         response = HttpResponse('while(1);'+ json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
         set_response_header(response)
         return response
     if text and len(text) != 0:
         m = NetworkMessage.objects.create(user_send = user, chat_frame = frame, text = text)
         users_of_frame = frame.users.all()
         for i in users_of_frame:
             if i != user:
                 a = NetworkChatUser.objects.get(user = i, frame = frame)
                 a.read = False
                 a.fetch = False
                 a.save()
                 NetworkMessageInfo.objects.create(user = i, network_message = m, read = False, fetch = False)
     data = {
     'status_code': 'ok',
     'mess': network_message_serialize(m)
     }
     response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript;charset=utf-8')
     set_response_header(response)
     return response
コード例 #7
0
 def get(self, request):
     frame_id = request.GET.get('frameId')
     current_index = request.GET.get('cIndex') if request.GET.get('cIndex') else 0
     nu = request.COOKIES.get('nu')
     if frame_id and current_index and nu:
         try:
             frame_id = int(frame_id)
             current_index = int(current_index)
         except:
             data = {
                 'status_code': 'error'
             }
             response = JsonResponse(data, content_type = "application/json")
             set_response_header(response)
             return response
         network_frame = NetworkChatFrame.objects.get(id = frame_id)
         user_send = NetworkAccount.objects.get(network_id = nu)
         if user_send in network_frame.users.all() and current_index != -1:
             m = NetworkMessage.objects.filter(chat_frame = network_frame).order_by('-create_time')[current_index:current_index+10]
         elif user_send in network_frame.users.all() and current_index == -1:
             m = NetworkMessage.objects.filter(chat_frame = network_frame, network_networkmessageinfo_network_message__fetch = False)
         # line next and for loop to reset the message read and fetch
         m_serialize = network_message_serialize(m)
         nmf = NetworkMessageInfo.objects.filter(user = user_send).filter(network_message_id__in = list(m.values_list('id', flat=True)))
         for i in nmf:
             i.fetch = True
             i.read = True
             i.save()
         data = {
         'status_code': 'ok',
         'messages': m_serialize
         }
         response = JsonResponse(data, content_type = "application/json")
         set_response_header(response)
         return response
コード例 #8
0
 def get(self, request):
     # this is section which is all or sport or language to filter
     tab_section = request.GET.get('tab_section')
     # the total number of current to fetch continuos
     number_offset = request.GET.get('number_offset')
     if tab_section and number_offset:
         try:
             number_offset = int(number_offset)
         except:
             number_offset = 0
         if tab_section == 'all':
             t = NetworkGoal.objects.filter(goal = 'sport')
             a = NetworkGoal.objects.filter(goal = 'language')
             data = []
             data.append(network_serialize(t, 'sport'))
             data.append(network_serialize(a, 'language'))
             data_response = {
             'status_code': 'ok',
             'data': data
             }
             response = JsonResponse(data_response)
             set_response_header(response)
             return response
     data_response = {
     'status_code': 'error',
     }
     response = JsonResponse(data_response)
     set_response_header(response)
     return response
コード例 #9
0
 def get(self, request):
     cookie_token = request.COOKIES.get('u')
     user_id = request.COOKIES.get('user')
     user_auto_id = request.COOKIES.get('a')
     if cookie_token and user_id and user_auto_id:
         if check_cookie_hash(user_id, cookie_token):
             user = User.objects.get(user_id = user_id,id = user_auto_id)
             info = Info.objects.get(user = user)
             data_response = {
                 'status': 'ok',
                 'user': {
                     'user_id': user.user_id.hex,
                     'email': user.email,
                     'fullname': user.fullname,
                     'profilepic': info.profile_pic.url if info.profile_pic else '',
                     'backgroundpic': info.background_pic.url if info.background_pic else '',
                     'newfeed': newfeed_serialize(user)
                 }
             }
             set_online_time(user)
             response = JsonResponse(data_response)
             set_response_header(response) 
             return response
     response = JsonResponse({'status':'no'})
     set_response_header(response)
     return response
コード例 #10
0
 def get(self, request):
     if check_authentication(request):
         user = get_user(request)
         c_index = int(
             request.GET.get('cIndex')) if request.GET.get('cIndex') else 0
         try:
             frame_id = request.GET.get('frameId')
             frame_id = int(frame_id)
         except:
             response_error()
         chat_frame = MessageFrame.objects.get(pk=frame_id)
         if user in chat_frame.users.all() and c_index != -1:
             m = Message.objects.filter(chat_frame=chat_frame).order_by(
                 '-create_time')[c_index:c_index + 10]
         elif user in chat_frame.users.all():
             m = Message.objects.filter(
                 chat_frame=chat_frame,
                 message_messagereadinfo_message__fetch=False)
             # here to reset the fetch in messageReadInfo
         mess = message_serialize(m)
         # line next and for loop to reset the message read and fetch
         mri = MessageReadInfo.objects.filter(user=user).filter(
             message_id__in=list(m.values_list('id', flat=True)))
         for i in mri:
             i.fetch = True
             i.save()
         data = {'status_code': 'ok', 'mess': mess}
         response = HttpResponse(
             'while(1);' + json.dumps(data),
             content_type='application/x-javascript;charset=utf-8')
         set_response_header(response)
         return response
コード例 #11
0
 def post(self, request):
     response = JsonResponse({'status_code': 'ok'})
     response.delete_cookie('a')
     response.delete_cookie('user')
     response.delete_cookie('u')
     response.delete_cookie('au')
     set_response_header(response)
     return response
コード例 #12
0
 def get(self, request):
     if check_authentication(request):
         user = get_user(request)
         past_5_days = timezone.now() - timedelta(days=5)
         #friend = Friend.objects.filter(user = user, friend__onlinetime__time__gte = past_5_days)
         friend = Friend.objects.filter(user=user)
         data = {'friends': friend_serialize(friend), 'status_code': 'ok'}
         response = JsonResponse(data)
         set_response_header(response)
         return response
コード例 #13
0
 def get(self, request):
     feedPk = request.GET.get('feedPk')
     totalFetch = int(request.GET.get('totalFetch')) if request.GET.get(
         'totalFetch') else 10
     currentIndex = int(request.GET.get('currentIndex'))
     status = Status.objects.get(pk=int(feedPk))
     comments = status_comment_serialize(status, totalFetch, currentIndex)
     response = JsonResponse({'comments': comments, 'status_type': 'ok'})
     set_response_header(response)
     return response
コード例 #14
0
 def get(self, request):
     # search for user
     q = request.GET.get('q')
     user = User.objects.filter(fullname__icontains = q)[0:10]
     data = {
         'data': header_search(user),
         'status_code': 'ok'
     }
     response = JsonResponse(data)
     set_response_header(response)
     return response
コード例 #15
0
 def get(self, request):
     user_id = request.GET.get('id')
     try:
         user = User.objects.get(user_id__exact=user_id)
     except User.DoesNotExist:
         response = JsonResponse({'status_code': 'error'})
         set_response_header(response)
         return response
     data = {'data': basic_info(user), 'status_code': 'ok'}
     response = JsonResponse(data)
     set_response_header(response)
     return response
コード例 #16
0
    def post(self, request):
        if check_authentication(request, True):
            user = get_user(request)
            data = request.POST
            post = PostModel.objects.create(user = user, text = data.get('textarea'))
            # sale items 
            post.sale_item = data.get('saleItem')
            post.save()
            # for friend
            fr_id = data.getlist('friendIds')
            if fr_id:
                pf = PostFriendTag.objects.create(post = post)
                for i in fr_id:
                    t = User.objects.get(user_id = i)
                    pf.friend.add(t)
                    noti = Notification.objects.create(user = t, noti_type = 'post-a')
                    PostANotification.objects.create(noti = noti, post = post)
            # for images
            images_id = data.getlist('images_id')
            for i in images_id:
                img = ImageModel.objects.get(pk = int(i))
                img.image_type = 'post-newfeed'
                img.user = user
                img.has_saved = True
                img.save()
                post.has_link_image = True
                post.image.add(img)
                post.save()
            status = Status.objects.create(verb = 'post', privacy = 'friend', post = post, user = user)
            if request.POST.get('verb') == 'sale':
                status.verb = 'sale'
                status.save()

            #for reactions
            use_default_reaction = True
            use_custom_reaction = False
            reaction = data.get('reaction')
            if reaction.strip() and len(reaction.strip()) < 30:
                use_default_reaction = False
                use_custom_reaction = True
                status.use_default_reaction = use_default_reaction
                status.use_custom_reaction = use_custom_reaction
                status.save()
                sr = StatusReaction.objects.create(status = status, reactionName = reaction, reactionType = 'a')
            else:
                sr = StatusReaction.objects.create(status = status, reactionName = 'like', reactionType = '1', icon = 'heart', vote = 0)
            response = JsonResponse({'data': status_serialize(status, user), 'status_code':'ok'})
            set_response_header(response)
            return response
        else:
            response = JsonResponse({'status_code':'error'})
            set_response_header(response)
            return response
コード例 #17
0
 def get(self, request):
     network_account = get_network_account(request)
     if network_account:
         goals = NetworkGoal.objects.filter(user_account = network_account)
         goal_serialize = network_goal_serialize(goals)
         data = {
             'status_code': 'ok',
             'goal': goal_serialize
         }
         response = HttpResponse('while(1);' + json.dumps(data), content_type = "application/x-javascript; charset=utf-8")
         set_response_header(response)
         return response
コード例 #18
0
 def get(self, request):
     if check_authentication(request):
         user_request = get_user(request)
         try:
             total = int(request.GET.get('total'))
         except:
             response_error()
         target = request.GET.get('target')
         user_receive_id = request.GET.getlist('listId[]')
         #now it is just 1 item in user_receive_id
         user_receive_id = user_receive_id[0]
         try:
             user_receive = User.objects.get(user_id=user_receive_id)
         except User.DoesNotExist:
             response_error()
         if total == 2 and target == 'user':
             m = MessageFrame.objects.filter(message_type='user').filter(
                 users=user_request).filter(users=user_receive)
             if len(m) == 1 and len(m[0].users.all()) == 2:
                 data = {
                     'frame_id':
                     m[0].id,
                     'status_code':
                     'ok',
                     'users': [
                         serialize_user_basic(user_request),
                         serialize_user_basic(user_receive)
                     ]
                 }
             elif len(m) == 0:
                 m = MessageFrame.objects.create(message_type='user')
                 m.users.add(user_request)
                 m.users.add(user_receive)
                 m.save()
                 data = {
                     'frame_id':
                     m.id,
                     'status_code':
                     'ok',
                     'users': [
                         serialize_user_basic(user_request),
                         serialize_user_basic(user_receive)
                     ]
                 }
             else:
                 data = {'status_code': 'error'}
         else:
             data = {'status_code': 'error'}
         response = HttpResponse('while(1);' + json.dumps(data),
                                 content_type='text/javascript')
         set_response_header(response)
         return response
コード例 #19
0
    def post(self, request):
        if check_authentication(request, True):
            user = get_user(request)
            data = request.POST
            try:
                status = Status.objects.get(
                    pk__exact=int(request.POST.get('feed_pk')))
            except Status.DoesNotExist:
                return JsonResponse({'status_type': 'error'})
            sc = StatusComment.objects.create(user=user,
                                              status=status,
                                              comment=request.POST.get('text'))
            self.define_plustag(status, user, request.POST.get('text'))
            if status.user and user != status.user:
                noti = Notification.objects.create(user=status.user,
                                                   noti_type='status-b')
                StatusBNotification.objects.create(noti=noti,
                                                   status=status,
                                                   statuscomment=sc)
            # friendship

            #if status.user:
            #    try:
            #        friend = status.user
            #        x = Friend.objects.get(user = user, friend = friend)
            #        try:
            #            t = FriendRelationship.objects.get(user = user, friend = x)
            #        except FriendRelationship.DoesNotExist:
            #             t = FriendRelationship.objects.create(user = user, friend = x)
            #        finally:
            #            try:
            #                a = FriendHeart.objects.get(user = user, friend = friend, friendrelationship = t, source = 'status',reason = 'comment',status = status)
            #            except FriendHeart.DoesNotExist:
            #                a = FriendHeart.objects.create(user = user, friend = friend, friendrelationship = t, source = 'status',reason = 'comment',status = status)
            #                a.heart = random.randint(1,2)
            #                t.friend_heart += a.heart
            #                a.save()
            #                t.save()
            #    except Friend.DoesNotExist:
            #        pass
            comment = status_comment_serialize(status, 1)
            response = JsonResponse({
                'comments':
                comment,
                'plustags':
                status_plustag_serialize(status),
                'status_type':
                'ok'
            })
            set_response_header(response)
            return response
コード例 #20
0
 def get(self, request):
     nu = request.COOKIES.get('nu')
     user = NetworkAccount.objects.get(network_id = nu)
     a = NetworkChatFrame.objects.filter(users = user, frame_type = 'goal')
     all_frames = []
     for i in a:
         all_frames.append(network_chat_frame_serialize(i))
     data_response = {
     'status_code': 'ok',
     'all_frames': all_frames
     }
     response = HttpResponse('while(1);'+ json.dumps(data_response), content_type = 'application/x-javascript; charset=utf-8')
     set_response_header(response)
     return response
コード例 #21
0
 def get(self, request):
     if check_authentication(request):
         user = get_user(request)
         name = request.GET.get('name')
         friendIds = request.GET.getlist('friendIds')
         if name:
             friends = Friend.objects.filter(
                 user=user, friend__fullname__icontains=name).exclude(
                     friend__user_id__in=friendIds)
         else:
             friends = []
         data = friend_serialize(friends)
         response = JsonResponse({'status_code': 'ok', 'friends': data})
         set_response_header(response)
         return response
コード例 #22
0
def handle_image_pillow(image):
    try:
        image = Image.open(image)
    except OSError:
        response = JsonResponse({'status_type':'error'})
        set_response_header(response)
        return response
    r_w, r_h = image_resize(530, 530, image.width, image.height)
    if image.mode != "RGB":
        image = image.convert("RGB")
    image = image.resize((math.floor(r_w), math.floor(r_h)), Image.ANTIALIAS)

    image_buffer = BytesIO()
    image.save(fp = image_buffer, format = 'jpeg', optimize = True, quality = 70, progressive = True)
    image_buffer_val = image_buffer.getvalue()
    return ContentFile(image_buffer_val)
コード例 #23
0
 def get(self, request):
     network_id = request.GET.get('network_id')
     try:
         user = NetworkAccount.objects.get(network_id = network_id)
     except NetworkAccount.DoesNotExist:
         data = {
         'status_code': 'error'
         }
         response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/json')
         set_response_header(response)
         return response
     data = {
     'status_code': 'ok',
     'user': network_account_serialize(user),
     }
     response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/json')
     set_response_header(response)
     return response
コード例 #24
0
 def post(self, request):
     if check_authentication(request):
         user = get_user(request)
         try:
             pk = int(request.POST.get('plustagPk'))
         except:
             response = JsonResponse({'status_code': 'error'})
             set_response_header(response)
             return response
         plustag = Plustag.objects.get(pk=pk)
         if plustag.user_send_plus == user:
             data = {
                 'data': plustag_vote_serialize(plustag),
                 'status_code': 'ok'
             }
             response = JsonResponse(data)
             set_response_header(response)
             return response
         else:
             try:
                 pv = PlustagVoteModel.objects.create(plustag=plustag,
                                                      user_vote=user,
                                                      been_vote=True)
                 plustag.votes += 1
                 plustag.save()
                 data = {
                     'data': plustag_vote_serialize(plustag),
                     'status_code': 'ok'
                 }
                 response = JsonResponse(data)
                 set_response_header(response)
                 return response
             except IntegrityError:
                 pv = PlustagVoteModel.objects.get(plustag=plustag,
                                                   user_vote=user)
                 if pv.been_vote == True:
                     pv.been_vote = False
                     pv.save()
                     plustag.votes -= 1
                     plustag.save()
                 else:
                     pv.been_vote = True
                     pv.save()
                     plustag.votes += 1
                     plustag.save()
                 data = {
                     'data': plustag_vote_serialize(plustag),
                     'status_code': 'ok'
                 }
                 response = JsonResponse(data)
                 set_response_header(response)
                 return response
コード例 #25
0
 def post(self, request):
     if check_authentication(request):
         user = get_user(request)
         try:
             a = OnlineTime.objects.create(user=user)
         except IntegrityError:
             a = OnlineTime.objects.get(user=user)
             a.time = timezone.now()
             a.save()
             data = {
                 'status_code': 'ok',
             }
             response = HttpResponse('while(1);' + json.dumps(data),
                                     content_type='text/javascript')
             set_response_header(response)
             return response
     else:
         response = JsonResponse({'status_code': 'error'})
         set_response_header(response)
         return response
コード例 #26
0
    def post(self, request):
        tab_id = request.GET.get('tab_id')

        tab_name = request.POST.get('tab_name')

        # action type is delete user or add user
        action_type = request.POST.get('action_type')

        if check_authentication(request):
            user = get_user(request)
            if action_type == 'create_tab':
                try:
                    a = FollowTimeline.objects.get(name=tab_name, user=user)
                    data = {'status_code': 'error'}
                except FollowTimeline.DoesNotExist:
                    a = FollowTimeline.objects.create(name=tab_name, user=user)
                    data = {'status_code': 'ok'}
                response = JsonResponse(data)
                set_response_header(response)
                return response
コード例 #27
0
 def get(self, request):
     if check_authentication(request):
         user = get_user(request)
         timeout = time.time() + 45  # 3 seconds
         while True:
             time.sleep(2)
             if time.time() > timeout:
                 break
             m = MessageUserInfo.objects.filter(user=user, fetch=False)
             if len(m) > 0:
                 data = {
                     'data': pollmessage_serialize(m),
                     'status_code': 'ok',
                     'on': True
                 }
                 response = HttpResponse(
                     'while(1);' + json.dumps(data),
                     content_type='application/x-javascript; charset=utf-8')
                 set_response_header(response)
                 return response
         data = {'status_code': 'ok', 'on': False}
         response = HttpResponse(
             'while(1);' + json.dumps(data),
             content_type='application/x-javascript; charset=utf-8')
         set_response_header(response)
         return response
     data = {'status_code': 'error'}
     response = HttpResponse(
         'while(1);' + json.dumps(data),
         content_type='application/x-javascript; charset=utf-8')
     set_response_header(response)
     return response
コード例 #28
0
 def post(self, request):
     nu = request.COOKIES.get('nu')
     network_account = NetworkAccount.objects.get(network_id = nu)
     action = request.POST.get('action')
     if action == 'create_topic':
         topic_name = request.POST.get('topic')
         topic_description = request.POST.get('topic_description')
         if topic_name != '' and topic_description != '':
             topic_url = '-'.join(topic_name.split())
             try:
                 a = NetworkChatroomTopic.objects.get(url__iexact = topic_url)
                 data = {
                 'status_code': 'duplicate'
                 }
                 response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
                 set_response_header(response)
                 return response
             except NetworkChatroomTopic.DoesNotExist:
                 a = NetworkChatroomTopic.objects.create(name = topic_name, description = topic_description, user = network_account, url = topic_url)
                 data = {
                 'status_code': 'ok',
                 'topic_name': a.url
                 }
                 response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
                 set_response_header(response)
                 return response
     data = {
     'status_code': 'error'
     }
     response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
     set_response_header(response)
     return response
コード例 #29
0
 def post(self, request):
     email = request.POST.get('email')
     password = request.POST.get('password')
     x = authenticate(email=email, password=password)
     if x is not None:
         try:
             user = User.objects.get(id=x.id)
             user.last_login = timezone.now()
             user.save()
         except User.DoesNotExist:
             user = User.objects.create(id=x.id,
                                        email=email,
                                        password=x.password,
                                        fullname=x.fullname)
         response = JsonResponse({'status_code': 200})
         response.set_cookie(key='u',
                             value=self.cookie_hash(user.user_id),
                             max_age=60 * 60 * 24)
         if type(user.user_id) is uuid.UUID:
             response.set_cookie(key='user',
                                 value=user.user_id.hex,
                                 max_age=60 * 60 * 24)
         else:
             response.set_cookie(key='user',
                                 value=user.user_id,
                                 max_age=60 * 60 * 24)
         response.set_cookie(key='a', value=user.id, max_age=60 * 60 * 24)
         token = uuid.uuid4().hex
         try:
             Authentication.objects.create(user=user, token=token)
         except IntegrityError:
             au = Authentication.objects.get(user=user)
             au.token = token
             au.save()
         response.set_cookie(key='au', value=token, max_age=60 * 60 * 24)
         set_response_header(response)
         return response
     response = JsonResponse({'status_code': 401})
     set_response_header(response)
     return response
コード例 #30
0
 def post(self, request):
     if check_authentication(request):
         user_request = get_user(request)
         text = request.POST.get('text')
         frame_id = request.POST.get('frameId')
         try:
             frame_id = int(frame_id)
         except:
             response_error()
         chat_frame = MessageFrame.objects.get(pk=frame_id)
         if text:
             m = Message.objects.create(user_send=user_request,
                                        chat_frame=chat_frame,
                                        text=text)
             # create or get a messageFrameInfo to detect user read or not read
             users_of_chat_frame = chat_frame.users.all()
             for user in users_of_chat_frame:
                 try:
                     a = MessageUserInfo.objects.get(frame=chat_frame,
                                                     user=user)
                 except MessageUserInfo.DoesNotExist:
                     a = MessageUserInfo.objects.create(frame=chat_frame,
                                                        user=user)
                 if user != user_request:
                     a.read = False
                     a.fetch = False
                     a.save()
                     # here to create messagereadInfo for each message
                     mri = MessageReadInfo.objects.create(user=user,
                                                          message=m,
                                                          read=False,
                                                          fetch=False)
         data = {'status_code': 'ok', 'mess': message_serialize(m)}
         response = HttpResponse(
             'while(1);' + json.dumps(data),
             content_type='application/x-javascript;charset=utf-8')
         set_response_header(response)
         return response