@classmethod
def set_login_cookie(cls, handler, user_id=None):
    """Call this on handlers to set the login cookie for success"""
    cookie_options = handler.settings.get('cookie_options', {})
    cookie_options.setdefault('httponly', True)
    if handler.settings.get('secure_cookie', handler.request.protocol ==
        'https'):
        cookie_options.setdefault('secure', True)
    handler.set_secure_cookie(handler.cookie_name, user_id, **cookie_options)
    return user_id
