Exemplo n.º 1
0
    def get(self):
        if self.input.uid:
            obj = Users.get_by_uid(self.input.uid)
            data = obj.to_dict(remove_fields_list=['password'])
        else:
            data = Users.filter_by_query()
            if self.input.sk_ and self.input.sv_:
                data = data.filter(getattr(Users, self.input.sk_).like(f'%{self.input.sv_}%'))

            if self.input.odb_ and self.input.odt_ in ['asc', 'desc']:
                data = data.order_by(getattr(getattr(Users, self.input.odb_), self.input.odt_)())
            else:
                data = data.order_by(Users.time_create.desc())

            total = None
            if self.input.page and self.input.page_size:
                total = data.count()
                data = data.offset(
                    (int(self.input.page) - 1) * int(self.input.page_size)
                ).limit(int(self.input.page_size))

            data = [_t.to_dict(remove_fields_list=['password']) for _t in data]

            if total is not None:
                data = {'total': total, 'list': data}

        return data
Exemplo n.º 2
0
 def put(self):
     obj = Users.get_by_uid(self.input.uid)
     if self.input.status:
         obj.status = self.input.status
     if self.input.role_id:
         obj.role_id = self.input.role_id
     obj.save()
Exemplo n.º 3
0
 def post(self):
     user_obj = Users.get_by_uid(session['user_info']['uid'])
     if not user_obj.check_password(self.input.password):
         raise LogicError('原密码错误!')
     user_obj.set_password(self.input.new_password)
     user_obj.save()
     # 强制下线
     token_id_list = Passport.query.with_entities(Passport.token).filter_by(user_id=user_obj.id).all()
     for _id in token_id_list:
         current_app.config['SESSION_REDIS'].delete(current_app.config['SESSION_KEY_PREFIX'] + _id[0])
     session.clear()
Exemplo n.º 4
0
    def post(self):
        user_info = session.get('user_info')
        user_obj = Users.get_by_uid(user_info['uid'])

        update_dict = dict()

        for k in ['sex', 'avatar_url', 'site', 'location', 'company', 'github', 'twitter', 'weibo', 'bio']:
            if getattr(self.input, k) is not None:
                update_dict[k] = getattr(self.input, k)
        if self.input.sex in [0, 1, 2]:
            update_dict['sex'] = self.input.sex

        if self.input.privacy_level in [0, 1, 2]:
            update_dict['privacy_level'] = self.input.privacy_level

        user_obj.update(**update_dict)
        user_info.update(update_dict)
        session['user_info'] = user_info

        return user_info
Exemplo n.º 5
0
 def post(self):
     obj = Users.get_by_uid(self.input.uid)
     # 自己不能关注自己
     if session['user_info']['uid'] == obj.uid:
         raise LogicError('自己不能关注自己哦')
     if self.input.action == 'add':
         user_fav_obj = UserFavUser.filter_by_query(
             fav_user_id=obj.id,
             user_id=session['user_info']['id'],
             show_deleted=True).first()
         if user_fav_obj:
             user_fav_obj.available = 1
         else:
             user_fav_obj = UserFavUser()
             user_fav_obj.fav_user_id = obj.id
             user_fav_obj.user_id = session['user_info']['id']
         user_fav_obj.save()
     elif self.input.action == 'cal':
         user_fav_obj = UserFavUser.filter_by_query(
             fav_user_id=obj.id,
             user_id=session['user_info']['id']).first()
         if user_fav_obj:
             user_fav_obj.available = 0
             user_fav_obj.save()