def add_registered(self, sid): real_key = db.c.fetch_var("SELECT radio_listenkey FROM phpbb_users WHERE user_id = %s", (self.user_id,)) if real_key != self.listen_key: raise APIException("invalid_argument", reason="mismatched listen_key.") tunedin = db.c.fetch_var("SELECT COUNT(*) FROM r4_listeners WHERE user_id = %s", (self.user_id,)) if tunedin: db.c.update( "UPDATE r4_listeners " "SET sid = %s, listener_ip = %s, listener_purge = FALSE, listener_icecast_id = %s, listener_relay = %s, listener_agent = %s " "WHERE user_id = %s", (sid, self.get_argument("ip"), self.get_argument("client"), self.relay, self.agent, self.user_id)) self.append("%s update: %s %s %s %s %s %s." % ('{:<5}'.format(self.user_id), sid, '{:<15}'.format(self.get_argument("ip")), '{:<15}'.format(self.relay), '{:<10}'.format(self.get_argument("client")), self.agent, self.listen_key)) self.failed = False else: db.c.update("INSERT INTO r4_listeners " "(sid, user_id, listener_ip, listener_icecast_id, listener_relay, listener_agent) " "VALUES (%s, %s, %s, %s, %s, %s)", (sid, self.user_id, self.get_argument("ip"), self.get_argument("client"), self.relay, self.agent)) self.append("%s new : %s %s %s %s %s %s." % ('{:<5}'.format(self.user_id), sid, '{:<15}'.format(self.get_argument("ip")), '{:<15}'.format(self.relay), '{:<10}'.format(self.get_argument("client")), self.agent, self.listen_key)) self.failed = False if not self.failed: u = user.User(self.user_id) u.get_listener_record(use_cache=False) if u.has_requests(): u.put_in_request_line(sid) sync_to_front.sync_frontend_user_id(self.user_id)
def add_registered(self, sid): tunedin = db.c.fetch_var("SELECT COUNT(*) FROM r4_listeners WHERE user_id = %s", (self.user_id,)) if tunedin: db.c.update( "UPDATE r4_listeners " "SET sid = %s, listener_ip = %s, listener_purge = FALSE, listener_icecast_id = %s, listener_relay = %s, listener_agent = %s " "WHERE user_id = %s", (sid, self.get_argument("ip"), self.get_argument("client"), self.relay, self.agent, self.user_id)) self.append("Registered user %s record updated." % self.user_id) self.failed = False else: db.c.update("INSERT INTO r4_listeners " "(sid, user_id, listener_ip, listener_icecast_id, listener_relay, listener_agent) " "VALUES (%s, %s, %s, %s, %s, %s)", (sid, self.user_id, self.get_argument("ip"), self.get_argument("client"), self.relay, self.agent)) self.append("Registered user %s is now tuned in." % self.user_id) self.failed = False if not self.failed: u = user.User(self.user_id) u.get_listener_record(use_cache=False) if u.has_requests(): u.put_in_request_line(sid) sync_to_front.sync_frontend_user_id(self.user_id)
def setUp(self): self.user = user.User(1)
def setUp(self): self.user = user.User(1) self.user.authorize(0, "127.0.0.1", "TESTKEY")