Example #1
0
def reward_add():
    view_data = {'title': '添加打赏-{}'.format(config['title'].TITLE)}
    profile = mdb_user.user_profile.find_one_or_404(
        {'user_id': current_user.id})
    form = EditRewardForm('add')
    if form.submit.data:
        if current_user.verify_password(form.password.data):
            bucket_name = {
                'b': config['upload'].IMG_B,
                'domain': 'img',
                'project': 'pay'
            }
            uploaded_files = request.files.getlist("payimg")
            r = img_up(uploaded_files, bucket_name)
            if r['url'] != -1 and r['url'] != 1:
                if 'pay' in profile and profile['pay']:
                    _pay = profile['pay']
                    _pay[form.pay_type.data] = {
                        'url': r['url'],
                        'word': form.word.data.strip(),
                        'status': 0,
                        'time': time.time()
                    }
                else:
                    _pay = {
                        form.pay_type.data: {
                            'url': r['url'],
                            'word': form.word.data.strip(),
                            'status': 0,
                            'time': time.time()
                        }
                    }
                flash({'msg': '二维码上传成功,需要等待审核!', 'type': 's'})
            else:
                flash({'type': 'e', 'msg': '支付二维码上传失败!'})
                return render_template('online/user/reward_edit.html',
                                       view_data=view_data,
                                       form=form)

            _pay[form.pay_type.data]['use'] = int(form.nonuse.data)
            _pay[form.pay_type.data]['time'] = time.time()
            mdb_user.user_profile.update({'user_id': current_user.id},
                                         {'$set': {
                                             'pay': _pay
                                         }})
            return redirect(url_for('online.reward'))
        else:
            flash({'msg': '登录密码不对!', 'type': 'e'})

    view_data['pay_url'] = {}
    return render_template('online/user/reward_edit.html',
                           view_data=view_data,
                           form=form)
Example #2
0
def add_img():

    view_data = {'title': '添加图片'}
    form = EditImgForm()
    if form.submit.data:
        if not form.name.data.strip():
            flash({'type': 'w', 'msg': '名字不能为空!'})
            return render_template('{}/media/image/add_img.html'.format(
                Theme.ADM_THEME_NAME),
                                   form=form,
                                   view_data=view_data)
        uploaded_files = request.files.getlist("img")
        bucket_name = {
            'b': app_config['upload'].IMG_B,
            'domain': 'img',
            'project': form.project.data
        }
        r = img_up(uploaded_files,
                   bucket_name,
                   new_name=form.name.data.strip())
        if r['url'] != -1 and r['url'] != 1:
            img_profile = {
                'url': r['url'],
                'type': form.project.data,
                'time': time.time(),
                'name': form.name.data.strip(),
                'showname': form.showname.data.strip(),
                'info': form.info.data,
                'link': form.link.data.strip()
            }
            mdb_sys.db.img.insert(img_profile)
            flash({'msg': '成功.', 'type': 's'})
        else:
            flash({'msg': '图片上传失败!', 'type': 'e'})
        return redirect(url_for('media.image', project=form.project.data))

    return render_template('{}/media/image/add_img.html'.format(
        Theme.ADM_THEME_NAME),
                           form=form,
                           view_data=view_data)
Example #3
0
def reward_edit(type):
    view_data = {'title': '打赏设置-{}'.format(config['title'].TITLE)}
    profile = mdb_user.user_profile.find_one_or_404(
        {'user_id': current_user.id})
    form = EditRewardForm('edit')
    if form.submit.data:
        if current_user.verify_password(form.password.data):
            bucket_name = {
                'b': config['upload'].IMG_B,
                'domain': 'img',
                'project': 'pay'
            }
            uploaded_files = request.files.getlist("payimg")
            r = img_up(uploaded_files, bucket_name)
            if r['url'] != -1 and r['url'] != 1:
                img_del(profile['pay'][type.strip()]['url'])
                if 'pay' in profile:
                    _pay = profile['pay']
                    _pay[type.strip()] = {
                        'url': r['url'],
                        'word': form.word.data.strip(),
                        'status': 0,
                        'time': time.time()
                    }
                else:
                    _pay = {
                        type.strip(): {
                            'url': r['url'],
                            'word': form.word.data.strip(),
                            'status': 0,
                            'time': time.time()
                        }
                    }
                flash({'msg': '修改了二维码,需要等待审核!', 'type': 's'})
            else:
                if 'pay' in profile:
                    _pay = profile['pay']
                    status = _pay[type.strip()]['status']
                    _pay[type.strip()] = {
                        'url': _pay[type.strip()]['url'],
                        'word': form.word.data.strip(),
                        'status': status
                    }
                else:
                    _pay = {
                        type.strip(): {
                            'url': '',
                            'word': form.word.data.strip(),
                            'status': 0
                        }
                    }
            _pay[type.strip()]['use'] = int(form.nonuse.data)
            _pay[type.strip()]['time'] = time.time()
            mdb_user.user_profile.update({'user_id': current_user.id},
                                         {'$set': {
                                             'pay': _pay
                                         }})
            return redirect(url_for('online.reward'))
        else:
            flash({'msg': '登录密码不对!', 'type': 'e'})

    form.pay_type.data = type.strip()
    form.word.data = profile['pay'][type.strip()]['word']
    form.nonuse.data = str(profile['pay'][type.strip()]['use'])
    view_data['pay_url'] = profile['pay'][type.strip()]['url']
    view_data['op_type'] = 'edit'
    return render_template('online/user/reward_edit.html',
                           view_data=view_data,
                           form=form)
Example #4
0
def user_edit_profile(uploaded_files, username, sex, addr, info):
    _data = {}
    domain = None
    if 'u-domain' in request.value.all and request.value.all['u-domain'].strip():
        names = mdb_sys.db.audit_rules.find_one({'type':'username'})
        domain = request.value.all['u-domain'].strip().replace(' ','')
        if len(domain)<3 or len(domain)>30:
            flash({'msg':'个性域名:需要3至30个字符!', 'type':'w'})
            return jsonify(_data)
        if not re.search(r"^[a-z0-9]+$",domain):
            flash({'msg':'个性域名:只能是数字, 小写字母!', 'type':'w'})
            return jsonify(_data)

        elif mdb_user.db.user_profile.find_one({'domain':domain}) or domain==str(current_user.id):
            flash({'msg':'此个性域名已被使用!', 'type':'w'})
            return jsonify(_data)
        elif domain in names and not current_user.can(Permission.ADMINISTER) and not current_user.is_role(Permission.ECP):
            flash({'msg':'此个性域名已被使用!', 'type':'w'})
            return jsonify(_data)

    if not username:
        flash({'msg':'名号不能为空!', 'type':'w'})
        return jsonify(_data)

    user = mdb_user.db.user.find_one({"username":username})
    if user and user["_id"] != current_user.id:
        flash({'msg':'此名号已被使用!', 'type':'w'})
        return jsonify(_data)

    names = mdb_sys.db.audit_rules.find_one({'type':'username'})
    try:
        t_username = username.upper()
    except:
        t_username = username
    if t_username in names['rule'] and not current_user.can(Permission.ADMINISTER) and not current_user.is_role(Permission.ECP):
        flash({'msg':'此名号已被使用!', 'type':'w'})
        return jsonify(_data)

    if len(username.encode("gbk").decode("gbk")) > 150:
        flash({'msg':u'最多150字哦!','type':'w'})
        return jsonify(_data)

    # ---------------------------------------------------------------
    tel = ""

    # 地址
    _provinces = ''
    _city = ''
    _area = ''
    addrs = addr_f()
    if addr['p'].strip("string:"):
        for lv in addrs:
            if lv['id'] == addr['p'].strip("string:"):
                lv1 = lv
                _provinces = lv['text']
                break
    if addr['c'].strip("string:"):
        for lv in lv1['children']:
            if lv['id'] == addr['c'].strip("string:"):
                lv2 = lv
                _city = lv['text']
                break
    if addr['a'].strip("string:"):
        for lv in lv2['children']:
            if lv['id'] == addr['a'].strip("string:"):
                _area = lv['text']
                break
    addr = {"provinces":_provinces}
    addr['city'] = _city
    addr['area'] = _area
    #性别
    if sex:
        sex = int(sex)
    # 头像
    bucket_name = {'b':config['upload'].AVA_B, 'domain':'avatar', 'project':'avatar'}
    r = img_up(uploaded_files, bucket_name)
    if r['url'] != -1:
        if r['url'] == 1:
            user_profile = {
            'username':username,
            'addr':addr,
            'info':info,
            'tel_num':tel,
            'sex':sex
            }
        else:
            user_profile = {
                'username':username,
                'addr':addr,
                'info':info,
                'tel_num':tel,
                'sex':sex,
                'avatar_url':r['url']
            }
            u_p = mdb_user.db.user_profile.find_one({'user_id':current_user.id})
            if u_p:
                if not 'default' in u_p['avatar_url']['key']:
                    img_del(u_p['avatar_url'])
        flash({'msg':'头像更改成功,2秒后更新!.','type':'s'})
    else:
        user_profile = {
            'username':username,
            'addr':addr,
            'info':info,
            'tel_num':tel,
            'sex':sex
            }

    mdb_user.db.user.update({"_id":current_user.id}, {"$set":{"username":username}})
    if domain:
        user_profile['user_domain'] = domain
        user.domain = domain
    mdb_user.db.user_profile.update({'user_id':current_user.id}, {'$set':user_profile})
    flash({'msg':'信息修改成功哦.','type':'s'})

    return _data
Example #5
0
def edit_img(id):

    view_data = {'op_type': 'edit', 'title': '编辑图片信息'}
    form = EditImgForm()
    view_data['img'] = mdb_sys.db.img.find_one_or_404({'_id': ObjectId(id)})
    if form.submit.data:
        if not form.name.data.strip():
            flash({'type': 'w', 'msg': '名字不能为空!'})
        else:
            uploaded_files = request.files.getlist("img")
            bucket_name = {
                'b': app_config['upload'].IMG_B,
                'domain': 'img',
                'project': form.project.data
            }

            if uploaded_files[0]:
                img_del(view_data['img']['url'])
            r = img_up(uploaded_files,
                       bucket_name,
                       new_name=form.name.data.strip())
            if r['url'] != -1 and r['url'] != 1:
                img_profile = {
                    'url': r['url'],
                    'time': time.time(),
                    'name': form.name.data.strip(),
                    'showname': form.showname.data.strip(),
                    'info': form.info.data,
                    'link': form.link.data.strip()
                }
                mdb_sys.db.img.update({'_id': ObjectId(id)},
                                      {'$set': img_profile})
                flash({'msg': '成功.', 'type': 's'})

            else:
                url = view_data['img']['url']
                if form.name.data.strip() != view_data['img']['name']:
                    new_url = img_rename(url, form.name.data.strip())
                else:
                    new_url = url
                img_profile = {
                    'url': new_url,
                    'time': time.time(),
                    'name': form.name.data.strip(),
                    'showname': form.showname.data.strip(),
                    'info': form.info.data,
                    'link': form.link.data.strip()
                }
                mdb_sys.db.img.update({'_id': ObjectId(id)},
                                      {'$set': img_profile})

            return redirect(
                url_for('media.image', project=view_data['img']['type']))

    form.name.data = view_data['img']['name']
    form.project.data = view_data['img']['type']
    form.showname.data = view_data['img']['showname']
    form.info.data = view_data['img']['info']
    form.link.data = view_data['img']['link']
    return render_template('{}/media/image/add_img.html'.format(
        Theme.ADM_THEME_NAME),
                           form=form,
                           view_data=view_data)