Exemple #1
0
 def test_register_monkey(self):
     """Test register_monkey()."""
     form = ProfileEditForm()
     form['first_name'].data = 'Test'
     form['last_name'].data = 'User'
     form['email'].data = '*****@*****.**'
     form['date_of_birth'].data = ''
     form['password'].data = '123'
     form['confirm'].data = '123'
     monkey = dba.register_monkey(form)
     assert isinstance(monkey, Monkey)
     assert monkey.id > 0
Exemple #2
0
def register():
    """Register a new monkey."""
    if 'id' in session:
        return redirect(url_for('index'))

    form = ProfileEditForm(request.form)

    if request.method == 'POST' and form.validate():
        # Check for email uniqueness by querying for another monkey
        # with the same address:
        if dba.check_unique_email(form['email'].data):
            # If no duplicate found:
            monkey = dba.register_monkey(form)
            if (monkey):
                # If registered, log in and go to index:
                session['id'] = monkey.id
                return redirect(url_for('index'))
            else:
                flash('Error registering!')
        else:
            form.email.errors.append(
                'This e-mail address is registered with another user')

    return render_template('edit.html', form=form)
Exemple #3
0
def register():
    """Register a new monkey."""
    if 'id' in session:
        return redirect(url_for('index'))

    form = ProfileEditForm(request.form)

    if request.method == 'POST' and form.validate():
        # Check for email uniqueness by querying for another monkey
        # with the same address:
        if dba.check_unique_email(form['email'].data):
            # If no duplicate found:
            monkey = dba.register_monkey(form)
            if (monkey):
                # If registered, log in and go to index:
                session['id'] = monkey.id
                return redirect(url_for('index'))
            else:
                flash('Error registering!')
        else:
            form.email.errors.append(
                'This e-mail address is registered with another user')

    return render_template('edit.html', form=form)