Example #1
0
def delete_travel(travel_id):
    travel = Travels.query.get_or_404(travel_id)
    db.session.delete(travel)
    db.session.commit()
    flash('游记已删除', 'info')
    push_delete_notification(current_user, travel)
    return redirect_back()
Example #2
0
def unfollow(username):
    user = User.query.filter_by(username=username).first_or_404()
    if not current_user.is_following(user):
        flash('还未关注此用户.', 'info')
        return redirect(url_for('user.index', username=username))

    current_user.unfollow(user)
    flash('取消关注成功.', 'info')
    return redirect_back()
Example #3
0
def follow(username):
    user = User.query.filter_by(username=username).first_or_404()
    if current_user.is_following(user):
        flash('已关注过此用户.', 'info')
        return redirect(url_for('user.index', username=username))

    current_user.follow(user)
    flash('关注成功.', 'success')
    if user.receive_follow_notification:
        push_follow_notification(follower=current_user, receiver=user)
    return redirect_back()
Example #4
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user is not None and user.validate_password(form.password.data):
            if login_user(user, form.remember_me.data):
                flash('登录成功', 'info')
                return redirect_back()
            else:
                flash('你的账号已被封禁', 'warning')
                return redirect(url_for('auth.login'))
        flash('邮箱或密码错误', 'warning')
    return render_template('auth/login.html', form=form)
Example #5
0
def search():
    q = request.args.get('q', '')
    if q == '':
        flash('请输入查询信息', 'warning')
        return redirect_back()

    order_rule = request.args.get('order_rule', 'search_travels')
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['MEITU_TRAVELS_USER_PER_PAGE']
    if order_rule == 'search_travels':
        pagination = Travels.query.whooshee_search(q).paginate(page, per_page)
        order_rule = 'search_travels'
    elif order_rule == 'search_users':
        pagination = User.query.whooshee_search(q).paginate(page, per_page)
        order_rule = 'search_users'
    else:
        pagination = Tag.query.whooshee_search(q).paginate(page, per_page)
        order_rule = 'search_tags'
    results = pagination.items

    return render_template('main/search.html', results=results, pagination=pagination, order_rule=order_rule, q=q)
Example #6
0
def unlock_user(user_id):
    user = User.query.get_or_404(user_id)
    user.unlock()
    flash('用户已解锁', 'info')
    return redirect_back()
Example #7
0
def delete_tag(tag_id):
    tag = Tag.query.get_or_404(tag_id)
    db.session.delete(tag)
    db.session.commit()
    flash('Tag deleted.', 'info')
    return redirect_back()