Exemplo n.º 1
0
def register():
    """
    Register method for creating a PYBOSSA account.

    Returns a Jinja2 template

    """
    if current_app.config.get('LDAP_HOST', False):
        return abort(404)
    if not app_settings.upref_mdata:
        form = RegisterForm(request.body)
    else:
        form = RegisterFormWithUserPrefMetadata(request.body)
        form.set_upref_mdata_choices()

    form.project_slug.choices = get_project_choices()
    msg = "I accept receiving emails from %s" % current_app.config.get('BRAND')
    form.consent.label = msg
    if request.method == 'POST':
        form.generate_password()
    if request.method == 'POST' and form.validate():
        if app_settings.upref_mdata:
            user_pref, metadata = get_user_pref_and_metadata(form.name.data, form)
            account = dict(fullname=form.fullname.data, name=form.name.data,
                           email_addr=form.email_addr.data,
                           password=form.password.data,
                           consent=form.consent.data,
                           user_type=form.user_type.data)
            account['user_pref'] = user_pref
            account['metadata'] = metadata
        else:
            account = dict(fullname=form.fullname.data, name=form.name.data,
                           email_addr=form.email_addr.data,
                           password=form.password.data,
                           consent=form.consent.data)
        ensure_user_data_access_assignment_from_form(account, form)
        confirm_url = get_email_confirmation_url(account)
        if current_app.config.get('ACCOUNT_CONFIRMATION_DISABLED'):
            project_slugs=form.project_slug.data
            create_account(account, project_slugs=project_slugs)
            flash(gettext('Created user successfully!'), 'success')
            return redirect_content_type(url_for("home.home"))
        msg = dict(subject='Welcome to %s!' % current_app.config.get('BRAND'),
                   recipients=[account['email_addr']],
                   body=render_template('/account/email/validate_account.md',
                                        user=account, confirm_url=confirm_url))
        msg['html'] = markdown(msg['body'])
        mail_queue.enqueue(send_mail, msg)
        data = dict(template='account/account_validation.html',
                    title=gettext("Account validation"),
                    status='sent')
        return handle_content_type(data)
    if request.method == 'POST' and not form.validate():
        flash(gettext('Please correct the errors'), 'error')
    del form.password
    del form.confirm

    data = dict(template='account/register.html',
                title=gettext("Register"), form=form)
    return handle_content_type(data)
Exemplo n.º 2
0
    def _valid_user_data(self, user_data):
        from pybossa.view.account import get_project_choices
        from pybossa.forms.forms import RegisterFormWithUserPrefMetadata

        form_data = copy.deepcopy(user_data)
        upref = form_data.pop('user_pref', {})
        mdata = form_data.pop('metadata', {})

        if not isinstance(upref, dict):
            err = dict(user_pref='incorrect value')
            return False, err
        if not isinstance(mdata, dict) or \
            'user_type' not in mdata:
            err = dict(metadata='missing or incorrect user_type value')
            return False, err

        form_data['languages'] = upref.get('languages', [])
        form_data['locations'] = upref.get('locations', [])
        form_data['user_type'] = mdata.get('user_type')
        form_data.pop('info', None)
        form_data['confirm'] = user_data['password']
        form_data['project_slug'] = form_data.pop('project_slugs', [])

        form = RegisterFormWithUserPrefMetadata(MultiDict(form_data))
        form.generate_password()
        form.set_upref_mdata_choices()
        form.project_slug.choices = get_project_choices()
        return form.validate(), form.errors
Exemplo n.º 3
0
def register():
    """
    Register method for creating a PYBOSSA account.

    Returns a Jinja2 template

    """
    if current_app.config.get('LDAP_HOST', False):
        return abort(404)
    if not current_app.config.upref_mdata:
        form = RegisterForm(request.body)
    else:
        form = RegisterFormWithUserPrefMetadata(request.body)
        form.set_upref_mdata_choices()

    msg = "Ich bin damit einverstanden Emails zu erhalten, welche über die Registrierungsbestätigung hinaus gehen. (optional)"
    form.consent.label = msg
    if request.method == 'POST' and form.validate():
        if current_app.config.upref_mdata:
            user_pref, metadata = get_user_pref_and_metadata(form.name.data, form)
            account = dict(fullname=form.fullname.data, name=form.name.data,
                           email_addr=form.email_addr.data,
                           password=form.password.data,
                           consent=form.consent.data,
                           user_type=form.user_type.data)
            account['user_pref'] = user_pref
            account['metadata'] = metadata
        else:
            account = dict(fullname=form.fullname.data, name=form.name.data,
                           email_addr=form.email_addr.data,
                           password=form.password.data,
                           consent=form.consent.data)

        confirm_url = get_email_confirmation_url(account)
        if current_app.config.get('ACCOUNT_CONFIRMATION_DISABLED'):
            return _create_account(account)
        msg = dict(subject='Welcome to %s!' % current_app.config.get('BRAND'),
                   recipients=[account['email_addr']],
                   body=render_template('/account/email/validate_account.md',
                                        user=account, confirm_url=confirm_url))
        msg['html'] = markdown(msg['body'])
        mail_queue.enqueue(send_mail, msg)
        data = dict(template='account/account_validation.html',
                    title=gettext("Account validation"),
                    status='sent')
        return handle_content_type(data)
    if request.method == 'POST' and not form.validate():
        flash(gettext('Please correct the errors'), 'error')
    data = dict(template='account/register.html',
                title=gettext("Register"), form=form)
    return handle_content_type(data)
Exemplo n.º 4
0
    def test_register_form_with_upref_mdata_contains_fields(self):
        form = RegisterFormWithUserPrefMetadata()

        for field in self.fields:
            assert form.__contains__(field), 'Field %s is not in form' % field
Exemplo n.º 5
0
    def test_register_form_with_upref_mdata_contains_fields(self):
        form = RegisterFormWithUserPrefMetadata()

        for field in self.fields:
            assert form.__contains__(field), 'Field %s is not in form' %field