def login_oauth2_user(valid, oauth):
    """Log in a user after having been verified."""
    if valid:
        login_user(oauth.user.id)
    return valid, oauth
Beispiel #2
0
def register():
    """Register."""
    req = request.get_legacy_request()

    # FIXME
    if cfg.get('CFG_ACCESS_CONTROL_LEVEL_SITE') > 0:
        from invenio.legacy import webuser
        return webuser.page_not_authorized(req,
                                           "../youraccount/register?ln=%s" %
                                           g.ln,
                                           navmenuid='youraccount')

    form = RegisterForm(request.values, csrf_enabled=False)

    title = _("Register")
    messages = []
    state = ""

    if form.validate_on_submit():
        from invenio.legacy import webuser
        ruid = webuser.registerUser(req,
                                    form.email.data.encode('utf8'),
                                    form.password.data.encode('utf8'),
                                    form.nickname.data.encode('utf8'),
                                    ln=g.ln)
        if ruid == 0:
            title = _("Account created")
            messages.append(_("Your account has been successfully created."))
            state = "success"
            if cfg.get('CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_NEW_ACCOUNT') \
                    == 1:
                messages.append(
                    _("In order to confirm its validity, "
                      "an email message containing an account "
                      "activation key has been sent to the given "
                      "email address."))
                messages.append(
                    _("Please follow instructions presented "
                      "there in order to complete the account "
                      "registration process."))
            if cfg.get('CFG_ACCESS_CONTROL_LEVEL_ACCOUNTS') >= 1:
                messages.append(
                    _("A second email will be sent when the "
                      "account has been activated and can be "
                      "used."))
            elif cfg['CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_NEW_ACCOUNT'] != 1:
                user = User.query.filter(
                    User.email == form.email.data.lower()).one()
                login_user(user.get_id())
                messages.append(_("You can now access your account."))
        else:
            title = _("Registration failure")
            state = "danger"
            if ruid == 5:
                messages.append(
                    _("Users cannot register themselves, only "
                      "admin can register them."))
            elif ruid == 6 or ruid == 1:
                # Note, code 1 is used both for invalid email, and email
                # sending
                # problems, however the email address is validated by the form,
                # so we only have to report a problem sending the email here
                messages.append(
                    _("The site is having troubles in sending "
                      "you an email for confirming your email "
                      "address."))
                messages.append(
                    _("The error has been logged and will be "
                      "taken in consideration as soon as possible."))
            else:
                # Errors [-2, (1), 2, 3, 4] taken care of by form validation
                messages.append(_("Internal error %(ruid)s", ruid=ruid))
    elif request.method == 'POST':
        title = _("Registration failure")
        state = "warning"

    return render_template('accounts/register.html',
                           form=form,
                           title=title,
                           messages=messages,
                           state=state)
def register():
    """Register."""
    req = request.get_legacy_request()

    # FIXME
    if cfg.get('CFG_ACCESS_CONTROL_LEVEL_SITE') > 0:
        from invenio.legacy import webuser
        return webuser.page_not_authorized(
            req, "../youraccount/register?ln=%s" % g.ln,
            navmenuid='youraccount')

    form = RegisterForm(request.values, csrf_enabled=False)

    title = _("Register")
    messages = []
    state = ""

    if form.validate_on_submit():
        from invenio.legacy import webuser
        ruid = webuser.registerUser(req, form.email.data.encode('utf8'),
                                    form.password.data.encode('utf8'),
                                    form.nickname.data.encode('utf8'),
                                    ln=g.ln)
        if ruid == 0:
            title = _("Account created")
            messages.append(_("Your account has been successfully created."))
            state = "success"
            if cfg.get('CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_NEW_ACCOUNT') \
                    == 1:
                messages.append(_("In order to confirm its validity, "
                                  "an email message containing an account "
                                  "activation key has been sent to the given "
                                  "email address."))
                messages.append(_("Please follow instructions presented "
                                  "there in order to complete the account "
                                  "registration process."))
            if cfg.get('CFG_ACCESS_CONTROL_LEVEL_ACCOUNTS') >= 1:
                messages.append(_("A second email will be sent when the "
                                  "account has been activated and can be "
                                  "used."))
            elif cfg['CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_NEW_ACCOUNT'] != 1:
                user = User.query.filter(
                    User.email == form.email.data.lower()).one()
                login_user(user.get_id())
                messages.append(_("You can now access your account."))
        else:
            title = _("Registration failure")
            state = "danger"
            if ruid == 5:
                messages.append(_("Users cannot register themselves, only "
                                  "admin can register them."))
            elif ruid == 6 or ruid == 1:
                # Note, code 1 is used both for invalid email, and email
                # sending
                # problems, however the email address is validated by the form,
                # so we only have to report a problem sending the email here
                messages.append(_("The site is having troubles in sending "
                                  "you an email for confirming your email "
                                  "address."))
                messages.append(
                    _("The error has been logged and will be "
                      "taken in consideration as soon as possible."))
            else:
                # Errors [-2, (1), 2, 3, 4] taken care of by form validation
                messages.append(_("Internal error %(ruid)s", ruid=ruid))
    elif request.method == 'POST':
        title = _("Registration failure")
        state = "warning"

    return render_template('accounts/register.html', form=form, title=title,
                           messages=messages, state=state)
def login_oauth2_user(valid, oauth):
    """Log in a user after having been verified."""
    if valid:
        login_user(oauth.user.id)
    return valid, oauth