Beispiel #1
0
def register(request, hive_id=1):

    event = Event.objects.get(id=hive_id)

    if event.finish_time < datetime.now():
        return HttpResponseRedirect('/')

    if event.max_reg <= event.registrations:
        return HttpResponseRedirect('/')

    registrations = event.registrations
    submitted = None

    if request.method == 'POST':
        registration_form = RegistrationForm(data=request.POST)

        if registration_form.is_valid():
            reg = registration_form.save(commit=False)
            reg.event = event
            # perform registration check
            if regCheck(event, reg):
                submitted = 'Dude, you already registered!'
            else:
                reg.save()
                registrations += 1
                event.registrations = registrations
                event.save()
                submitted = 'Congratulations! You have registered.'
            return render(request, 'register.html', {'event':event, 'regData': reg, 'registration_form': registration_form, 'submitted':submitted})
        else:
            print registration_form.errors
    else:
        registration_form = RegistrationForm

    return render (request, 'register.html', {'registration_form': registration_form, 'event':event, 'submitted': submitted})
Beispiel #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations you are new one!')
        return redirect(url_for('login'))
    return render_template('register.html', title='REGISTER', form=form)
Beispiel #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Beispiel #4
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        flash(f'Account created for {form.username.data}!', 'success')
        if request.method == 'POST':
            result = request.form
            cursor1 = connection.cursor()
            insert = ("INSERT INTO details "
                      "(email, password, username) "
                      "VALUES(?,?,?)")
            values = list(result.values())
            values = [values[2], values[3], values[1]]
            cursor1.execute(insert, values)
            connection.commit()
        return redirect(url_for('home'))
    return render_template('register.html', title='Register', form=form)
Beispiel #5
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/hello')
    else:
        form = RegistrationForm()

    args = {'form': form}
    return render(request, 'hello/reg_form.html', args)
Beispiel #6
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('home'))
    return render_template('register.html', title='Register', form=form)