Beispiel #1
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()
Beispiel #2
0
def edit_profile_admin(user_id):
    """管理员编辑用户资料"""
    user = User.query.get_or_404(user_id)
    form = EditProfileAdminForm(user=user)  # 传入被修改的用户对象作为参数
    if form.validate_on_submit():
        user.name = form.name.data
        role = Role.query.get(form.role.data)
        if role.name == 'Locked':
            user.lock()
        user.role = role
        user.username = form.username.data
        user.email = form.email.data
        user.website = form.website.data
        user.location = form.location.data
        user.bio = form.bio.data
        user.active = form.active.data
        user.confirmed = form.confirmed.data
        db.session.commit()
        flash('更新', 'success')
        return redirect_back()
    form.name.data = user.name
    form.role.data = user.role_id
    form.username.data = user.username
    form.email.data = user.email
    form.website.data = user.website
    form.location.data = user.location
    form.bio.data = user.bio
    form.active.data = user.active
    form.confirmed.data = user.confirmed
    return render_template('admin/edit_profile.html', form=form, user=user)
Beispiel #3
0
def unfollow(username):
    """取消关注"""
    user = User.query.filter_by(username=username).first_or_404()
    if not current_user.is_followed(user):
        flash('没有关注他', 'info')
        return redirect(url_for('user.index', username=username))
    current_user.unfollow(user)
    return redirect_back()
Beispiel #4
0
def uncollect(photo_id):
    """取消收藏"""
    photo = Photo.query.get_or_404(photo_id)
    if not current_user.is_collecting(photo):
        flash('没有收藏过图片.', 'info')
        return redirect(url_for('main.show_photo', photo_id=photo_id))

    current_user.uncollect(photo)
    return redirect_back()
Beispiel #5
0
def re_authenticate():
    """当用户‘不新鲜’时访问带@fresh_login_required的视图时,重新认证"""
    if login_fresh():
        return redirect(url_for('main.index'))
    form = LoginForm()
    if form.validate_on_submit() and current_user.validate_password(
            form.password.data):
        confirm_login()
        return redirect_back()
    return render_template('auth/login.html', form=form)
Beispiel #6
0
def follow(username):
    """关注"""
    user = User.query.filter_by(username=username).first_or_404()
    if current_user.is_followed(user):
        flash('已经关注过', 'info')
        return redirect(url_for('user.index', username=username))
    current_user.follow(user)
    if user.receive_follow_notification:
        push_follow_notification(follower=current_user, receiver=user)
    return redirect_back()
Beispiel #7
0
def collect(photo_id):
    """收藏"""
    photo = Photo.query.get_or_404(photo_id)
    if current_user.is_collecting(photo):
        flash('图片已经收藏过.', 'info')
        return redirect(url_for('main.show_photo', photo_id=photo_id))

    current_user.collect(photo)
    if current_user != photo.author and photo.author.receive_collect_notification:
        push_collect_notification(collector=current_user,
                                  photo_id=photo_id,
                                  receiver=photo.author)
    return redirect_back()
Beispiel #8
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('main.index'))
        flash('无效的邮箱或者密码.', 'warning')
    return render_template('auth/login.html', form=form)
Beispiel #9
0
def search():
    """搜索"""
    q = request.args.get('q', '')
    if q == '':
        flash('请输入与图片、标签或者用户相关的信息', 'warning')
        return redirect_back()

    category = request.args.get('category', 'photo')
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['PHOTOSOCIAL_SEARCH_RESULT_PER_PAGE']
    if category == 'user':
        pagination = User.query.whooshee_search(q).paginate(page, per_page)
    elif category == 'tag':
        pagination = Tag.query.whooshee_search(q).paginate(page, per_page)
    else:
        pagination = Photo.query.whooshee_search(q).paginate(page, per_page)
    results = pagination.items
    return render_template('main/search.html',
                           q=q,
                           pagination=pagination,
                           results=results,
                           category=category)
Beispiel #10
0
def unblock_user(user_id):
    """解除用户封禁"""
    user = User.query.get_or_404(user_id)
    user.unblock()
    flash('用户封禁已解除', 'info')
    return redirect_back()
Beispiel #11
0
def block_user(user_id):
    """封禁用户"""
    user = User.query.get_or_404(user_id)
    user.block()
    flash('用户已封禁', 'info')
    return redirect_back()
Beispiel #12
0
def unlock_user(user_id):
    """解除用户锁定"""
    user = User.query.get_or_404(user_id)
    user.unlock()
    flash('该用户锁定解除', 'info')
    return redirect_back()
Beispiel #13
0
def lock_user(user_id):
    """用户锁定"""
    user = User.query.get_or_404(user_id)
    user.lock()
    flash('该用户已锁定', 'info')
    return redirect_back()