Exemplo n.º 1
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)
Exemplo n.º 2
0
def edit():
    """Edit monkey's own profile."""
    monkey_self = dba.get_monkey_by_id(session['id'])
    if monkey_self is None:
        return redirect(url_for('index'))

    # If no formdata is present in the request, the form is populated
    # from the object:
    form = ProfileEditForm(request.form, monkey_self)

    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, monkey_self.id):
            # If no duplicate found:
            if dba.edit_monkey_profile(monkey_self, form):
                flash('Changes saved')
            else:
                flash('Error saving changes!')
        else:
            form.email.errors.append(
                'This e-mail address is registered with another user')

    return render_template('edit.html', form=form, monkey_self=monkey_self)
Exemplo n.º 3
0
def edit():
    """Edit monkey's own profile."""
    monkey_self = dba.get_monkey_by_id(session['id'])
    if monkey_self is None:
        return redirect(url_for('index'))

    # If no formdata is present in the request, the form is populated
    # from the object:
    form = ProfileEditForm(request.form, monkey_self)

    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, monkey_self.id):
            # If no duplicate found:
            if dba.edit_monkey_profile(monkey_self, form):
                flash('Changes saved')
            else:
                flash('Error saving changes!')
        else:
            form.email.errors.append(
                'This e-mail address is registered with another user')

    return render_template('edit.html', form=form, monkey_self=monkey_self)
Exemplo n.º 4
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)
Exemplo n.º 5
0
 def test_check_unique_email(self, test_monkey):
     """Test check_unique_email()."""
     monkey = test_monkey
     assert not dba.check_unique_email(monkey.email)
     assert dba.check_unique_email(monkey.email, monkey.id)