Beispiel #1
0
def user_detail(id):
    u = User.find(id)
    if u is None:
        abort(404)
    else:
        token = new_csrf_token()
        return render_template('user/user_detail.html', user=u, token=token)
Beispiel #2
0
def profile():
    u = current_user()
    token = new_csrf_token()
    if u is None:
        return redirect(url_for('.index'))
    else:
        return render_template('profile.html', user=u, token=token)
Beispiel #3
0
def detail(id):
    t = Topic.get(id)
    if t is not None:
        token = new_csrf_token()
        return render_template("topic/detail.html", topic=t, token=token)
    else:
        return abort(404)
Beispiel #4
0
def user_setting():
    token = new_csrf_token()
    u = current_user()
    if u is None:
        abort(404)
    else:
        return render_template('user_setting.html', user=u, token=token)
Beispiel #5
0
def send_back():
    """用于回复私信"""
    receiver_id = request.args.get('receiver_id')
    token = new_csrf_token()
    u = current_user()
    receiver = cached_user_id2user(receiver_id)
    return render_template('mail/reply_page.html', user=u, token=token, receiver=receiver)
Beispiel #6
0
def login_view():
    u = current_user()
    token = new_csrf_token()
    return render_template('routes_user/user_login.html',
                           u=u,
                           message='',
                           token=token)
Beispiel #7
0
def index(request):
    """
    todo 首页的路由函数
    """
    u = current_user(request)
    todos = Todo.all(user_id=u.id)
    token = new_csrf_token(request)
    return html_response('todo_index.html', todos=todos, token=token)
Beispiel #8
0
def new():
    u = current_user()
    boards = Board.all()
    token = new_csrf_token()
    return render_template('routes_blog/blog_new.html',
                           u=u,
                           boards=boards,
                           token=token)
Beispiel #9
0
def setting():
    u = current_user()
    if u is None:
        flash('请先登录')
        return (redirect(url_for('index.index')))
    else:
        token = new_csrf_token()
        return render_template('user/setting.html', user=u, token=token)
Beispiel #10
0
def login_view():
    user = current_user()

    if user.username != '游客':
        return redirect(url_for('public.index'))

    token = new_csrf_token()
    return render_template('user/login.html', token=token)
Beispiel #11
0
def register_view():
    user = current_user()

    if user.username != '游客':
        return redirect('/')

    token = new_csrf_token()
    return render_template('user/register.html', token=token)
Beispiel #12
0
def new():
    u = current_user()
    board_id = int(request.args.get('board_id'))
    bs = Board.all()
    token = new_csrf_token()
    return render_template("topic/new.html",
                           bs=bs,
                           bid=board_id,
                           token=token,
                           u=u)
Beispiel #13
0
def edit():
    id = int(request.args.get('id'))
    topic = Topic.find(id)
    board_id = int(request.args.get('board_id', -1))
    token = new_csrf_token()
    bs = Board.all()
    return render_template('topic/edit.html',
                           topic=topic,
                           bs=bs,
                           token=token,
                           bid=board_id)
Beispiel #14
0
def index():
    u = current_user()
    board_id = int(request.args.get('board_id', -1))
    if board_id == -1:
        ms = Topic.all()
    else:
        ms = Topic.all(board_id=board_id)
    ms.sort(key=lambda ms: ms.created_time, reverse=True)
    token = new_csrf_token()
    bs = Board.all()
    return render_template("index.html", user=u, ms=ms, token=token, bs=bs, bid=board_id)
Beispiel #15
0
def detail(blog_id):
    u = current_user()
    b = Blog.find(blog_id)
    Blog.get(blog_id)
    v = b.user()
    token = new_csrf_token()
    return render_template('routes_blog/blog_detail.html',
                           blog=b,
                           u=u,
                           v=v,
                           token=token)
Beispiel #16
0
def reset_view():
    token = request.args["token"]
    key = "csrf_token_{}".format(token)
    if cache.exists(key):
        user_id = cache.get(key)
        cache.delete(key)
        user = User.one(id=user_id)
        token = new_csrf_token(user)
        return render_template('reset.html', token=token, user=user)
    else:
        return abort(401)
Beispiel #17
0
def login():
    form = request.form
    u, message = User.login(form)
    if u.is_guest():
        token = new_csrf_token()
        return render_template('routes_user/user_login.html',
                               u=u,
                               message=message,
                               token=token)
    else:
        session['user_id'] = u.id
        return redirect(url_for('routes_blog.index'))
Beispiel #18
0
def index():
    u = current_user()
    token = new_csrf_token()

    recv = Messages.newest_n(3, receiver_id=u.id)
    t = render_template(
        'mail/index.html',
        user=u,
        token=token,
        received=recv,
    )
    return t
Beispiel #19
0
def new():
    """进入新建Topic的编辑页面"""
    current_bid = int(request.args.get('board_id', -1))
    token = new_csrf_token()
    u = current_user()
    bs = Board.all()
    return render_template("topic/new.html",
                           token=token,
                           user=u,
                           current_bid=current_bid,
                           bs=bs
                           )
Beispiel #20
0
def index():
    board_id = int(request.args.get('board_id', -1))
    if board_id == -1:
        ms = Topic.all()
    else:
        ms = Topic.find_all(board_id=board_id)
    token = new_csrf_token()
    bs = Board.all()
    return render_template('index.html',
                           ms=ms,
                           token=token,
                           bs=bs,
                           bid=board_id)
Beispiel #21
0
def index():
    u = current_user()

    sent_mail = Mail.all(sender_id=u.id)
    received_mail = Mail.all(receiver_id=u.id)

    token = new_csrf_token()
    t = render_template(
        'mail/index.html',
        send=sent_mail,
        received=received_mail,
        token=token,
    )
    return t
Beispiel #22
0
def detail(username):
    u = User.one(username=username)
    t = Topic.recent_created_topics(u)
    t2 = Topic.recent_join_topics(u)
    token = new_csrf_token()

    if u is None:
        abort(404)
    else:
        return render_template('user/detail.html',
                               user=u,
                               ms=t,
                               ms2=t2,
                               token=token)
Beispiel #23
0
def change_password():
    # 发送 token
    print('running setting route')
    u = current_user()
    if u is None:
        return redirect(url_for('.index'))
    else:
        token = new_csrf_token()
        log('send csrf token: <{}>'.format(token))
        return render_template(
            'user/change_password.html',
            user=u,
            token=token,
        )
Beispiel #24
0
def register():
    if request.method == 'GET':
        token = new_csrf_token()
        return render_template('user/register.html',
                               token=token,
                               data=weibo_oauth)
    else:
        form = request.form
        if User.validate_register(form):
            flash('注册成功')
            return redirect(url_for('.login'))
        else:
            flash('注册失败')
            return redirect(url_for('.register'))
Beispiel #25
0
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)
    bs = Board.all()
    u = current_user()
    token = new_csrf_token()
    return render_template("topic/index.html",
                           ms=ms,
                           token=token,
                           u=u,
                           bs=bs,
                           bid=board_id)
Beispiel #26
0
def login():
    if request.method == 'GET':
        token = new_csrf_token()
        return render_template('user/login.html',
                               token=token,
                               data=weibo_oauth)
    else:
        form = request.form
        u = User.validate_login(form)
        if u is not None:
            session['user_id'] = u.id
            return redirect(url_for('.index'))
        else:
            flash('用户名或密码有误')
            return redirect(url_for('.login'))
Beispiel #27
0
def info():
    """系统通知主页,查看所有系统通知"""
    user = current_user()
    all_info = cached_received_info(user.id)

    unread_info = [i for i in all_info if not i.been_read]
    been_read_info = [i for i in all_info if i.been_read]
    token = new_csrf_token()
    return render_template(
        "info/info.html",
        user=user,
        token=token,
        unread=unread_info,
        been_read=been_read_info,
    )
Beispiel #28
0
def reset_send():
    form = request.form.to_dict()
    # 生成 token
    token: Dict = new_csrf_token()
    log('reset send token', token)
    # 生成 url
    content = 'http://{}/reset/view?token={}'.format(request.host, token)
    # 发送邮件
    receiver: User = User.one(username=form['username'])
    send_mail(
        subject='[www.dviii.com] 重置密码',
        author=admin_mail,
        to=receiver.email,
        content='站内信通知:\n {}'.format(content),
    )
    return redirect(url_for('.index'))
Beispiel #29
0
def edit(topic_id):
    """进入话题编辑页面的get请求"""
    # old_topic: Topic = Topic.one(id=id)
    old_topic: Topic = cached_topic_id2topic(topic_id)
    token = new_csrf_token()
    u = current_user()
    all_borads = Board.all()

    if u.id != old_topic.user_id:
        return abort(404)

    return render_template("topic/edit.html",
                           token=token,
                           user=u,
                           current_bid=old_topic.board_id,
                           bs=all_borads,
                           old_topic=old_topic,
                           )
Beispiel #30
0
def send_email():
    username = request.form['username']
    u = User.one(username=username)
    if u is None:
        flash('用户名不存在!')
        return redirect(url_for('.index'))
    if u.email == '暂无邮箱':
        flash('此用户尚未绑定邮箱!')
        return redirect(url_for('.index'))
    token = new_csrf_token(u)
    Message.send(
        title='frost论坛重置密码',
        content='http://{}/forget/reset?token={}'.format(server_ip, token),
        sender_id=0,
        receiver_id=u.id
    )
    flash('重置密码链接已发送至该用户名绑定邮箱!')
    return redirect(url_for('.index'))