コード例 #1
0
ファイル: reply.py プロジェクト: TeamoSCSC/Anfield
def add():
    form = request.form
    u = current_user()

    content = form['content']
    users = users_from_content(content)
    send_mails(u, users, request.referrer, content)

    form = request.form.to_dict()
    u = current_user()
    print('DEBUG', form)
    m = Reply.add(form, user_id=u.id)
    return redirect(url_for('route_topic.detail', id=m.topic_id))
コード例 #2
0
ファイル: reply.py プロジェクト: lilunqin/llqClub
def add():
    form = request.form.to_dict()

    u = current_user()
    print('DEBUG', form)
    m = Reply.new(form, user_id=u.id)
    return redirect(url_for('topic.detail', id=m.topic_id))
コード例 #3
0
def detail(id):
    m = Topic.get(id)
    u = current_user()
    c = 'n'  # 未收藏
    if Collect.one(topic_id=m.id, user_id=u.id) is not None:
        c = 'c'
    return render_template("topic/detail.html", topic=m, u=u, c=c)
コード例 #4
0
def collect_delete(id):
    m = Topic.get(id)
    u = current_user()
    collect_item = Collect.one(topic_id=m.id, user_id=u.id)
    Collect.delete(collect_item.id)
    c = 'n'
    return render_template("topic/detail.html", topic=m, u=u, c=c)
コード例 #5
0
def add(request):
    # 得到浏览器发送的表单, 浏览器用 ajax 发送 json 格式的数据过来
    # 所以这里用json 函数来获取格式化后的 json 数据
    form = request.json()
    u = current_user(request)
    t = Todo.add(form, u.id)
    return json_response(t.json())
コード例 #6
0
def add():
    form = request.form.to_dict()
    form['receiver_id'] = int(form['receiver_id'])
    u = current_user()
    form['sender_id'] = u.id
    m = Messages.new(form)
    return redirect(url_for('.index'))
コード例 #7
0
def current_user_detail():
    u: User = current_user()
    if u is None:
        abort(404)
    else:
        data = u.get_detail()
        return response(data=data, status=status.HTTP_200_OK)
コード例 #8
0
ファイル: index.py プロジェクト: lilunqin/llqClub
def avatar_add():
    file: FileStorage = request.files['avatar']
    log('fileaaa', file)
    # file = request.files['avatar']
    # filename = file.filename
    # 用户上传数据过滤
    # ../../root/.ssh/authorized_keys
    # images/../../root/.ssh/authorized_keys
    # flask 的处理方法
    # filename = secure_filename(file.filename)
    suffix = file.filename.split('.')[-1]
    if suffix not in ['gif', 'jpg', 'jpeg', 'png']:
        abort(400)
        log('不接受的后缀, {}'.format(suffix))
    else:
        filename = '{}.{}'.format(str(uuid.uuid4()), suffix)
        path = os.path.join('images', filename)
        # path = 'images/' + filename
        log('tupianpath', path)
        file.save(path)
        log('save成功', path)
        u = current_user()
        User.update(u.id, image='/images/{}'.format(filename))

        return redirect(url_for('.profile'))
コード例 #9
0
ファイル: routes_public.py プロジェクト: LiRuiPan/simiweb
def index(request):
    """
    主页的处理函数, 返回主页的响应
    """
    u = current_user(request)
    body = template('index.html', username=u.username)
    return html_response(body)
コード例 #10
0
ファイル: index.py プロジェクト: LiRuiPan/forum
def index():
    u = current_user()
    if u is None:
        result = request.args.get('result', ' ')
        c = Captcha.get()
        return render_template("user/login.html", path=c.path, cap_id=c.id, result=result)
    else:
        return redirect(url_for('topic.index'))
コード例 #11
0
def view(id):
    message = Messages.one(id=id)
    u = current_user()
    # if u.id == mail.receiver_id or u.id == mail.sender_id:
    if u.id in [message.receiver_id, message.sender_id]:
        return render_template('mail/detail.html', message=message)
    else:
        return redirect(url_for('.index'))
コード例 #12
0
ファイル: reply.py プロジェクト: TeamoSCSC/Anfield
def delete():
    u = current_user()
    topic = Topic.one(id=int(request.args['topic_id']))
    reply = Reply.one(id=int(request.args['reply_id']))
    if u.id == int(topic.user_id) or u.id == int(reply.user_id):
        Reply.delete(reply.id)
        return redirect(url_for('route_topic.detail', id=topic.id))
    else:
        return abort(Response('您无权进行此操作'))
コード例 #13
0
def edit_password():
    u = current_user()
    key = 'user_id_{}'.format(u.id)
    form = request.form.to_dict()
    print('password', User.salted_password(form['old_pass']), u.password)
    if User.salted_password(form['old_pass']) == u.password and len(form['new_pass']) > 2:
        User.update(u.id, password=User.salted_password(form['new_pass']))
        cache.delete(key)
    return render_template("edit.html", user=u)
コード例 #14
0
def my_collect():
    u = current_user()
    token = new_csrf_token()
    bs = Board.all()
    t = Collect.all(user_id=u.id)
    l = []
    for c in t:
        l.append(Topic.one(id=c.topic_id))

    return render_template("topic/collect.html", u=u, ms=l, bs=bs, token=token)
コード例 #15
0
def new():
    board_id = int(request.args.get('board_id'))
    bs = Board.all()
    user = current_user()
    token = new_csrf_token()
    return render_template("topic/new.html",
                           bs=bs,
                           bid=board_id,
                           user=user,
                           token=token)
コード例 #16
0
def write():
    receiver_id = int(request.args['id'])
    r: User = User.one(id=receiver_id)
    if r.receive_message is False:
        result = '对方不接受私信'
        return redirect(url_for('index.user_detail', id=r.id, result=result))
    else:
        u = current_user()
        token = new_csrf_token()
        return render_template('mail/write.html', r=r, user=u, token=token)
コード例 #17
0
def profile():
    u = current_user()
    if u is None:
        return redirect(url_for('.index'))
    else:
        ts = topic_all(u.id)
        t_join = topic_join_all(u.id)
        return render_template('profile.html',
                               user=u,
                               topic=ts,
                               topic_join=t_join)
コード例 #18
0
ファイル: routes_user.py プロジェクト: LiRuiPan/simiweb
def login_view(request):
    u = current_user(request)
    result = request.query.get('result', ' ')
    result = unquote_plus(result)

    body = template(
        'login.html',
        username=u.username,
        result=result,
    )
    return html_response(body)
コード例 #19
0
def index():
    # todo:add csrfCheck
    board_id = int(request.args.get('board_id', -1))
    if board_id == -1:
        ms = Topic.all()
    else:
        ms = Topic.all(board_id=board_id)
    token = new_csrf_token()
    bs = Board.all()
    u = current_user()
    return render_template("topic/index.html", u=u, ms=ms, bs=bs, bid=board_id, token=token)
コード例 #20
0
ファイル: topic.py プロジェクト: lilunqin/llqClub
def delete():
    u = current_user()

    # token = request.args['token']
    # user_id = csrf_tokens[token]
    # assert user_id == u.id

    id = int(request.args['id'])
    print('删除 topic 用户是', u, id)
    Topic.delete(id)
    return redirect(url_for('.index'))
コード例 #21
0
def delete():
    reply_id = request.args['reply_id']
    r = Reply.one(id=reply_id)
    topic_id = r.topic_id
    u = current_user()
    if u.id == r.user_id or u.role == 'admin':
        Reply.delete(id=reply_id)
        r = '删除评论成功'
        return redirect(url_for('topic.detail', id=topic_id, result=r))
    else:
        r = '没有权限'
        return redirect(url_for('topic.detail', id=topic_id, result=r))
コード例 #22
0
def add():
    form = request.form.to_dict()
    u = current_user()
    receiver_id = int(form['receiver_id'])
    # receiver_username = User.one(id=receiver_id)
    # 发邮件
    Messages.send(title=form['title'],
                  content=form['content'],
                  sender_id=u.id,
                  receiver_id=receiver_id)

    return redirect(url_for('.index'))
コード例 #23
0
ファイル: user.py プロジェクト: thelajiest/BBS
def photo():
    form: FileStorage = request.form.to_dict()
    file = request.files['photo']
    suffix = file.filename.split('.')[-1]
    filename = '{}.{}'.format(str(uuid.uuid4()), suffix)
    path = os.path.join('images', filename)
    file.save(path)
    form['img'] = '/' + path

    u = current_user()
    User.img_update(u.id, **form)
    return render_template("user/edit.html", user=u, m='t')
コード例 #24
0
def index():
    u = current_user()

    send = Messages.all(sender_id=u.id)
    received = Messages.all(receiver_id=u.id)

    t = render_template(
        'mail/index.html',
        send=send,
        received=received,
    )
    return t
コード例 #25
0
def index():
    # l=level C:Country c:City p:Province
    # t=time UpdateTime(String)
    # n=name Country/City/Province name
    # d=data 一个数据类组成的列表
    statis_data = ChinaStatus.one(province='all')
    chart_data_list = ChinaStatus.top(name='confirm', num=8, city='all')
    time = statis_data.updateTime
    name = '中国'
    u = current_user()
    return render_template('./dashboard/statis.html', l='C', n=name, t=time, sd=statis_data, u=u,
                           cd=chart_data_list)
コード例 #26
0
ファイル: topic.py プロジェクト: LiRuiPan/forum
def index():
    board_id = int(request.args.get('board_id', -1))
    if board_id == -1:
        ms = Topic.all()
    else:
        ms = Topic.all(board_id=board_id)
    u = current_user()
    bs = Board.all()
    return render_template("topic/index.html",
                           user=u,
                           bs=bs,
                           ms=ms,
                           bid=board_id)
コード例 #27
0
def avatar_add():
    file: FileStorage = request.files['avatar']
    suffix = file.filename.split('.')[-1]
    filename = '{}.{}'.format(str(uuid.uuid4()), suffix)
    path = os.path.join('images', filename)
    file.save(path)

    u = current_user()
    User.update(u.id, image='/images/{}'.format(filename))
    key = 'user_id_{}'.format(u.id)
    cache.delete(key)

    return redirect(url_for('personal.edit', id=u.id))
コード例 #28
0
def index():
    u = current_user()
    unread = Messages.all(receiver_id=u.id, read=False)
    reads = Messages.all(receiver_id=u.id, read=True)
    sends = Messages.all(sender_id=u.id)
    token = new_csrf_token()
    t = render_template('mail/index.html',
                        user=u,
                        unread=unread,
                        read=reads,
                        sends=sends,
                        token=token)
    return t
コード例 #29
0
def delete_topic():
    topic_title = request.form['title']
    t = Topic.one(title=topic_title)
    topic_id = t.id
    user_id = t.user_id
    content = '您的帖子《{}》已被管理员删除'.format(t.title)
    form = dict(receiver_id=user_id,
                sender_id=current_user().id,
                content=content)
    Messages.new(form)
    Topic.delete(id=topic_id)
    Reply.delete(topic_id=topic_id)
    return redirect(url_for('.index'))
コード例 #30
0
def statis(name):
    # 提供国内的省级/国外的国家级数据查询
    typename = Country.one(name=name)
    typename = typename.APIType
    if typename == 'basic':
        data = ChinaStatus.one(province=name)
    elif typename == 'foreign':
        data = GlobalStatus.one(country=name)
    time = data.updateTime
    statis_data = data
    u = current_user()
    return render_template('./dashboard/statis.html', l='p', n=name, t=time, sd=statis_data, u=u,
                           cd=statis_data)