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 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 #4
0
def create_user(get_account_res, token_response):
    """
    Create a user account:
    """

    refresh_ready = datetime.utcnow() + timedelta(
        seconds=int(token_response['expires_in']))
    refresh_expired = datetime.utcnow() + timedelta(
        seconds=int(token_response['refresh_expires_in']))
    access_expired = datetime.utcnow() + timedelta(
        seconds=int(token_response['expires_in']))
    last_seen = datetime.utcnow()

    print(type(refresh_ready))

    account = {
        'bungieMembershipId':
        get_account_res['Response']['bungieNetUser']['membershipId'],
        'displayName':
        get_account_res['Response']['bungieNetUser']['displayName'],
        'access_token':
        token_response['access_token'],
        'refresh_token':
        token_response['refresh_token'],
        'refresh_ready':
        refresh_ready,
        'refresh_expired':
        refresh_expired,
        'access_expired':
        access_expired,
        'last_seen':
        last_seen
    }

    print(account['bungieMembershipId'])

    user = User(
        username=account['displayName'],
        unique_name=account['displayName'] + "_" +
        account['bungieMembershipId'],
        bungieMembershipId=account['bungieMembershipId'],
        access_token=account['access_token'],
        refresh_token=account['refresh_token'],
        refresh_ready=account['refresh_ready'],
        refresh_expired=account['refresh_expired'],
        access_expired=account['access_expired'],
        last_seen=account['last_seen'],
    )

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

    return user
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))