예제 #1
0
def my_account():
    form = accountForm()

    response_table = []
    responses = Response.query.filter_by(user_id=current_user.id)
    i = 0
    for response in responses:
        print(response)
        poll_name = Poll.query.filter_by(id=response.pool_id).first().name
        response_table.append([
            i, poll_name,
            str(response.date_posted).split()[0], response.pool_id
        ])
        i += 1

    if not current_user.is_authenticated:
        return redirect(url_for('users.login'))

    if form.validate_on_submit():
        current_user.firstname = firstnames
        current_user.lastname = lastnames
        current_user.email = emails
        db.session.commit()
    return render_template('user/account.html',
                           form=form,
                           response_table=response_table,
                           client=get_client())
예제 #2
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RequestResetFrom()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash('An email has been sent to reset your password', 'info')
        return redirect(url_for('users.login'))
    return render_template('user/reset_request.html',
                           title='Reset Password',
                           form=form,
                           client=get_client())
예제 #3
0
def account_reset_password():
    form = accountResetPasswordForm()
    if not current_user.is_authenticated:
        return redirect(url_for('users.login'))
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        current_user.password = hashed_password
        db.session.commit()
        flash('Your password has been updated.', 'success')
        logout()
        return redirect(url_for('users.login'))
    return render_template('user/reset_password.html',
                           form=form,
                           client=get_client())
예제 #4
0
def admin_add_poll():
    users = User.query.all()
    categories = Category.query.all()
    polls = Poll.query.all()
    responses = Response.query.all()
    user_form = RegistrationForm()
    category_form = NewCategoryForm()
    poll_form = NewPollForm()
    poll_form.category_poll.choices = [(str(category.id), category.name)
                                       for category in Category.query.all()]
    if poll_form.validate_on_submit():
        print(request.files)
        if poll_form.picture.data:
            print(poll_form.picture.data)
            picture_file = save_picture_poll(poll_form.picture.data)
            poll = Poll(name=poll_form.poll_name.data,
                        rank=poll_form.rank.data,
                        category_id=poll_form.category_poll.data,
                        image_file=picture_file,
                        description=poll_form.description.data,
                        video_url=poll_form.video.data)
            db.session.add(poll)
            db.session.commit()
        else:
            poll = Poll(name=poll_form.poll_name.data,
                        rank=poll_form.rank.data,
                        category_id=poll_form.category_poll.data,
                        description=poll_form.description.data,
                        video_url=poll_form.video.data)
            db.session.add(poll)
            db.session.commit()
        flash('New poll has been added!', 'success')
        return redirect(url_for('user_admin.user_index'))
    print('failed')
    return render_template('user-admin/user_admin.html',
                           users=users,
                           categories=categories,
                           polls=polls,
                           responses=responses,
                           user_form=user_form,
                           category_form=category_form,
                           poll_form=poll_form,
                           title="Admin",
                           data={
                               'form': 'poll_form',
                               'form_checking': True
                           },
                           client=get_client())
예제 #5
0
def add_category():
    users = User.query.all()
    categories = Category.query.all()
    polls = Poll.query.all()
    responses = Response.query.all()
    user_form = RegistrationForm()
    category_form = NewCategoryForm()
    poll_form = NewPollForm()
    poll_form.category_poll.choices = [(str(category.id), category.name)
                                       for category in Category.query.all()]
    if category_form.validate_on_submit():
        print(request.files)
        if category_form.catergory_picture.data:
            print(category_form.catergory_picture.data)
            picture_file = save_picture_category(
                category_form.catergory_picture.data)
            category = Category(
                name=category_form.category_name.data,
                image_file=picture_file,
                description=category_form.catergory_description.data,
                end_date=category_form.end_date.data)
            db.session.add(category)
            db.session.commit()
        else:
            category = Category(
                name=category_form.category_name.data,
                description=category_form.catergory_description.data,
                end_date=category_form.end_date.data)
            db.session.add(category)
            db.session.commit()
        flash('New category has been added!', 'success')
        return redirect(url_for('user_admin.user_index'))
    return render_template('user-admin/user_admin.html',
                           users=users,
                           categories=categories,
                           polls=polls,
                           responses=responses,
                           user_form=user_form,
                           category_form=category_form,
                           poll_form=poll_form,
                           title="Admin",
                           data={
                               'form': 'category_form',
                               'form_checking': True
                           },
                           client=get_client())
예제 #6
0
def login():
    form = LoginForm()
    # Using bcrypt to check the password
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            flash('Login successfull', 'success')
            return redirect(next_page) if next_page else redirect(
                url_for('main.index'))
        else:
            flash('Login unsuccessful. Please check Email and Password',
                  'danger')
    return render_template('user/login.html',
                           title='Login',
                           form=form,
                           client=get_client())
예제 #7
0
def active_polls():

	Categories = Category.query.all()
	responses = Response.query

	databases = []
	for categorie in Categories:
		temp = Poll.query.filter_by(category_id = categorie.id)
		response = responses.filter_by(category_id = categorie.id)
		if current_user.is_active:
			if response.filter_by(user_id = current_user.id).count() == 0:
				databases.append([categorie, temp, response.count(), False])
			else:
				databases.append([categorie, temp, response.count(), True])
		else:
			databases.append([categorie, temp, response.count(), False])

	return render_template('polls/polls.html',
						   databases = databases,
						   client= get_client())
예제 #8
0
def add_user():
    users = User.query.all()
    categories = Category.query.all()
    polls = Poll.query.all()
    responses = Response.query.all()
    user_form = RegistrationForm()
    category_form = NewCategoryForm()
    poll_form = NewPollForm()
    poll_form.category_poll.choices = [(str(category.id), category.name)
                                       for category in Category.query.all()]
    # Check Form input and encrypt the password before store them
    if user_form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            user_form.password.data).decode('utf-8')
        user = User(firstname=user_form.firstname.data,
                    lastname=user_form.lastname.data,
                    email=user_form.email.data,
                    gender=user_form.gender.data,
                    password=hashed_password,
                    is_admin=user_form.is_admin.data)
        db.session.add(user)
        db.session.commit()
        flash('New user account has been created!', 'success')
        return redirect(url_for('user_admin.user_index'))
    flash(
        u'New user account has not been created! Please try again, or look the log error',
        'danger')
    return render_template('user-admin/user_admin.html',
                           users=users,
                           categories=categories,
                           polls=polls,
                           responses=responses,
                           user_form=user_form,
                           category_form=category_form,
                           poll_form=poll_form,
                           title="Admin",
                           data={
                               'form': 'user_form',
                               'form_checking': True
                           },
                           client=get_client())
예제 #9
0
def register():
    form = RegistrationForm()
    # Check Form input and encrypt the password before store them
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(firstname=form.firstname.data,
                    lastname=form.lastname.data,
                    email=form.email.data,
                    gender=form.gender.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()

        flash('Your account has been created! You are now able to login',
              'success')
        return redirect(url_for('users.login'))
    return render_template('user/register.html',
                           title='Register',
                           form=form,
                           client=get_client())
예제 #10
0
def user_index():
    users = User.query.all()
    categories = Category.query.all()
    polls = Poll.query.all()
    responses = Response.query.all()
    user_form = RegistrationForm()
    category_form = NewCategoryForm()
    poll_form = NewPollForm()
    poll_form.category_poll.choices = [(str(category.id), category.name)
                                       for category in Category.query.all()]
    poll_form.rank.data = 0
    return render_template('user-admin/user_admin.html',
                           users=users,
                           categories=categories,
                           polls=polls,
                           responses=responses,
                           user_form=user_form,
                           category_form=category_form,
                           poll_form=poll_form,
                           title="Admin",
                           data={'form_checking': False},
                           client=get_client())
예제 #11
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordFrom()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()

        flash('Your password has been updated! You are now able to login',
              'success')
        return redirect(url_for('users.login'))
    return render_template('user/reset_token.html',
                           title='Reset Password',
                           form=form,
                           token=token,
                           client=get_client())
예제 #12
0
def reference():
    return render_template('reference/reference.html', client=get_client())
예제 #13
0
def about():
    return render_template('user/about.html',
                           title='About',
                           client=get_client())