Exemple #1
0
    def test_get_by_id(self):
        """Get user by ID."""
        user = User('foo', '*****@*****.**')
        user.save()

        retrieved = User.get_by_id(user.id)
        assert retrieved == user
Exemple #2
0
def register():
    """Register new user."""
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        User.create(username=form.username.data,
                    email=form.email.data,
                    password=form.password.data,
                    active=True)
        flash('Thank you for registering. You can now log in.', 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('public/register.html', form=form)
Exemple #3
0
def login():
    if current_user.is_authenticated:
        return redirect('/')
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        result = mongo.db.auth.find_one({'email': form.email.data})
        if result and b_crypt.check_password_hash(result['password'],
                                                  form.password.data):
            user = User(result['username'], result['password'],
                        result['email'], result['firstName'],
                        result['lastName'])
            login_user(user, remember=form.remember)
            return redirect('/')
        else:
            form.password.errors.append('Invalid password')
    return render_template('login.jinja2', form=form)
Exemple #4
0
 def test_check_password(self):
     """Check password."""
     user = User.create(username='******', email='*****@*****.**',
                        password='******')
     assert user.check_password('foobarbaz123') is True
     assert user.check_password('barfoobaz') is False
Exemple #5
0
 def test_password_is_nullable(self):
     """Test null password."""
     user = User(username='******', email='*****@*****.**')
     user.save()
     assert user.password is None
Exemple #6
0
 def test_created_at_defaults_to_datetime(self):
     """Test creation date."""
     user = User(username='******', email='*****@*****.**')
     user.save()
     assert bool(user.created_at)
     assert isinstance(user.created_at, dt.datetime)
Exemple #7
0
def load_user(user_id):
    """Load user by ID."""
    return User.get_by_id(int(user_id))