def musicbrainz_post():
    """Callback endpoint."""
    if provider.validate_post_login():
        user = provider.get_user()
        db_user.update_last_login(user.musicbrainz_id)
        login_user(user, remember=True, duration=datetime.timedelta(current_app.config['SESSION_REMEMBER_ME_DURATION']))
        next = session.get('next')
        if next:
            return redirect(next)
    else:
        flash.error("Login failed.")
    return redirect(url_for('index.index'))
Ejemplo n.º 2
0
def musicbrainz_post():
    """Callback endpoint."""
    if provider.validate_post_login():
        user = provider.get_user()
        db_user.update_last_login(user.musicbrainz_id)
        login_user(user)
        next = session.get('next')
        if next:
            return redirect(next)
    else:
        flash.error("Login failed.")
    return redirect(url_for('index.index'))
    def test_update_last_login(self):
        """ Tests db.user.update_last_login """

        user = db_user.get_or_create(2, 'testlastloginuser')

        # set the last login value of the user to 0
        with db.engine.connect() as connection:
            connection.execute(
                sqlalchemy.text("""
                UPDATE "user"
                   SET last_login = to_timestamp(0)
                 WHERE id = :id
            """), {'id': user['id']})

        user = db_user.get(user['id'])
        self.assertEqual(int(user['last_login'].strftime('%s')), 0)

        db_user.update_last_login(user['musicbrainz_id'])
        user = db_user.get_by_mb_id(user['musicbrainz_id'])

        # after update_last_login, the val should be greater than the old value i.e 0
        self.assertGreater(int(user['last_login'].strftime('%s')), 0)
Ejemplo n.º 4
0
def musicbrainz_post():
    """Callback endpoint."""

    no_email_warning = Markup(
        'You have not provided an email address. Please provide an '
        '<a href="https://musicbrainz.org/account/edit">email address</a> ')
    blog_link = Markup(
        'Read this <a href="https://blog.metabrainz.org/?p=8915">blog post</a> '
        'to understand why we need your email.')

    if provider.validate_post_login():
        try:
            user = provider.get_user()
            if current_app.config[
                    "REJECT_NEW_USERS_WITHOUT_EMAIL"] and not user["email"]:
                # existing user without email, show a warning
                flash.warning(
                    no_email_warning +
                    'before 1 November 2021, or you will be unable to submit '
                    'listens. ' + blog_link)

            db_user.update_last_login(user["musicbrainz_id"])
            login_user(User.from_dbrow(user),
                       remember=True,
                       duration=datetime.timedelta(
                           current_app.config['SESSION_REMEMBER_ME_DURATION']))
            next = session.get('next')
            if next:
                return redirect(next)
        except MusicBrainzAuthSessionError:
            flash.error("Login failed.")
        except MusicBrainzAuthNoEmailError:
            # new user without email tried to create an account
            flash.error(no_email_warning +
                        'before creating a ListenBrainz account. ' + blog_link)
    else:
        flash.error("Login failed.")
    return redirect(url_for('index.index'))
Ejemplo n.º 5
0
 def test_update_last_login(self):
     user = db_user.get_or_create('testlastloginuser')
     val = int(time.time())
     db_user.update_last_login(user['musicbrainz_id'], val)
     user = db_user.get_by_mb_id(user['musicbrainz_id'])
     self.assertEqual(val, int(user['last_login'].strftime('%s')))