Exemple #1
0
    def wrapper(*args, **kwargs):
        config = get_config()

        if config.start_date and config.start_date > date.today():
            message = "Registration has not started yet"
            return flask.render_template('message.html', message=message)

        if config.end_date and config.end_date < date.today():
            message = "Registration has finished"
            return flask.render_template('message.html', message=message)

        return view(*args, **kwargs)
Exemple #2
0
    def wrapper(*args, **kwargs):
        config = get_config()

        if config.start_date and config.start_date > date.today():
            message = "Registration has not started yet"
            return flask.render_template('message.html', message=message)

        if config.end_date and config.end_date < date.today():
            message = "Registration has finished"
            return flask.render_template('message.html', message=message)

        return view(*args, **kwargs)
Exemple #3
0
def register_ldap():
    #TODO maybe remove as the user is now registered on first LDAP login
    user_credentials = g.get('user_credentials', {})
    user_id = user_credentials.get('user_id')

    if not user_credentials.get('is_ldap_user'):
        if user_id:
            message = "You are already logged in."
            return render_template('message.html', message=message)

        else:
            message = (
                'First log into your EIONET account by clicking "login" '
                'at the top of the page.')
            return render_template('message.html', message=message)

    if user_id and g.identity.id:
        return render_template('auth/register_ldap_exists.html', **{
            'admin_email': get_config().admin_email,
        })
    initial_data = _get_initial_ldap_data(user_id)
    form = Art17LDAPRegisterForm(ImmutableMultiDict(initial_data))

    if request.method == 'POST':
        form = Art17LDAPRegisterForm(request.form)
        form.name.data = initial_data.get('name', '')
        form.email.data = initial_data.get('email', '')
        if form.validate():
            datastore = current_app.extensions['security'].datastore
            user = datastore.create_user(id=user_id,
                                         is_ldap=True,
                                         password='',
                                         confirmed_at=datetime.utcnow(),
                                         **form.to_dict())
            datastore.commit()
            flash(
                "Eionet account %s has been activated" % user_id,
                'success',
            )
            activate_and_notify_admin(_app_ctx_stack.top.app, user)
            add_default_role(user)
            return render_template('auth/register_ldap_done.html')

    return render_template(
        'auth/register_ldap.html', **{
            'already_registered': g.get('user') is not None,
            'user_id': user_id,
            'register_user_form': form,
        })
Exemple #4
0
def activate_and_notify_admin(app, user, **extra):
    set_user_active(user, True)
    models.db.session.commit()
    admin_email = get_config().admin_email

    if not admin_email:
        logger.warn("No admin_email is configured; not sending email")

    else:
        msg = Message(
            subject="User has registered",
            sender=app.extensions['security'].email_sender,
            recipients=admin_email.split(),
        )
        msg.body = flask.render_template(
            'auth/email_admin_new_user.txt',
            user=user,
            activation_link=flask.url_for(
                'auth.admin_user',
                user_id=user.id,
                _external=True,
            ),
        )
        safe_send_mail(app, msg)
Exemple #5
0
def activate_and_notify_admin(app, user, **extra):
    set_user_active(user, True)
    models.db.session.commit()
    admin_email = get_config().admin_email

    if not admin_email:
        logger.warn("No admin_email is configured; not sending email")

    else:
        msg = Message(
            subject="User has registered",
            sender=app.extensions['security'].email_sender,
            recipients=admin_email.split(),
        )
        msg.body = flask.render_template(
            'auth/email_admin_new_user.txt',
            user=user,
            activation_link=flask.url_for(
                'auth.admin_user',
                user_id=user.id,
                _external=True,
            ),
        )
        safe_send_mail(app, msg)
def _set_config(**kwargs):
    from art17.common import get_config
    from art17.models import db
    for key in kwargs:
        setattr(get_config(), key, kwargs[key])
    db.session.commit()