def new(handler, auth_entity=None, blog_id=None, **kwargs): """Creates and returns a Blogger for the logged in user. Args: handler: the current RequestHandler auth_entity: oauth_dropins.blogger.BloggerV2Auth blog_id: which blog. optional. if not provided, uses the first available. """ urls, domains = Blogger._urls_and_domains(auth_entity, blog_id=blog_id) if not urls or not domains: handler.messages = {'Blogger blog not found. Please create one first!'} return None if blog_id is None: for blog_id, hostname in zip(auth_entity.blog_ids, auth_entity.blog_hostnames): if domains[0] == hostname: break else: assert False, "Internal error, shouldn't happen" return Blogger(id=blog_id, auth_entity=auth_entity.key, url=urls[0], name=auth_entity.user_display_name(), domains=domains, domain_urls=urls, picture=auth_entity.picture_url, superfeedr_secret=util.generate_secret(), **kwargs)
def new(handler, auth_entity=None, **kwargs): """Creates and returns a WordPress for the logged in user. Args: handler: the current RequestHandler auth_entity: oauth_dropins.wordpress.WordPressAuth """ auth_domain = auth_entity.key.id() site_info = WordPress.get_site_info(handler, auth_entity) if site_info is None: return urls = util.dedupe_urls( util.trim_nulls([site_info.get('URL'), auth_entity.blog_url])) domains = [util.domain_from_link(u) for u in urls] avatar = (json.loads(auth_entity.user_json).get('avatar_URL') if auth_entity.user_json else None) return WordPress(id=domains[0], auth_entity=auth_entity.key, name=auth_entity.user_display_name(), picture=avatar, superfeedr_secret=util.generate_secret(), url=urls[0], domain_urls=urls, domains=domains, site_info=site_info, **kwargs)
def new(handler, auth_entity=None, **kwargs): """Creates and returns a WordPress for the logged in user. Args: handler: the current RequestHandler auth_entity: oauth_dropins.wordpress.WordPressAuth """ # Fetch blog's site info auth_domain = auth_entity.key.id() site_info = json.loads(auth_entity.urlopen( API_SITE_URL % auth_entity.blog_id).read()) site_url = site_info.get('URL') if site_url: domains = [util.domain_from_link(site_url), auth_domain] urls = [site_url, auth_entity.blog_url] else: domains = [auth_domain] urls = [auth_entity.blog_url] avatar = (json.loads(auth_entity.user_json).get('avatar_URL') if auth_entity.user_json else None) return WordPress(id=domains[0], auth_entity=auth_entity.key, name=auth_entity.user_display_name(), picture=avatar, superfeedr_secret=util.generate_secret(), url=urls[0], domain_urls=urls, domains=domains, site_info=site_info, **kwargs)
def new(handler, auth_entity=None, blog_name=None, **kwargs): """Creates and returns a :class:`Tumblr` for the logged in user. Args: handler: the current :class:`webapp2.RequestHandler` auth_entity: :class:`oauth_dropins.tumblr.TumblrAuth` blog_name: which blog. optional. passed to _urls_and_domains. """ urls, domains = Tumblr._urls_and_domains(auth_entity, blog_name=blog_name) if not urls or not domains: handler.messages = { 'Tumblr blog not found. Please create one first!' } return None id = domains[0] return Tumblr(id=id, auth_entity=auth_entity.key, domains=domains, domain_urls=urls, name=auth_entity.user_display_name(), picture=TUMBLR_AVATAR_URL % id, superfeedr_secret=util.generate_secret(), **kwargs)
def new(handler, auth_entity=None, **kwargs): """Creates and returns a WordPress for the logged in user. Args: handler: the current RequestHandler auth_entity: oauth_dropins.wordpress.WordPressAuth """ auth_domain = auth_entity.key.id() site_info = WordPress.get_site_info(handler, auth_entity) if site_info is None: return urls = util.dedupe_urls(util.trim_nulls( [site_info.get('URL'), auth_entity.blog_url])) domains = [util.domain_from_link(u) for u in urls] avatar = (json.loads(auth_entity.user_json).get('avatar_URL') if auth_entity.user_json else None) return WordPress(id=domains[0], auth_entity=auth_entity.key, name=auth_entity.user_display_name(), picture=avatar, superfeedr_secret=util.generate_secret(), url=urls[0], domain_urls=urls, domains=domains, site_info=site_info, **kwargs)
def new(handler, auth_entity=None, id=None, **kwargs): """Creates and returns a Medium for the logged in user. Args: handler: the current :class:`webapp2.RequestHandler` auth_entity: :class:`oauth_dropins.medium.MediumAuth` id: string, either username (starting with @) or publication id """ assert id medium = Medium(id=id, auth_entity=auth_entity.key, superfeedr_secret=util.generate_secret(), **kwargs) data = medium._data(auth_entity) medium.name = data.get('name') or data.get('username') medium.picture = data.get('imageUrl') medium.url = data.get('url') return medium
def new(auth_entity=None, username=None, **kwargs): """Creates and returns a Medium for the logged in user. Args: auth_entity: :class:`oauth_dropins.medium.MediumAuth` username: string, either username (starting with @) or publication id """ assert username assert 'id' not in kwargs medium = Medium(username=username, auth_entity=auth_entity.key, superfeedr_secret=util.generate_secret(), **kwargs) data = medium._data(auth_entity) medium.name = data.get('name') or data.get('username') medium.picture = data.get('imageUrl') medium.url = data.get('url') return medium
def new(handler, auth_entity=None, blog_name=None, **kwargs): """Creates and returns a Tumblr for the logged in user. Args: handler: the current RequestHandler auth_entity: oauth_dropins.tumblr.TumblrAuth blog_name: which blog. optional. passed to _url_and_domain. """ url, domain, ok = Tumblr._url_and_domain(auth_entity, blog_name=blog_name) if not ok: handler.messages = {'Tumblr blog not found. Please create one first!'} return None return Tumblr(id=domain, auth_entity=auth_entity.key, domains=[domain], domain_urls=[url], name=auth_entity.user_display_name(), picture=TUMBLR_AVATAR_URL % domain, superfeedr_secret=util.generate_secret(), **kwargs)
def new(handler, auth_entity=None, blog_name=None, **kwargs): """Creates and returns a :class:`Tumblr` for the logged in user. Args: handler: the current :class:`webapp2.RequestHandler` auth_entity: :class:`oauth_dropins.tumblr.TumblrAuth` blog_name: which blog. optional. passed to _urls_and_domains. """ urls, domains = Tumblr._urls_and_domains(auth_entity, blog_name=blog_name) if not urls or not domains: handler.messages = {'Tumblr blog not found. Please create one first!'} return None id = domains[0] return Tumblr(id=id, auth_entity=auth_entity.key, domains=domains, domain_urls=urls, name=auth_entity.user_display_name(), picture=TUMBLR_AVATAR_URL % id, superfeedr_secret=util.generate_secret(), **kwargs)
(r"/admin/user_management", admin.user_management.Handler), (r"/admin/server_list", admin.server_list.Handler), ], cookie_secret=os.urandom(32), xsrf_cookies=True, static_path=os.path.join(os.path.dirname(__file__), "static"), ) if __name__ == "__main__": parse_command_line() if not database.initialize(): exit(1) if options.add_sysop is not None: RANDOM_PW = util.generate_secret() database.add_login(options.add_sysop, RANDOM_PW, True) print("Password for {}: {}".format(options.add_sysop, RANDOM_PW)) exit(0) if options.reset_pw is not None: RANDOM_PW = util.generate_secret() database.update_login(options.reset_pw, RANDOM_PW) print("New password for {}: {}".format(options.reset_pw, RANDOM_PW)) exit(0) APP = make_app() APP.listen(options.port) print("Listening on port {}...".format(options.port)) tornado.ioloop.IOLoop.current().start()
def session_add(self): """Adds a new session""" if not check_origin(self): self.write({"status": "BAD_ORIGIN"}) return if list(HOSTS.values()).count( get_ip(self)) > settings.MAXIMUM_SESSIONS_PER_HOST: self.write({"status": "TOO_MANY_SESSIONS"}) return session = {} for key in [ "name", "region", "game", "server_id", "port", "player_count", "in_game", "password", "version", "method", ]: session[key] = self.get_argument(key, default=None, strip=True) if session[key] is None: self.write({"status": "MISSING_PARAMETER", "parameter": key}) return if database.is_string_blacklisted(session[key]): self.write({"status": "BLACKLISTED_WORD", "parameter": key}) return if session["region"] not in settings.VALID_REGIONS: self.write({"status": "BAD_REGION"}) return if not 0 < len(session["name"]) < settings.SESSION_MAX_STRING_LENGTH: self.write({"status": "BAD_NAME_LENGTH"}) return if not 0 < len(session["game"]) < settings.SESSION_MAX_STRING_LENGTH: self.write({"status": "BAD_GAME_LENGTH"}) return if not 0 < len( session["server_id"]) < settings.SESSION_MAX_STRING_LENGTH: self.write({"status": "BAD_SERVER_ID_LENGTH"}) return if not 0 < int(session["port"]) <= 65535: self.write({"status": "BAD_PORT"}) return if session["method"] not in ["direct", "traversal"]: self.write({"status": "BAD_METHOD"}) return session["timestamp"] = time.time() try: session["in_game"] = bool(int(session["in_game"])) session["password"] = bool(int(session["password"])) session["port"] = int(session["port"]) session["player_count"] = int(session["player_count"]) except ValueError: self.write({"status": "PARSING_ERROR"}) return secret = generate_secret() SESSIONS[secret] = session HOSTS[secret] = get_ip(self) REGIONS[secret] = get_ip_region(HOSTS[secret]) self.write({"status": "OK", "secret": secret})
def test_generate_secret(self): self.assertEquals(24, len(util.generate_secret()))