Example #1
0
def add_competition():
    if not (current_user.is_authenticated and current_user.admin):
        flash('You do not have admin privilages!', 'danger')
        return redirect(url_for('home'))
    form = CompetitionAddForm()
    form.tasks.choices = [(t.id, t.title) for t in Task.select()]
    form.participants.choices = [(u.id, u.username) for u in User.select()]
    if form.validate_on_submit():
        competition = Competition(name=form.name.data,
                                  start_time=form.start_time.data,
                                  end_time=form.end_time.data,
                                  public=form.public.data)
        competition.save()

        for task in form.tasks.data:
            contains = Contains(competition=competition.id,
                                task=int(task)).save()
        for participant in form.participants.data:
            ParticipatesIn(competition=competition.id,
                           user=int(participant)).save()
        flash('Competition added seccesfully!', 'success')
        return redirect(url_for('calendar'))
    return render_template('add_competition.html',
                           title='Add competition',
                           form=form,
                           action='add')
Example #2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.select().where(User.username == form.username.data).get()
        if user and bcrypt.check_password_hash(user.password_hash,
                                               form.password.data):
            login_user(user)
            flash('Welcome ' + form.username.data, 'success')
            next_page = request.args.get('next')
            if next_page:
                return redirect(next_page)
            return redirect(url_for('home'))
        flash('Login failed. Invalid username or password', 'danger')
    return render_template('login.html', title='Login', form=form)
Example #3
0
 def validate_username(self, username):
     if not User.select().where(User.username == username.data).exists():
         raise ValidationError("Username '" + username.data + "' does not exist")
Example #4
0
 def validate_email(self, email):
     if User.select().where(User.email == email.data).exists():
         raise ValidationError("Email '" + email.data + "' already in use")
Example #5
0
 def validate_username(self, username):
     if User.select().where(User.username == username.data).exists():
         raise ValidationError("Username '" + username.data + "' already in use")