Beispiel #1
0
    def test_allow_password(self):
        from app.users.security import allow_password
        import string

        # Not long enough
        self.assertFalse(allow_password(''))
        self.assertFalse(allow_password('1234567'))

        # Just right
        self.assertTrue(allow_password('12345678'))
        self.assertTrue(allow_password('1' * 1024))

        # Too long
        self.assertFalse(allow_password('1' * 1025))

        # Special characters
        self.assertTrue(allow_password('プレーヤープレーヤー'))
        self.assertTrue(
            allow_password(
                unicode(string.ascii_letters + string.digits +
                        string.punctuation + ' ')))

        # Control codes
        self.assertFalse(allow_password('12345678\t'))
        self.assertFalse(allow_password('1234\u20285678'))
        self.assertFalse(allow_password('\uFFF912345678'))
Beispiel #2
0
    def test_allow_password(self):
        from app.users.security import allow_password
        import string

        # Not long enough
        self.assertFalse(allow_password(''))
        self.assertFalse(allow_password('1234567'))

        # Just right
        self.assertTrue(allow_password('12345678'))
        self.assertTrue(allow_password('1' * 1024))

        # Too long
        self.assertFalse(allow_password('1' * 1025))

        # Special characters
        self.assertTrue(allow_password('プレーヤープレーヤー'))
        self.assertTrue(allow_password(unicode(
            string.ascii_letters + string.digits + string.punctuation + ' '
        )))

        # Control codes
        self.assertFalse(allow_password('12345678\t'))
        self.assertFalse(allow_password('1234\u20285678'))
        self.assertFalse(allow_password('\uFFF912345678'))
Beispiel #3
0
def register():
    form = RegisterForm(request.form)

    if form.validate_on_submit():
        existing_user = User.query.filter_by(email=form.email.data).first()

        if existing_user:
            form.email.errors = (_('This email is already taken'),)

        elif not allow_password(form.password.data):
            form.password.errors = (_(
                'Your password must contain at least 8 '
                '(printable) characters.'
            ),)

        else:
            user = User(
                email=form.email.data,
                password=generate_password_hash(form.password.data),
                name=form.name.data,
            )

            user.set_geo_from_ip(request.remote_addr)

            user.locale = request.accept_languages.best_match(
                app.config['LANGUAGES']
            )

            db.session.add(user)
            db.session.commit()

            login_user(user, remember=True)

            send_confirmation_email(user)

            flash(_('An email has been sent to you with a confirmation link. '
                    'Please login to your email at your convenience '
                    'and click the link to finish registration.'))

            return redirect(url_for('home'))

    return render_template('users/register.html', form=form)
Beispiel #4
0
def register():
    form = RegisterForm(request.form)

    if form.validate_on_submit():
        existing_user = User.query.filter_by(email=form.email.data).first()

        if existing_user:
            form.email.errors = (_('This email is already taken'), )

        elif not allow_password(form.password.data):
            form.password.errors = (_('Your password must contain at least 8 '
                                      '(printable) characters.'), )

        else:
            user = User(
                email=form.email.data,
                password=generate_password_hash(form.password.data),
                name=form.name.data,
            )

            user.set_geo_from_ip(request.remote_addr)

            user.locale = request.accept_languages.best_match(
                app.config['LANGUAGES'])

            db.session.add(user)
            db.session.commit()

            login_user(user, remember=True)

            send_confirmation_email(user)

            flash(
                _('An email has been sent to you with a confirmation link. '
                  'Please login to your email at your convenience '
                  'and click the link to finish registration.'))

            return redirect(url_for('home'))

    return render_template('users/register.html', form=form)