Esempio n. 1
0
 def post(self):
     id = request.form.get('id')
     if not id:
         return field.params_error(message='参数缺失')
     image = Images.query.get(id)
     if not image:
         return field.params_error(message='没有改图片')
     filename = image.name
     if image.type == 'github':
         git = GithubTools()
         code, message = git.delete_file('{}{}'.format(
             config.PATH, '/' + filename))
         db.session.delete(image)
         db.session.commit()
         return field.success(message=message)
     elif image.type == 'server':
         path = os.path.join(config.LOCAL_STORAGE_PATH, filename)
         if os.path.exists(path):
             os.remove(path)
             db.session.delete(image)
             db.session.commit()
             return field.success(message='删除成功')
         else:
             return field.params_error(message='没有改图片')
     else:
         return field.params_error('配置文件中STORE_TYPE字段设置不正确')
Esempio n. 2
0
    def post(self):
        form = LoginForm(request.form)
        if form.validate():
            email = form.email.data  # 邮箱或者用户名
            password = form.password.data
            remember = form.remember.data
            user = Admin.query.filter_by(
                email=email).first() or Admin.query.filter_by(
                    username=email).first()
            if user and user.check_password(password):
                session[
                    current_app.config['CMS_USER_ID']] = user.id  # 保存用户登录信息
                if remember:
                    # 如果设置session.permanent = True,那么过期时间为31天
                    session.permanent = True
                user.last_login_time = datetime.datetime.now()
                db.session.add(user)
                db.session.commit()
                return field.success(message='登陆成功!')
            else:
                return field.params_error(message='邮箱或者密码错误')

        else:
            message = form.get_error()
            return field.params_error(message=message)
Esempio n. 3
0
 def get(self):
     account_id = request.args.get('account_id')
     if account_id:
         account = WechatAccount.query.filter_by(__biz=account_id.strip()).first()
         if account:
             img = account.qr_code
             return field.success(message='查询成功', data={'img': img})
         else:
             return field.params_error('')
     return field.params_error('参数错误')
Esempio n. 4
0
    def post(self):
        ips = request.form.get('ips')

        if ips:
            is_exc = IPS.query.filter(IPS.ips == ips).first()
            if not is_exc:
                new_ips = IPS(ips=ips)
                db.session.add(new_ips)
                db.session.commit()
                return field.success(message='{}添加成功!'.format(ips))
            return field.params_error(message='添加失败!')
        return field.params_error(message='添加失败!')
Esempio n. 5
0
    def post(self):
        data = request.values
        print(data)
        get_id = data.get('id')
        status = data.get('status')
        ips = IPS.query.filter(IPS.id == get_id).first()
        if ips:
            if status:
                if ips.status != status:
                    ips.status = status

                db.session.commit()
                return field.success(message='修改成功!')
            return field.params_error(message='修改失败!')
        return field.params_error(message='修改失败!')
Esempio n. 6
0
def article():
    id = request.args.get('id')
    if id:
        article = WechatArticle.query.filter_by(sn=id).filter(WechatArticle.is_hide == 0).first()
        announcement = Announcement.query.order_by(Announcement.time.desc()).first()
        if article:
            context = {
                'article': article,
                'announcement': announcement
            }
            return render_template('front/front_article.html', **context)
        else:
            return field.params_error(message='没有找到相关文章!')
    else:
        return field.params_error(message='参数错误!')
Esempio n. 7
0
 def post(self):
     data = request.values
     id = data.get('id')
     del_ips = IPS.query.filter(IPS.id == id).first()
     if del_ips:
         db.session.delete(del_ips)
         db.session.commit()
         return field.success(message='删除成功!')
     return field.params_error(message='删除失败!')
Esempio n. 8
0
 def post(self):
     file = request.files['file']
     filename = file.filename
     content = file.read()
     if not file:
         return field.params_error(message='未接收到文件')
     if not allowed_file(file.filename,
                         ALLOWED_EXTENSIONS=config.ALLOWED_PIC_EXTENSIONS):
         return field.params_error(message='图片格式不合法')
     if not file_len(content):
         return field.params_error(message='图片大小超过{}M'.format(
             int(config.ALLOWED_PIC_LEN / 1024 / 1024)))
     new_name = rename(filename)
     if config.STORE_TYPE == 'github':  # github存储
         git = GithubTools()
         code, link = git.create_file(
             '{}{}'.format(config.PATH, '/' + new_name), content)
         if code:
             image = Images(name=new_name, link=link, type='github')
             db.session.add(image)
             db.session.commit()
             return field.layui_success(message='上传成功,请拷贝链接使用',
                                        data={
                                            'link': link,
                                            'id': image.id
                                        })
         else:
             return field.params_error(message=link)
     elif config.STORE_TYPE == 'server':  # 本地存储
         img = open(os.path.join(config.LOCAL_STORAGE_PATH, new_name), 'wb')
         img.write(content)
         img.close()
         link = request.url_root + 'static/images/' + new_name
         image = Images(name=new_name, link=link, type='server')
         db.session.add(image)
         db.session.commit()
         return field.layui_success(message='上传成功,请拷贝链接使用',
                                    data={
                                        'link': link,
                                        'id': image.id
                                    })
     else:
         return field.params_error('配置文件中STORE_TYPE字段设置不正确')
Esempio n. 9
0
 def get(self):
     id = request.args.get('id')
     if id:
         article = WechatArticleList.query.filter_by(sn=id).first()
         if article:
             article_dict = {}
             article_dict['title'] = article.title
             if article.author == '':
                 article_dict['author'] = '匿名'
             else:
                 article_dict['author'] = article.author
             article_dict['publish_time'] = str(article.publish_time)
             article_dict['account_name'] = article.account
             article_dict['url'] = article.url
             article_dict['content_html'] = tools.filter_html(article.content_html)
             article_dict['id'] = getattr(article, '__biz')
             return field.success(message='', data=article_dict)
         else:
             return field.params_error(message='没有该文章!')
     return field.params_error(message='参数错误!')
Esempio n. 10
0
def send_email(subject, sender, recipients, text_body, html_body):
    app = db.app

    with app.app_context():
        msg = Message(subject, sender=sender, recipients=recipients)
        msg.body = text_body
        msg.html = html_body
        try:
            mail.send(msg)
        except Exception as e:
            print(e)
            return field.params_error(message='邮件服务器出错')
Esempio n. 11
0
def article_id():
    # TODO:必须登录用户才能够查看快照功能
    id = request.args.get('id')
    if id:
        article = WechatArticle.query.filter_by(sn=id).filter(WechatArticle.is_hide == 0).first()
        if article:
            article_dict = {}
            article_dict['title'] = article.title
            if article.author == '':
                article_dict['author'] = '匿名'
            else:
                article_dict['author'] = article.author
            article_dict['publish_time'] = str(article.publish_time)
            article_dict['account_name'] = article.account
            article_dict['url'] = article.url
            article_dict['content_html'] = tools.filter_html(article.content_html)
            article_dict['id'] = article.__biz
            return field.success(message='', data=article_dict)
        else:
            return field.params_error(message='没有该文章!')
    return field.params_error(message='参数错误!')
Esempio n. 12
0
 def get(self):
     return field.params_error(message='不支持改方法')
Esempio n. 13
0
 def post(self):
     return field.params_error(message='不支持该方法')