'Get the next_url for login redirect
Defaults to hub base_url /hub/ if user is not running,
otherwise user.url.'

def get_next_url(self, user=None):

    next_url = self.get_argument('next', default='')
    if (next_url + '/').startswith(('%s://%s/' % (self.request.protocol, self.request.host))):
        next_url = urlparse(next_url).path
    if (not next_url.startswith('/')):
        next_url = ''
    if (not next_url):
        if (user and user.running):
            next_url = user.url
        else:
            next_url = self.hub.base_url
    return next_url
