Beispiel #1
0
def group(groupid):
    if not(is_authenticated()):
        flash('Sorry, you are not logged in. Please login to continue')
        return redirect(url_for('auth.login'))
    if not(GroupMembers.query.filter_by(member_id=current_user.id).filter_by(group_id=groupid).all()):
        return render_template('errors/404.html'), 404
    user=get_current_user()
    group=get_group(groupid)
    if not(group):
        return render_template('errors/404.html'), 404
    page = request.args.get('page', 1, type=int)
    group=GroupTable.query.filter_by(id=groupid).first()
    if(GroupMembers.query.filter_by(group_id=group.id,member_id=user.id).order_by(Message.message_time.desc())):
        messages=Message.query.filter_by(group_id=group.id).order_by(Message.message_time.desc()).paginate(page,3,False)
        form=MessageForm()
        if form.validate_on_submit():
            create_message(form,groupid,user=user)
            return redirect(url_for('dashboard.group',groupid=groupid))
        next_url = url_for('dashboard.group', page=messages.next_num,groupid=groupid) \
        if messages.has_next else None
        prev_url = url_for('dashboard.group', page=messages.prev_num,groupid=groupid) \
        if messages.has_prev else None
        return render_template('dashboard/messages.html',group=group.id,username=user.username,title=group.groupname,messages=messages.items,form=MessageForm(),groupname=group.groupname,groupdescription=group.group_description,groupid=groupid,next_url=next_url,prev_url=prev_url)
    else:
        flash('Sorry, this group is not found')
        return redirect(url_for('auth.login'))
Beispiel #2
0
def search():
    if not (is_authenticated()):
        flash('Sorry you are not logged in. Login to continue')
        return redirect(url_for('auth.login'))
    if not g.search_form.validate():
        return redirect(url_for('dashboard.dashboard'))
    if not (elasticsearch):
        flash("Search is not available now.")
        return redirect(url_for('dashboard.dashboard'))
    groups, total_groups = query_index('group_table', g.search_form.q.data, 1,
                                       5)
    messages, total_message = query_index('message', g.search_form.q.data, 1,
                                          5)
    users, total_users = query_index('user_table', g.search_form.q.data, 1, 5)
    current_user_group_id = get_list_of_group_id()
    groups_searched = []
    for group in groups:
        if (group in current_user_group_id):
            groups_searched.append(
                GroupTable.query.filter_by(id=group).first())
    users_searched = []
    for user in users:
        users_searched.append(UserTable.query.filter_by(id=user).first())
    message_searched = []
    for message in messages:
        if (Message.query.filter_by(
                id=message).first().user_id == current_user.id):
            message_searched.append(
                Message.query.filter_by(id=message).first())
    return render_template('search.html',
                           title='Search',
                           users=users_searched,
                           groups=groups_searched,
                           messages=message_searched)
Beispiel #3
0
def dashboard():
    if is_authenticated():
        groups,username=get_list_of_groups()
        return render_template('dashboard/dashboard.html',groups=groups,username=username)
    else:
        flash('Sorry, you are not logged in. Please login to continue.')
        return redirect(url_for('auth.login'))
Beispiel #4
0
def download(task_id):
    if not (is_authenticated()):
        return 'Not Logged In'
    res = download_chat.AsyncResult(task_id=task_id)
    if (res.status == 'PENDING'):
        return 'wait'
    if (res.status == 'SUCCESS'):
        return res.result
Beispiel #5
0
def download_content(group_id, task_id):
    if not (is_authenticated()):
        return 'Not Logged In'
    if not (GroupTable.query.filter_by(id=group_id).first().admin_id
            == current_user.id):
        return 'Unauthorised Action'
    download_object = download_chat.apply_async(
        args=[group_id, current_user.id])
    return download_object.task_id
Beispiel #6
0
def user(username):
    if not(is_authenticated()):
        flash('Sorry, you are not logged in. Please login to continue')
        return redirect(url_for('auth.login'))
    user=UserTable.query.filter_by(username=username).first()
    if not(user):
        flash('Sorry user is not found')
        return redirect(url_for('dashboard.dashboard'))
    return render_template('dashboard/user.html',user=user)
Beispiel #7
0
def deletegroup(groupid):
    if not(is_authenticated()):
        flash('Sorry, you are not logged in. Please login to continue')
        return redirect(url_for('auth.login'))
    if(GroupTable.query.filter_by(id=groupid).first().admin_id !=current_user.id):
        flash('Unauthorised action')
        return redirect(url_for('dashboard.dashboard'))
    groupname=delete_group(groupid)
    flash('You deleted the group "'+groupname+'"')
    return redirect(url_for('dashboard.dashboard'))
Beispiel #8
0
def leavegroup(groupid):
    if not(is_authenticated()):
        flash('Sorry, you are not logged in. Please login to continue')
        return redirect(url_for('auth.login'))
    if(GroupTable.query.filter_by(id=groupid).first().admin_id==current_user.id):
        flash("You can't leave group in which you are the admin. You can delete the group itself.")
        return redirect(url_for('dashboard.dashboard'))
    groupname=leave_group(groupid)
    flash('You left the group "'+groupname+'"')
    return redirect(url_for('dashboard.dashboard'))
Beispiel #9
0
def removemember(groupid,memberid):
    if not(is_authenticated()):
        flash('Sorry, you are not logged in. Please login to continue')
        return redirect(url_for('auth.login'))
    if(GroupTable.query.filter_by(id=groupid).first().admin_id !=current_user.id):
        flash('Unauthorised action')
        return redirect(url_for('dashboard.dashboard'))
    groupmembername=remove_group_member(memberid,groupid)
    flash('You removed "'+groupmembername+'" from the group')
    return redirect(url_for('dashboard.groupinfo',group_id=groupid))
Beispiel #10
0
def message_from_client(message):
    if not (is_authenticated()):
        return 'Not logged in'
    user = UserTable.query.filter_by(id=current_user.id).first()
    group = GroupTable.query.filter_by(id=message['groupidnumber']).first()
    messageobj = Message(message=message['message'],
                         group_id=group.id,
                         user_id=current_user.id,
                         user_name=user.username)
    db.session.add(messageobj)
    db.session.commit()
    add_to_index('message', messageobj)
    emit(str(message['groupidnumber']), message, broadcast=True)
Beispiel #11
0
def login():
    if is_authenticated():
        return redirect(url_for('main.index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = UserTable.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Wrong username or password')
            return redirect(url_for('auth.login'))
        else:
            login_user(user, remember=form.remember_me.data)
            flash('Login successful')
            return redirect(url_for('dashboard.dashboard'))
    return render_template('auth/login.html', title='Login', form=form)
Beispiel #12
0
def groupinfo(group_id):
    if not(is_authenticated()):
        flash('Sorry, you are not logged in. Please login to continue')
        return redirect(url_for('auth.login'))
    if not(GroupMembers.query.filter_by(member_id=current_user.id).filter_by(group_id=group_id).all()):
        return render_template('errors/404.html'), 404
    user=get_current_user()
    group=get_group_single(group_id)
    members=get_group_members(group_id)
    members_names=get_group_members_names(members)
    admin=UserTable.query.filter_by(id=group.admin_id).first()
    form=AddMembers()
    description_form=ChangeGroupDescription()
    if description_form.validate_on_submit():
        change_group_description(description_form,group_id)
        redirect(url_for('dashboard.groupinfo',group_id=group_id))
    if form.validate_on_submit():
        add_group_members(form,group_id)
        return redirect(url_for('dashboard.groupinfo',group_id=group_id))
    if(admin.id!=user.id):
        return render_template('dashboard/showmembers.html',currentid=current_user.id,groupid=group_id,members=members_names,group=group.groupname,description=group.group_description,admin=admin.username,is_admin=False,form=form,changedesc=description_form)
    else:
        return render_template('dashboard/showmembers.html',currentid=current_user.id,groupid=group_id,members=members_names,group=group.groupname,description=group.group_description,admin='You are the admin',is_admin=True,form=form,changedesc=description_form)
Beispiel #13
0
def before_request():
    if is_authenticated():
        g.search_form = SearchForm()
Beispiel #14
0
def index():
    if is_authenticated():
        return redirect(url_for('dashboard.dashboard'))
    return redirect(url_for('auth.login'))