コード例 #1
0
ファイル: views.py プロジェクト: aikx/diamond_backend
 def get(self, request):
     E = EasyDict()
     E.uk = -1
     E.key, E.auth, E.tid = 1, 2, 3
     if dict(request.GET).keys() != set():
         return E.key, [], []
     if not request.session['is_login']:
         return E.auth
     uid = int(decode(request.session['uid']))
     try:
         members = Member.objects.filter(member=uid)
     except:
         return E.uk
     my_team = []
     join_team = []
     for m in members:
         if m.auth == 'owner':
             my_team.append({
                 'tid': encode(str(m.team.id)),
                 'name': m.team.name,
                 'intro': m.team.intro,
                 'portrait': m.team.portrait if m.team.portrait else '',
                 'member_count': len(Member.objects.filter(team=m.team))
             })
         else:
             join_team.append({
                 'tid': encode(str(m.team.id)),
                 'name': m.team.name,
                 'intro': m.team.intro,
                 'portrait': m.team.portrait if m.team.portrait else '',
                 'member_count': len(Member.objects.filter(team=m.team))
             })
     return 0, my_team, join_team
コード例 #2
0
ファイル: views.py プロジェクト: aikx/diamond_backend
    def get(self, request):
        print(request.GET)
        E = EasyDict()
        E.uk = -1
        E.key, E.auth, E.tid = 1, 2, 3
        if dict(request.GET).keys() != {'tid'}:
            return E.key, '', '', '', '', 0, '', '', [], []
        uid = int(decode(request.session['uid']))
        tid = int(decode(request.GET.get('tid')))
        try:
            user = User.objects.get(id=uid)
        except:
            return E.auth, '', '', '', '', 0, '', '', [], []
        try:
            team = Team.objects.get(id=tid)
        except:
            return E.tid, '', '', '', '', 0, '', '', [], []
        members = Member.objects.filter(team=team)
        if not members.exists():
            return E.tid, '', '', '', '', 0, '', '', [], []
        name = team.name
        intro = team.intro
        portrait = team.portrait if team.portrait else ''
        create_dt = team.create_dt_str
        doc_num = len(team.root.subtree)
        cuid = ''
        cname = ''
        norm = []
        admin = []

        for m in members:
            if m.auth == 'owner':
                cuid = encode(str(m.member.id))
                cname = m.member.name
            elif m.auth == 'admin':
                admin.append({
                    'uid': encode(str(m.member.id)),
                    'name': m.member.name
                })
            else:
                norm.append({
                    'uid': encode(str(m.member.id)),
                    'name': m.member.name
                })
        return 0, name, intro, portrait, create_dt, doc_num, cuid, cname, norm, admin
コード例 #3
0
ファイル: views.py プロジェクト: aikx/diamond_backend
    def post(self, request):
        if request.session.get('is_login', None):  # 已登录
            try:
                u = User.objects.get(id=int(decode(request.session['uid'])))
            except:
                return 0, -1
            print(1)
            if u.login_date != date.today():
                u.login_date = date.today()
                u.wrong_count = 0
                try:
                    u.save()
                except:
                    return 0, -1
            return 0, 0
        print(2)
        E = EasyDict()
        E.uk = -1
        E.key, E.exist, E.pwd, E.many = 1, 2, 3, 4
        kwargs: dict = json.loads(request.body)
        if kwargs.keys() != {'acc', 'pwd'}:
            return 0, E.key
        print(3)
        u = User.objects.filter(acc=kwargs['acc'])
        if not u.exists():
            return 0, E.exist
        u = u.get()
        print(4)
        if u.login_date != date.today():
            u.login_date = date.today()
            u.wrong_count = 0
            try:
                u.save()
            except:
                return u.wrong_count, E.uk

        if u.wrong_count == MAX_WRONG_PWD:
            return u.wrong_count, E.many
        print(4.5)
        if u.pwd != str(hash_password(kwargs['pwd'])):
            print(5)
            u.wrong_count += 1
            try:
                u.save()
            except:
                return 0, -1
            return u.wrong_count, E.pwd
        print(6)
        request.session['is_login'] = True
        request.session['uid'] = encode(u.id)
        request.session['name'] = u.name
        request.session.save()
        try:
            u.save()
        except:
            return u.wrong_count, E.uk
        return u.wrong_count, 0
コード例 #4
0
ファイル: views.py プロジェクト: aikx/diamond_backend
 def get(self, request):
     if not request.session.get('is_login', None):
         return '', '', '', '', 2
     try:
         uid = int(decode(request.session.get('uid', None)))
     except:
         return '', '', '', '', -1
     u = User.objects.filter(id=uid)
     if not u.exists():
         return '', '', '', '', -1
     u = u.get()
     return u.name, u.portrait, u.acc, encode(u.id), 0
コード例 #5
0
ファイル: views.py プロジェクト: aikx/diamond_backend
 def post(self, request):
     if not request.session['is_login']:
         return [], 2
     kwargs: dict = json.loads(request.body)
     if kwargs.keys() != {'key'}:
         return [], 1
     us = User.objects.filter(Q(name__icontains=kwargs['key']) | Q(acc__icontains=kwargs['key']))
     ulist = []
     for u in us:
         ulist.append({
             'name': u.name,
             'portrait': u.portrait,
             'acc': u.email,
             'uid': encode(u.id)
         })
     return ulist, 0
コード例 #6
0
ファイル: views.py プロジェクト: aikx/diamond_backend
    def get(self, request):
        if dict(request.GET).keys() != {'page', 'each'}:
            return 1, [], 0, ''
        try:
            page = int(request.GET.get('page'))
            each = int(request.GET.get('each'))
        except ValueError:
            return -1, [], 0, ''

        u = User.objects.filter(id=int(decode(request.session['uid'])))
        if not u.exists():
            return -1, [], 0, ''
        u = u.get()
        messages = Message.objects.filter(owner_id=u.id).order_by('dt')[(page - 1) * each: page * each]
        msg = []
        for message in messages:
            msg.append({
                'mid': encode(message.id),
                'dt': message.dt_str,
            })
        return 0, cur_time(), len(msg), msg
コード例 #7
0
ファイル: views.py プロジェクト: aikx/diamond_backend
    def post(self, request):
        E = EasyDict()
        E.uk = -1
        E.key, E.acc, E.pwd, E.code, E.name, E.uni = 1, 2, 3, 4, 5, 6
        kwargs: dict = json.loads(request.body)
        if kwargs.keys() != {'acc', 'ver_code', 'pwd', 'name'}:
            return E.key,
        if not CHECK_ACC(kwargs['acc']):
            return E.acc,
        if not CHECK_PWD(kwargs['pwd']):
            return E.pwd,
        if not CHECK_NAME(kwargs['name']):
            return E.name,
        kwargs.update({'pwd': hash_password(kwargs['pwd'])})
        kwargs.update({'portrait': DEFAULT_PROFILE_ROOT + '\handsome.jpg'})
        er = EmailRecord.objects.filter(code=kwargs['ver_code'], acc=kwargs['acc'])
        if not er.exists():
            return E.code
        er = er.get()
        kwargs.pop('ver_code')

        if datetime.now() < er.expire_time:
            try:
                # print(kwargs)
                root = Entity.locate_root(name=kwargs['name'])
                u = User.objects.create(root=root, **kwargs)
            except IntegrityError:
                return E.uni,  # 字段unique未满足
            except DataError as e:
                return E.uk,  # 诸如某个CharField超过了max_len的错误
            except:
                return E.uk,
            request.session['is_login'] = True
            request.session['uid'] = encode(u.id)
            # print(u.portrait.path)
            return 0,
        else:
            return 7
コード例 #8
0
 def encoded_id(self):
     return encode(self.id)
コード例 #9
0
ファイル: views.py プロジェクト: aikx/diamond_backend
    def get(self, request):
        if dict(request.GET).keys() != {'mid'}:
            return 1, [] * 13
        try:
            mid = int(decode(request.GET.get('mid')))
        except ValueError:
            return -1, [] * 13

        u = User.objects.filter(id=int(decode(request.session['uid'])))

        if not u.exists():
            return -1, [] * 13
        u = u.get()
        msg = Message.objects.filter(id=mid)
        if not msg.exists():
            return -1, [] * 13
        msg = msg.get()
        return 0, msg.is_read, msg.is_process, u.is_dnd, msg.title, msg.portrait, msg.type, encode(msg.related_id) if msg.related_id else '', msg.content, cur_time(), msg.dt_str