Пример #1
0
 def wechat_login(self, uid, nickname, profile_img_url):
     is_new_user = self.bind_account_helper.check_new_user_by_wechat(uid)
     if is_new_user:
         username = self.user_helper.generate_username()
         self.user_helper.register(username, None)
         self.bind_account_helper.bind_new_account(username, "wechat", uid)
         ProfileHelper(username).update_profile(nickname, profile_img_url)
         token = self.user_helper.generate_token(username)
         active = False
     else:
         username, active = self.bind_account_helper.get_username_by_wechat(
             uid)
         ProfileHelper(username).update_profile(nickname, profile_img_url)
         token = self.user_helper.generate_token(username)
     return username, token, active
Пример #2
0
 def __get_profile(self, user_id, anonymous):
     if anonymous:
         profile = None
     elif user_id in self.profile_dict:
         profile = self.profile_dict[user_id]
     else:
         profile = ProfileHelper(user_id).get_profile()
         self.profile_dict[user_id] = profile
     return profile
Пример #3
0
def user_profile_update(request):
    username = request.user.username
    req_data = json.loads(request.body)
    nickname = req_data['nickname'] if 'nickname' in req_data else None
    img_url = req_data['img_url'] if 'img_url' in req_data else None
    error_code = ProfileHelper(username).update_profile(nickname=nickname,
                                                        img_url=img_url)
    res_data = dict(error=error_code)
    return Response(data=res_data, status=status.HTTP_200_OK)
Пример #4
0
def phone_login(request):
    req_data = json.loads(request.body)
    phone_number = req_data['phone']
    password = req_data['password']
    result_tup = PhoneLoginHelper(phone_number).login(password)
    res_data = dict(error=result_tup[0], token=result_tup[1])
    username = result_tup[2]
    profile = ProfileHelper(username).get_profile()
    if profile:
        res_data['profile'] = profile
    return Response(data=res_data, status=status.HTTP_200_OK)
Пример #5
0
 def __get_members_dict(self, classroom_uuid_list):
     members_dict = dict()
     for row in ClassroomMember.objects.filter(
             classroom_uuid__in=classroom_uuid_list, active=True):
         classroom_uuid = row.classroom_uuid
         if classroom_uuid not in members_dict:
             members_dict[classroom_uuid] = []
         role = row.role
         member_user_id = row.user_id
         members_dict[classroom_uuid].append(
             dict(role=role,
                  user_id=member_user_id,
                  profile=ProfileHelper(member_user_id).get_profile()))
     return members_dict
Пример #6
0
 def new_submission(self, student_user_id, homework_uuid):
     """Teacher only"""
     student_nickname = ProfileHelper(student_user_id).get_nickname_by_username(student_user_id)
     creator = HomeworkHelper().get_creator_by_homework_uuid(homework_uuid)
     item_dict = dict(
         student_user_id=student_user_id,
         student_nickname=student_nickname,
         homework_uuid=homework_uuid,
         timestamp=self.timestamp
     )
     key = self.__get_key(creator, 't', UPDATE_KEY_TYPES['submissions'])
     self.__update_value(key, item_dict)
     # send message
     message = MESSAGE['submissions']
     tasks.send_apns_notification.delay(creator, message)
Пример #7
0
 def new_comment(self, author_user_id, receiver_user_id, receiver_role, homework_uuid, submission_uuid, info):
     """T & S"""
     author_profile_info = ProfileHelper(author_user_id).get_profile()
     item_dict = dict(
         author_profile_info=author_profile_info,
         homework_uuid=homework_uuid,
         submission_uuid=submission_uuid,
         info=info,
         timestamp=self.timestamp
     )
     key = self.__get_key(receiver_user_id, receiver_role, UPDATE_KEY_TYPES['comments'])
     self.__update_value(key, item_dict)
     # send message
     nickname = author_profile_info['nickname'] if author_profile_info else ""
     message = MESSAGE['comments'].format(nickname)
     tasks.send_apns_notification.delay(receiver_user_id, message)
Пример #8
0
 def request_approved(self, requester_user_id, requester_role, classroom_uuid):
     """T & S"""
     approver = self.user_id
     approver_profile_info = ProfileHelper(approver).get_profile()
     classroom_info = ClassroomHelper(user_id=requester_user_id, role=requester_role).get_classroom_info(classroom_uuid)
     item_dict = dict(
         approver_profile_info=approver_profile_info,
         classroom_info=classroom_info,
         timestamp=self.timestamp
     )
     key = self.__get_key(requester_user_id, requester_role, UPDATE_KEY_TYPES['approvals'])
     self.__update_value(key, item_dict)
     # send message
     classroom_name = classroom_info['classroom_name'] if 'classroom_name' in classroom_info else ""
     message = MESSAGE['approvals'].format(classroom_name)
     tasks.send_apns_notification.delay(requester_user_id, message)
Пример #9
0
 def new_pending_request(self, requester, classroom_uuid, request_uuid):
     """T & S"""
     creator_user_id = ClassroomHelper().get_creator_by_classroom(classroom_uuid)
     requester_profile_info = ProfileHelper(requester).get_profile()
     item_dict = dict(
         requester_profile=requester_profile_info,
         classroom_uuid=classroom_uuid,
         request_uuid=request_uuid,
         requester_role=self.role,
         timestamp=self.timestamp
     )
     key = self.__get_key(creator_user_id, 't', UPDATE_KEY_TYPES['requests'])
     self.__update_value(key, item_dict)
     # send message
     message = MESSAGE['requests'].format(requester_profile_info['nickname'])
     tasks.send_apns_notification.delay(creator_user_id, message)