Esempio n. 1
0
    def test_register_form_password(self):
        """Test RegisterForm password."""
        from invenio.modules.accounts.forms import RegisterForm

        not_valid_pwd = "x" * (self.min_len - 1)
        valid_pwd = "x" * self.min_len

        form = RegisterForm(
            email="*****@*****.**",
            nickname="testvalidnickname",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is True

        form = RegisterForm(
            email="*****@*****.**",
            nickname="testvalidnickname",
            password=not_valid_pwd,
            password2=not_valid_pwd
        )
        assert form.validate() is False

        form = RegisterForm(
            email="*****@*****.**",
            nickname="testvalidnickname",
            password=valid_pwd,
            password2=valid_pwd+"different"
        )
        assert form.validate() is False
Esempio n. 2
0
def register():
    """Register."""
    req = request.get_legacy_request()

    # FIXME
    if cfg.get('CFG_ACCESS_CONTROL_LEVEL_SITE') > 0:
        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():
        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)
Esempio n. 3
0
    def test_register_form_nickname(self):
        """Test RegisterForm nickname."""
        from invenio.modules.accounts.forms import RegisterForm

        valid_pwd = "x" * self.min_len

        form = RegisterForm(
            email="*****@*****.**",
            nickname="testvalidnickname",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is True

        form = RegisterForm(
            email="*****@*****.**",
            nickname="",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is False

        form = RegisterForm(
            email="*****@*****.**",
            nickname="notvalid@user",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is False

        form = RegisterForm(
            email="*****@*****.**",
            nickname="notvalid,user",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is False

        form = RegisterForm(
            email="*****@*****.**",
            nickname=" testnickname",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is False

        form = RegisterForm(
            email="*****@*****.**",
            nickname="testnickname ",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is False

        form = RegisterForm(
            email="*****@*****.**",
            nickname="guest",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is False
Esempio n. 4
0
    def test_register_form_email(self):
        """Test RegisterForm email."""
        from invenio.modules.accounts.forms import RegisterForm
        from invenio.base.globals import cfg

        cfg['CFG_ACCESS_CONTROL_LIMIT_REGISTRATION_TO_DOMAIN'] = ''

        valid_pwd = "x" * self.min_len

        form = RegisterForm(
            email="*****@*****.**",
            nickname="testvalidnickname",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is True

        form = RegisterForm(
            email="",
            nickname="testvalidnickname",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is False

        form = RegisterForm(
            email=self.email,
            nickname="testvalidnickname",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is False

        form = RegisterForm(
            email="email@fuu",
            nickname="testvalidnickname",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is False

        form = RegisterForm(
            email="email.fuu",
            nickname="testvalidnickname",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is False

        cfg['CFG_ACCESS_CONTROL_LIMIT_REGISTRATION_TO_DOMAIN'] = 'fuu.it'

        form = RegisterForm(
            email="*****@*****.**",
            nickname="testvalidnickname",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is False

        email = "fu@" + cfg['CFG_ACCESS_CONTROL_LIMIT_REGISTRATION_TO_DOMAIN']
        form = RegisterForm(
            email=email,
            nickname="testvalidnickname",
            password=valid_pwd,
            password2=valid_pwd
        )
        assert form.validate() is True