Beispiel #1
0
    def test_begin_update_credentials_email_change(self):
        """ Update credentials but only the e-mail address. """
        self.login()

        user = {'current_password': '******', 'email': '*****@*****.**'}
        response = self.client.post(url_for('user.update_credentials'),
                                    data=user,
                                    follow_redirects=True)

        assert_status_with_message(200, response,
                                   'Your sign in settings have been updated.')

        old_user = User.find_by_identity('*****@*****.**')
        assert old_user is None

        new_user = User.find_by_identity('*****@*****.**')
        assert new_user is not None
Beispiel #2
0
    def test_deliver_password_reset_email(self, token):
        """ Deliver password reset email. """
        with mail.record_messages() as outbox:
            user = User.find_by_identity('*****@*****.**')
            deliver_password_reset_email(user.id, token)

            assert len(outbox) == 1
            assert token in outbox[0].body
def token(db):
    """
    Serialize JWS token.

    :param db: Pytest fixture
    :return: JWS token
    """
    user = User.find_by_identity('*****@*****.**')
    return user.serialize_token()
    def post():
        content = request.get_json()
        username = content.get('username', None)
        email = content.get('email', None)
        username_error = "Username has been taken."
        email_error = "An account with that email has already been registered."

        if User.find_by_identity(username) and User.find_by_identity(email):
            return render_json(404,
                {'username': username_error,
                 'email': email_error})
        if User.find_by_identity(username):
            return render_json(404, 
                {'username': username_error})
        if User.find_by_identity(email):
            return render_json(404, 
                {'email': email_error})

        return None
Beispiel #5
0
    def test_login_activity(self, users):
        """ Login successfully and update the activity stats. """
        user = User.find_by_identity('*****@*****.**')
        old_sign_in_count = user.sign_in_count

        response = self.login()

        new_sign_in_count = user.sign_in_count

        assert response.status_code == 200
        assert (old_sign_in_count + 1) == new_sign_in_count
Beispiel #6
0
def ensure_identity_exists(form, field):
    """
    Ensure an identity exists.

    :param form: wtforms Instance
    :param field: Field being passed in
    :return: None
    """
    user = User.find_by_identity(field.data)

    if not user:
        raise ValidationError('Unable to locate account.')
Beispiel #7
0
    def test_password_reset(self, users, token):
        """ Reset successful. """
        reset = {'password': '******', 'reset_token': token}
        response = self.client.post(url_for('user.password_reset'),
                                    data=reset,
                                    follow_redirects=True)

        assert_status_with_message(200, response,
                                   'Your password has been reset.')

        admin = User.find_by_identity('*****@*****.**')
        assert admin.password != 'newpassword'
    def post():
        content = request.form
        user = User.find_by_identity(content.get('identity'))

        if user and user.authenticated(password=content.get('password')):
            if login_user(user, remember=True) and user.is_active():
                user.update_activity_tracking(request.remote_addr)
                return render_json(200, {'message': 'Login successful'})
            else:
                return render_json(401, {'message': 'This account has been disabled'})
        else:
            return render_json(401, {'message': 'Identity or password provided was incorrect.'})
Beispiel #9
0
    def test_cancel_subscription(self, subscriptions, mock_stripe):
        """ User subscription gets cancelled. """
        user = User.find_by_identity('*****@*****.**')
        params = {
            'id': user.id
        }

        self.login()
        response = self.client.post(url_for('admin.users_cancel_subscription'),
                                    data=params, follow_redirects=True)

        assert_status_with_message(200, response,
                                   'Subscription has been cancelled for Subby')
        assert user.cancelled_subscription_on is not None
Beispiel #10
0
    def test_welcome_with_existing_username(self, users):
        """ Create username failure due to username already existing. """
        self.login()

        u = User.find_by_identity('*****@*****.**')
        u.username = '******'
        u.save()

        user = {'username': '******'}
        response = self.client.post(url_for('user.welcome'),
                                    data=user,
                                    follow_redirects=True)

        assert_status_with_message(200, response,
                                   'You already picked a username.')
Beispiel #11
0
    def test_signup(self, users):
        """ Signup successfully. """
        old_user_count = User.query.count()

        user = {'email': '*****@*****.**', 'password': '******'}
        response = self.client.post(url_for('user.signup'),
                                    data=user,
                                    follow_redirects=True)

        assert_status_with_message(200, response,
                                   'Awesome, thanks for signing up!')

        new_user_count = User.query.count()
        assert (old_user_count + 1) == new_user_count

        new_user = User.find_by_identity('*****@*****.**')
        assert new_user.password != 'password'
Beispiel #12
0
def seed():
    """
    Seed the database with an initial user.

    :return: User instance
    """
    if User.find_by_identity(app.config['SEED_ADMIN_EMAIL']) is not None:
        return None

    params = {
        'role': 'admin',
        'username': app.config['SEED_ADMIN_USERNAME'],
        'first_name': app.config['SEED_ADMIN_FIRST_NAME'],
        'last_name': app.config['SEED_ADMIN_LAST_NAME'],
        'email': app.config['SEED_ADMIN_EMAIL'],
        'password': app.config['SEED_ADMIN_PASSWORD'],
        'phone_number': app.config['SEED_ADMIN_PHONE_NUMBER']
    }

    return User(**params).save()
Beispiel #13
0
def authenticate(username, password):
    from server.blueprints.user.models import User
    user = User.find_by_identity(username)
    if user and user.authenticated(password=password):
        return user