当前位置: 首页>>代码示例>>Python>>正文


Python User.is_anonymous方法代码示例

本文整理汇总了Python中rainwave.user.User.is_anonymous方法的典型用法代码示例。如果您正苦于以下问题:Python User.is_anonymous方法的具体用法?Python User.is_anonymous怎么用?Python User.is_anonymous使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rainwave.user.User的用法示例。


在下文中一共展示了User.is_anonymous方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: WSHandler

# 需要导入模块: from rainwave.user import User [as 别名]
# 或者: from rainwave.user.User import is_anonymous [as 别名]

#.........这里部分代码省略.........
				return

		if message['action'] == "ping":
			self.write_message({ "pong": { "timestamp": timestamp() } })
			return

		if message['action'] == "pong":
			self.write_message({ "pongConfirm": { "timestamp": timestamp() } })
			return

		if message['action'] == "vote":
			zeromq.publish({ "action": "vote_by", "by": self.votes_by_key })

		if message['action'] == "check_sched_current_id":
			self._do_sched_check(message)
			return

		message['action'] = "/api4/%s" % message['action']
		if not message['action'] in api_endpoints:
			self.write_message({ "wserror": { "tl_key": "websocket_404", "text": self.locale.translate("websocket_404") } })
			return

		endpoint = api_endpoints[message['action']](websocket=True)
		endpoint.locale = self.locale
		endpoint.request = FakeRequestObject(message, self.request.cookies)
		endpoint.sid = message['sid'] if ('sid' in message and message['sid']) else self.sid
		endpoint.user = self.user
		#pylint: disable=W0212
		try:
			startclock = timestamp()
			# TODO: this should be a part of prepare_standalone!
			# it's required to see if another person on the same IP address has overriden the vote
			# for the in-memory user here, so it requires a DB fetch.
			if message['action'] == "/api4/vote" and self.user.is_anonymous():
				self.user.refresh(self.sid)
			if "message_id" in message:
				if message_id == None:
					endpoint.prepare_standalone()
					raise APIException("invalid_argument", argument="message_id", reason=fieldtypes.zero_or_greater_integer_error, http_code=400)
				endpoint.prepare_standalone(message_id)
			else:
				endpoint.prepare_standalone()
			endpoint.post()
			endpoint.append("api_info", { "exectime": timestamp() - startclock, "time": round(timestamp()) })
			if endpoint.sync_across_sessions:
				if endpoint.return_name in endpoint._output and isinstance(endpoint._output[endpoint.return_name], dict) and not endpoint._output[endpoint.return_name]['success']:
					pass
				else:
					zeromq.publish({ "action": "result_sync", "sid": self.sid, "user_id": self.user.id, "data": endpoint._output, "uuid_exclusion": self.uuid })
			if message['action'] == "/api4/vote" and endpoint.return_name in endpoint._output and isinstance(endpoint._output[endpoint.return_name], dict) and endpoint._output[endpoint.return_name]['success']:
				live_voting = rainwave.schedule.update_live_voting(self.sid)
				endpoint.append("live_voting", live_voting)
				if self.should_vote_throttle():
					zeromq.publish({ "action": "delayed_live_voting", "sid": self.sid, "uuid_exclusion": self.uuid, "data": { "live_voting": live_voting } })
				else:
					zeromq.publish({ "action": "live_voting", "sid": self.sid, "uuid_exclusion": self.uuid, "data": { "live_voting": live_voting } })
		except Exception as e:
			endpoint.write_error(500, exc_info=sys.exc_info(), no_finish=True)
			log.exception("websocket", "API Exception during operation.", e)
		finally:
			self.write_message(endpoint._output)
		#pylint: enable=W0212

	def update(self):
		handler = APIHandler(websocket=True)
		handler.locale = self.locale
开发者ID:Abchrisabc,项目名称:rainwave,代码行数:70,代码来源:sync.py

示例2: RainwaveHandler

# 需要导入模块: from rainwave.user import User [as 别名]
# 或者: from rainwave.user.User import is_anonymous [as 别名]

#.........这里部分代码省略.........
				self.cleaned_args[field] = None
			else:
				parsed = type_cast(self.get_argument(field), self)
				if parsed == None and required != None:
					raise APIException("invalid_argument", argument=field, reason="%s %s" % (field, getattr(fieldtypes, "%s_error" % type_cast.__name__)), http_code=400)
				else:
					self.cleaned_args[field] = parsed

		if self.sid is None and not self.sid_required:
			self.sid = config.get("default_station")
		if self.sid == 0 and self.allow_sid_zero:
			pass
		elif not self.sid in config.station_ids:
			raise APIException("invalid_station_id", http_code=400)
		if self.sid:
			self.set_cookie("r4_sid", str(self.sid), expires_days=365, domain=config.get("cookie_domain"))

		if self.phpbb_auth:
			self.do_phpbb_auth()
		else:
			self.rainwave_auth()

		if not self.user and self.auth_required:
			raise APIException("auth_required", http_code=403)
		elif not self.user and not self.auth_required:
			self.user = User(1)
			self.user.ip_address = self.request.remote_ip

		self.user.refresh(self.sid)

		if self.user and config.get("store_prefs"):
			self.user.save_preferences(self.request.remote_ip, self.get_cookie("r4_prefs", None))

		if self.login_required and (not self.user or self.user.is_anonymous()):
			raise APIException("login_required", http_code=403)
		if self.tunein_required and (not self.user or not self.user.is_tunedin()):
			raise APIException("tunein_required", http_code=403)
		if self.admin_required and (not self.user or not self.user.is_admin()):
			raise APIException("admin_required", http_code=403)
		if self.perks_required and (not self.user or not self.user.has_perks()):
			raise APIException("perks_required", http_code=403)

		if self.unlocked_listener_only and not self.user:
			raise APIException("auth_required", http_code=403)
		elif self.unlocked_listener_only and self.user.data['lock'] and self.user.data['lock_sid'] != self.sid:
			raise APIException("unlocked_only", station=config.station_id_friendly[self.user.data['lock_sid']], lock_counter=self.user.data['lock_counter'], http_code=403)

		is_dj = False
		if self.dj_required and not self.user:
			raise APIException("dj_required", http_code=403)
		if self.dj_required and not self.user.is_admin():
			#pylint: disable=E1103
			potential_dj_ids = []
			if cache.get_station(self.sid, "sched_current") and cache.get_station(self.sid, "sched_current").dj_user_id:
				potential_dj_ids.append(cache.get_station(self.sid, "sched_current").dj_user_id)
			if cache.get_station(self.sid, "sched_next"):
				for evt in cache.get_station(self.sid, "sched_next"):
					potential_dj_ids.append(evt.dj_user_id)
			if cache.get_station(self.sid, "sched_history") and cache.get_station(self.sid, "sched_history")[-1].dj_user_id:
				potential_dj_ids.append(cache.get_station(self.sid, "sched_history")[-1].dj_user_id)
			if not self.user.id in potential_dj_ids:
				raise APIException("dj_required", http_code=403)
			is_dj = True
			#pylint: enable=E1103

		if self.dj_preparation and not is_dj and not self.user.is_admin():
开发者ID:Siqo53,项目名称:rainwave,代码行数:70,代码来源:web.py


注:本文中的rainwave.user.User.is_anonymous方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。