Ejemplo n.º 1
0
def c_upload():
    error = ''
    #如果无法获取CKEditorFuncNum,去编辑器config下添加config.filebrowserUploadMethod = 'form';
    text = 'https://blogai.cn | @%s' % current_user.username
    callback = request.args.get("CKEditorFuncNum")
    pic = request.files.get('upload')
    fn = time.strftime('%Y%m%d%H%M%S') + '_%d' % random.randint(0,
                                                                100) + '.png'
    creat_folder(
        os.path.join(app.config['UPLOADS_FOLDER'], md5(current_user.uuid)))
    pic_dir = os.path.join(app.config['UPLOADS_FOLDER'],
                           md5(current_user.uuid), fn)
    pic.save(pic_dir)
    image = Image.open(pic_dir)
    draw = ImageDraw.Draw(image)
    width, height = image.size
    margin = 20
    font = ImageFont.truetype("C://Windows/Fonts/simsun.ttc", 20)
    textWidth, textHeight = draw.textsize(text, font)
    x = (width - textWidth - margin) / 2
    y = height - textHeight - margin
    draw.text((x, y), text, fill=(144, 109, 189), font=font)
    image.save(pic_dir)
    folder = 'uploads/' + md5(current_user.uuid)
    url = folder + '/' + fn
    u = 'http://127.0.0.1:5000/static/' + url
    cb_str = """
    <script type="text/javascript">
    window.parent.CKEDITOR.tools.callFunction(%s, '%s', '%s')
    </script>
    """ % (callback, u, error)
    response = make_response(cb_str)
    response.headers["Content-Type"] = "text/html"

    return response
Ejemplo n.º 2
0
def e_upload():

    text = 'https://blogai.cn | @{}'.format(current_user.username)
    pic = request.files.get('editormd-image-file')
    fn = time.strftime('%Y%m%d%H%M%S') + '_%d' % random.randint(0,
                                                                100) + '.png'
    creat_folder(
        os.path.join(app.config['UPLOADS_FOLDER'], md5(current_user.uuid)))
    pic_dir = os.path.join(app.config['UPLOADS_FOLDER'],
                           md5(current_user.uuid), fn)
    pic.save(pic_dir)
    image = Image.open(pic_dir)
    draw = ImageDraw.Draw(image)
    width, height = image.size
    margin = 20
    font = ImageFont.truetype("C://Windows/Fonts/simsun.ttc", 20)
    font_w, font_h = draw.textsize(text, font)

    x = (width - font_w - margin) / 2
    y = height - font_h - margin
    draw.text((x, y), text, fill=(144, 109, 189), font=font)
    image.save(pic_dir)

    folder = 'uploads/' + md5(current_user.uuid)
    url = folder + '/' + fn
    res = {
        'success': 1,
        'message': '上传成功',
        'url': 'http://127.0.0.1:5000/static/' + url
    }
    return jsonify(res)
Ejemplo n.º 3
0
def ckeditor():
    form = PostForm()
    if form.validate_on_submit():
        post = Article()
        pic_ = form.pic.data
        if pic_ is not None:
            fn = time.strftime('%Y%m%d%H%M%S') + '_%d' % random.randint(
                0, 100) + '.png'
            creat_folder(
                os.path.join(app.config['UPLOADS_FOLDER'],
                             md5(current_user.uuid)))
            pic_dir = os.path.join(app.config['UPLOADS_FOLDER'],
                                   md5(current_user.uuid), fn)
            print(pic_dir)
            pic = Image.open(pic_)
            pic.save(pic_dir)
            folder = 'uploads/' + md5(current_user.uuid)
            post.img = folder + '/' + fn

        post.uuid = current_user.uuid
        post.tittle = form.title.data
        post.body = form.body.data
        db.session.add(post)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('ck.html', form=form)
Ejemplo n.º 4
0
def mp_send_mail():
    appid = os.environ.get('APP_ID')
    receive = request.headers['Appid']
    if receive == appid:
        says = json.loads(request.values.get('iss'))
        imgs = request.files.get('imgs')
        print(says)
        send = Message('小程序反馈',
                       sender='*****@*****.**',
                       recipients=['*****@*****.**'])
        if imgs is not None:
            fn = time.strftime('%Y%m%d%H%M%S') + '_%d' % random.randint(
                0, 100) + '.png'
            creat_folder(os.path.join(app.config['UPLOADS_FOLDER'], 'iss'))
            pic_folder = os.path.join(app.config['UPLOADS_FOLDER'], 'iss', fn)
            img = Image.open(imgs)
            img.save(pic_folder)
            with app.open_resource(pic_folder) as f:
                send.attach('pic.png', 'image/png', f.read())
        send.html = "<div><p>{}</p></div>".format(says)
        thread = Thread(target=send_async_email, args=[app, send])
        thread.start()
        return 'success'
Ejemplo n.º 5
0
def profile():
    form = Profile()
    if form.validate_on_submit():
        user = UserProfile()
        fn = time.strftime('%Y%m%d%H%M%S') + '_%d' % random.randint(
            0, 100) + '.png'
        avata = form.avatar.data
        new = compression_img(avata)
        creat_folder(
            os.path.join(app.config['UPLOADS_FOLDER'], md5(current_user.uuid)))
        pic_dir = os.path.join(app.config['UPLOADS_FOLDER'],
                               md5(current_user.uuid), fn)
        print(pic_dir)
        new.save(pic_dir)

        header = Role.query.filter_by(uuid=current_user.uuid).first()
        folder = 'uploads/' + md5(current_user.uuid)
        header.avatar = folder + '/' + fn

        if header.profile:
            proid = UserProfile.query.filter_by(
                user_id=current_user.uuid).first()
            proid.nickname = form.nickname.data
            proid.gender = form.gender.data
            proid.intro = form.intro.data
            proid.birthday = request.form.get('birthday')
            db.session.commit()
        else:
            user.user_id = current_user.uuid
            user.nickname = form.nickname.data
            user.birthday = request.form.get('birthday')
            user.gender = form.gender.data
            user.intro = form.intro.data
            db.session.add(user)
            db.session.commit()
        return redirect(url_for('profile'))
    return render_template('profile.html', form=form)