Beispiel #1
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.bio = form.bio.data
        user.website = form.website.data
        user.confirmed = form.confirmed.data
        user.active = form.active.data
        user.location = form.location.data
        user.username = form.username.data
        user.email = form.email.data
        db.session.commit()
        flash('Profile updated.', 'success')
        return redirect_back()
    form.name.data = user.name
    form.role.data = user.role_id
    form.bio.data = user.bio
    form.website.data = user.website
    form.location.data = user.location
    form.username.data = user.username
    form.email.data = user.email
    form.confirmed.data = user.confirmed
    form.active.data = user.active
    return render_template('admin/edit_profile.html', form=form, user=user)
Beispiel #2
0
def lock_user(user_id):
    user = User.query.get_or_404(user_id)
    if user.role.name in ['Administrator', 'Moderator']:
        flash(_('Доступ запрещен.'), 'warning')
    else:
        user.lock()
        flash(_('Аккаунт закрыт.'), 'info')
    return redirect_back()
Beispiel #3
0
def lock_user(user_id):
    user = User.query.get_or_404(user_id)
    if user.role.name in ['Administrator', 'Moderator']:
        flash('Permission denied.', 'warning')
    else:
        user.lock()
        flash('Account locked.', 'info')
    return redirect_back()
Beispiel #4
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('.index', username=username))

    current_user.unfollow(user)
    flash(_('Вы отписались от пользователя.'), 'info')
    return redirect_back()
Beispiel #5
0
def re_authenticate():
    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 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('.index', username=username))

    current_user.unfollow(user)
    flash('Подписка на пользователя отменена', 'info')
    return redirect_back()
Beispiel #7
0
def unfollow(username):
    user = User.query.filter_by(username=username).first_or_404()
    if not current_user.is_following(user):
        flash(_l('Not follow yet.'), 'info')
        return redirect(url_for('.index', username=username))

    current_user.unfollow(user)
    flash(_l('User unfollowed.'), 'info')
    return redirect_back()
Beispiel #8
0
def follow(username):
    user = User.query.filter_by(username=username).first_or_404()
    if current_user.is_following(user):
        flash(_l('Already followed.'), 'info')
        return redirect(url_for('.index', username=username))

    current_user.follow(user)
    flash(_l('User followed.'), 'success')
    if user.receive_follow_notification:
        push_follow_notification(follower=current_user, receiver=user)
    return redirect_back()
Beispiel #9
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('.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()
Beispiel #10
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('Login success.', 'info')
                return redirect_back()
            else:
                flash('Your account is blocked.', 'warning')
                return redirect(url_for('main.index'))
        flash('Invalid email or password.', 'warning')
    return render_template('auth/login.html', form=form)
Beispiel #11
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(_('Неверный email или пароль.'), 'warning')
    return render_template('auth/login.html', form=form)
Beispiel #12
0
def search():
    q = request.args.get('q', '').strip()
    if q == '':
        flash(_l('Enter keyword about photo, user or tag.'), 'warning')
        return redirect_back()

    category = request.args.get('category', 'photo')
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['VSHAURME_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, results=results, pagination=pagination, category=category)
Beispiel #13
0
def search():
    q = request.args.get('q', '').strip()
    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['VSHAURME_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, results=results, pagination=pagination, category=category)
Beispiel #14
0
def unblock_user(user_id):
    user = User.query.get_or_404(user_id)
    user.unblock()
    flash('Block canceled.', 'info')
    return redirect_back()
Beispiel #15
0
def unblock_user(user_id):
    user = User.query.get_or_404(user_id)
    user.unblock()
    flash('Блокировка отменена', 'info')
    return redirect_back()
Beispiel #16
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 #17
0
def unlock_user(user_id):
    user = User.query.get_or_404(user_id)
    user.unlock()
    flash('Профиль открыт', 'info')
    return redirect_back()
Beispiel #18
0
def unlock_user(user_id):
    user = User.query.get_or_404(user_id)
    user.unlock()
    flash(_('Аккаут открыт.'), 'info')
    return redirect_back()
Beispiel #19
0
def unblock_user(user_id):
    user = User.query.get_or_404(user_id)
    user.unblock()
    flash(_('Аккаунт разблокирован.'), 'info')
    return redirect_back()
Beispiel #20
0
def delete_tag(tag_id):
    tag = Tag.query.get_or_404(tag_id)
    db.session.delete(tag)
    db.session.commit()
    flash(_('Тег удален.'), 'info')
    return redirect_back()