Exemple #1
0
    def post(self):
        data = request.json
        username = data.get('username')
        password = data.get('password')
        if username is None or username == '' or \
                password is None or password == '':
            current_app.logger.error(
                '用户名或密码为空 %s', str({
                    'username': username,
                    'password': password
                }))
            return Warp.fail_warp(301)

        try:
            res = MLogin().user_login(username, password)
            return Warp.success_warp(res.__dict__)
        except SQLAlchemyError as e:
            current_app.logger.error(e)
            return Warp.fail_warp(501)
        except UserNotFound as e:
            current_app.logger.error(e)
            return Warp.fail_warp(201)
        except PasswordError as e:
            current_app.logger.error(e)
            return Warp.fail_warp(202)
Exemple #2
0
 def get(self):
     try:
         res = MServer().get_server_info()
         return Warp.success_warp(res.__dict__)
     except SQLAlchemyError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(501)
     except NotImplementedError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(403)
Exemple #3
0
    def get(self, mail_id: str):
        current_app.logger.debug(mail_id)
        if mail_id is None:
            # 获取所有邮件列表
            args = request.args
            subject = args.get('subject')
            # 做类型验证
            try:
                current_app.logger.debug(args.get('limit'))
                limit = int(args.get('limit'))
            except (TypeError, ValueError):
                limit = 10
            try:
                page = int(args.get('page'))
            except (TypeError, ValueError):
                page = 0

            try:
                res = get_email(g.user_type,
                                g.user_id,
                                subject=subject,
                                page=page,
                                limit=limit).get_mail_list()
                return Warp.success_warp(res.__dict__)
            except SQLAlchemyError as e:
                current_app.logger.error(e)
                return Warp.fail_warp(501)
            except NotImplementedError as e:
                current_app.logger.error(e)
                return Warp.fail_warp(403)
        else:
            try:
                res = get_email(g.user_type,
                                user_id=g.user_id).get_mail_detail(mail_id)
                return Warp.success_warp(res.__dict__)
            except SQLAlchemyError as e:
                current_app.logger.error(e)
                return Warp.fail_warp(501)
            except MailNotExist as e:
                current_app.logger.error(e)
                return Warp.fail_warp(208)
            except NotYourMail as e:
                current_app.logger.error(e)
                return Warp.fail_warp(403)
            except NotImplementedError as e:
                current_app.logger.error(e)
                return Warp.fail_warp(403)
            except ErrorProto as e:
                current_app.logger.error(e)
                return Warp.fail_warp(502)
            except POPServerUseless as e:
                current_app.logger.error(e)
                return Warp.fail_warp(504)
Exemple #4
0
 def put(self, user_id):
     try:
         get_manage_user(g.user_type, user_id=user_id).modify_user(request.json)
         return Warp.success_warp('修改成功')
     except (TypeError, ValueError, PropertyNotExist) as e:
         current_app.logger.error(e)
         return Warp.fail_warp(302, msg=str(e))
     except SQLAlchemyError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(501)
     except UserNotFound as e:
         current_app.logger.error(e)
         return Warp.fail_warp(201)
     except ModifyAdminError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(406)
     except PasswordNotSatisfactory as e:
         current_app.logger.error(e)
         return Warp.fail_warp(203)
     except NotImplementedError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(403)
     except ModifyUserTypeError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(403)
Exemple #5
0
 def delete(self, mail_id):
     if mail_id is None:
         current_app.logger.error('邮件id为空 %s', str({
             'mail_id': mail_id,
         }))
         return Warp.fail_warp(301)
     try:
         get_email(g.user_type, user_id=g.user_id).receive_delete(mail_id)
         return Warp.success_warp('删除成功')
     except NotImplementedError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(403)
     except MailNotExist as e:
         current_app.logger.error(e)
         return Warp.fail_warp(208)
Exemple #6
0
 def delete(self, user_id):
     try:
         get_manage_user(g.user_type, user_id=user_id).delete_user()
         return Warp.success_warp('删除成功')
     except SQLAlchemyError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(501)
     except UserNotFound as e:
         current_app.logger.error(e)
         return Warp.fail_warp(201)
     except DeleteAdminError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(406)
     except NotImplementedError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(403)
Exemple #7
0
    def delete(self):
        data = request.json
        ip_id = data.get('id')
        if ip_id is None:
            current_app.logger.error('ip号为空 %s', str({'id': ip_id}))
            return Warp.fail_warp(301)

        try:
            MManage().delete_ip(ip_id)
            return Warp.success_warp('ip移除黑名单成功')
        except SQLAlchemyError as e:
            current_app.logger.error(e)
            return Warp.fail_warp(501)
        except AddressNotExist as e:
            current_app.logger.error(e)
            return Warp.fail_warp(206)
Exemple #8
0
 def post(self):
     data = request.json
     sender_ip = request.remote_addr
     if g.user_type == 2:
         to_addr = data.get('receivers')
     else:
         to_addr = []
     content = data.get('content')
     subject = data.get('subject')
     try:
         get_email(g.user_type,
                   user_id=g.user_id).send_mail(sender_ip, to_addr, content,
                                                subject)
         return Warp.success_warp('发送成功')
     except SMTPException as e:
         current_app.logger.error(e)
         return Warp.fail_warp(500)
     except NotImplementedError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(403)
     except AddrIsUseless as e:
         current_app.logger.error(e)
         return Warp.fail_warp(209)
     except UserIsUseless as e:
         current_app.logger.error(e)
         return Warp.fail_warp(210)
     except HaveNoReceiver as e:
         current_app.logger.error(e)
         return Warp.fail_warp(303)
     except SMTPServerUseless as e:
         current_app.logger.error(e)
         return Warp.fail_warp(503)
Exemple #9
0
    def decode_token():
        token = request.headers.get('Authorization')
        if token is None:
            current_app.logger.warn(errors['402'])
            return Warp.fail_warp(402), 401

        try:
            jwt = Token.parse_token(token)
            user_id, user_type = jwt['user_id'], jwt['user_type']
            g.user_id, g.user_type = user_id, user_type

            current_app.logger.info('当前登录用户 id 为 %d, 用户类型为 %d', user_id,
                                    user_type)
        except ExpiredSignatureError:
            current_app.logger.warn(errors['404'])
            return Warp.fail_warp(404), 401
        except DecodeError:
            current_app.logger.warn(errors['405'])
            return Warp.fail_warp(405), 401
Exemple #10
0
    def post(self):
        data = request.json
        address = data.get('address')
        if address is None or address == '':
            current_app.logger.error('ip地址为空 %s', str({'address': address}))
            return Warp.fail_warp(301)

        try:
            MManage().add_ip(address)
            return Warp.success_warp('拉黑ip成功')
        except SQLAlchemyError as e:
            current_app.logger.error(e)
            return Warp.fail_warp(501)
        except AddressExist as e:
            current_app.logger.error(e)
            return Warp.fail_warp(205)
        except AddressError as e:
            current_app.logger.error(e)
            return Warp.fail_warp(207)
Exemple #11
0
    def get(self):
        # 获取所有黑名单ip信息
        args = request.args
        try:
            current_app.logger.debug(args.get('limit'))
            limit = int(args.get('limit'))
        except (TypeError, ValueError):
            limit = 10
        try:
            page = int(args.get('page'))
        except (TypeError, ValueError):
            page = 0

        try:
            res = MManage(page=page, limit=limit).get_ip_list()
            return Warp.success_warp(res.__dict__)
        except SQLAlchemyError as e:
            current_app.logger.error(e)
            return Warp.fail_warp(501)
Exemple #12
0
    def post(self):
        data = request.json
        username = data.get('username')
        password = data.get('password')
        if username is None or username == '' or \
                password is None or password == '':
            current_app.logger.error('用户名或密码为空 %s', str({
                'username': username,
                'password': password
            }))
            return Warp.fail_warp(301)

        try:
            MRegister().create_new_user(username, password)
            return Warp.success_warp('注册成功')
        except SQLAlchemyError as e:
            current_app.logger.error(e)
            return Warp.fail_warp(501)
        except PasswordNotSatisfactory as e:
            current_app.logger.error(e)
            return Warp.fail_warp(203)
        except UserHaveExist as e:
            current_app.logger.error(e)
            return Warp.fail_warp(204)
Exemple #13
0
    def get(self, user_id):
        # 管理员执行方法
        if user_id is None:
            # 获取所有用户信息
            args = request.args
            username = args.get('username')
            # 做类型验证
            try:
                current_app.logger.debug(args.get('limit'))
                limit = int(args.get('limit'))
            except (TypeError, ValueError):
                limit = 10
            try:
                page = int(args.get('page'))
            except (TypeError, ValueError):
                page = 0

            try:
                res = get_manage_user(g.user_type, username=username, page=page, limit=limit).get_all_user()
                return Warp.success_warp(res.__dict__)
            except SQLAlchemyError as e:
                current_app.logger.error(e)
                return Warp.fail_warp(501)
            except NotImplementedError as e:
                current_app.logger.error(e)
                return Warp.fail_warp(403)
        else:
            try:
                res = get_manage_user(g.user_type, user_id=user_id).get_user_detail()
                return Warp.success_warp(res.__dict__)
            except SQLAlchemyError as e:
                current_app.logger.error(e)
                return Warp.fail_warp(501)
            except UserNotFound as e:
                current_app.logger.error(e)
                return Warp.fail_warp(201)
            except NotImplementedError as e:
                current_app.logger.error(e)
                return Warp.fail_warp(403)
Exemple #14
0
 def put(self):
     try:
         my_server(request.json)
         return Warp.success_warp('修改成功')
     except (TypeError, ValueError, PropertyNotExist) as e:
         current_app.logger.error(e)
         return Warp.fail_warp(302, msg=str(e))
     except SQLAlchemyError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(501)
     except StateNotExist as e:
         current_app.logger.error(e)
         return Warp.fail_warp(302)
     except PortOutOfRange as e:
         current_app.logger.error(e)
         return Warp.fail_warp(302)
     except NotImplementedError as e:
         current_app.logger.error(e)
         return Warp.fail_warp(403)
Exemple #15
0
 def get(self):
     return Warp.success_warp('get pong')
Exemple #16
0
 def post(self):
     return Warp.success_warp('post pong')