コード例 #1
0
def login():
    form = LoginForm(next=request.args.get('next'))

    if form.validate_on_submit():
        u = User.find_by_identity(request.form.get('identity'))

        if u and u.authenticated(password=request.form.get('password')):
            # As you can see remember me is always enabled, this was a design
            # decision I made because more often than not users want this
            # enabled. This allows for a less complicated login form.
            #
            # If however you want them to be able to select whether or not they
            # should remain logged in then perform the following 3 steps:
            # 1) Replace 'True' below with: request.form.get('remember', False)
            # 2) Uncomment the 'remember' field in user/forms.py#LoginForm
            # 3) Add a checkbox to the login form with the id/name 'remember'
            if login_user(u, remember=True):
                u.update_activity_tracking(request.remote_addr)

                # Handle optionally redirecting to the next URL safely.
                next_url = request.form.get('next')
                if next_url:
                    return redirect(safe_next_url(next_url))

                return redirect(url_for('quant.dashboard'))
            else:
                flash('This account has been disabled.', 'error')
        else:
            flash('Identity or password is incorrect.', 'error')

    return render_template('user/login.html', form=form)
コード例 #2
0
    def test_deliver_password_reset_email(self, token):
        """ Deliver a 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
コード例 #3
0
def token(db):
    """
    Serialize a JWS token.

    :param db: Pytest fixture
    :return: JWS token
    """
    user = User.find_by_identity('*****@*****.**')
    return user.serialize_token()
コード例 #4
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.')
コード例 #5
0
ファイル: test_models.py プロジェクト: cg94301/turboquant
    def test_invoice_create(self, users, mock_stripe):
        """ Successfully create an invoice item. """
        user = User.find_by_identity('*****@*****.**')

        invoice = Invoice()
        invoice.create(user=user,
                       currency='usd',
                       amount='900',
                       coins=1000,
                       coupon=None,
                       token='cus_000')

        assert user.coins == 1100
コード例 #6
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
コード例 #7
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',
        'email': app.config['SEED_ADMIN_EMAIL'],
        'password': app.config['SEED_ADMIN_PASSWORD']
    }

    return User(**params).save()
コード例 #8
0
def subscriptions(db):
    """
    Create subscription fixtures.

    :param db: Pytest fixture
    :return: SQLAlchemy database session
    """
    subscriber = User.find_by_identity('*****@*****.**')
    if subscriber:
        subscriber.delete()
    db.session.query(Subscription).delete()

    params = {
        'role': 'admin',
        'email': '*****@*****.**',
        'name': 'Subby',
        'password': '******',
        'payment_id': 'cus_000'
    }

    subscriber = User(**params)

    # The account needs to be commit before we can assign a subscription to it.
    db.session.add(subscriber)
    db.session.commit()

    # Create a subscription.
    params = {'user_id': subscriber.id, 'plan': 'gold'}
    subscription = Subscription(**params)
    db.session.add(subscription)

    # Create a credit card.
    params = {
        'user_id': subscriber.id,
        'brand': 'Visa',
        'last4': '4242',
        'exp_date': datetime.date(2015, 6, 1)
    }
    credit_card = CreditCard(**params)
    db.session.add(credit_card)

    db.session.commit()

    return db
コード例 #9
0
    def test_subscribed_user_receives_more_coins(self, users):
        """ Subscribed user receives more coins. """
        user = User.find_by_identity('*****@*****.**')
        user.add_coins(Subscription.get_plan_by_id('bronze'))

        assert user.coins == 210