Ejemplo n.º 1
0
def index(request):
	'''Display login form or redirect user if logged on already'''
	response = HttpResponse()
	rLogin = login(request,'rpgEngine/login.html','next')
	if request.user.is_authenticated():
		if rpgEngineHelper.getPlayer(request.user) != None:
			return HttpResponseRedirect("/messageBox/")
		if rpgEngineHelper.getMaster(request.user) != None:
			return HttpResponseRedirect("/messageBox/")
		if rpgEngineHelper.getAdmin(request.user) != None:
			return HttpResponseRedirect("/gameList/")
		logout(request)
		return HttpResponseRedirect("/")
	response.write(rLogin.content)
	return response
Ejemplo n.º 2
0
def gameList(request):
	if rpgEngineHelper.getAdmin(request.user) == None:
		return HttpResponseForbidden()
	menu = rpgEngineHelper.getMenuList(request.user)
	form = addGameForm(auto_id=True)
	isError = False
	isError_username_alreay_exist = False
	isError_game_name_alreay_exist = False
	if (request.method == 'POST'):
		f_post = addGameForm(request.POST, auto_id=True)
		if f_post.is_valid():
			#a game has been submitted, together with details to create Master account
			#check if username already exist
			try:
				u_tmp = User.objects.get(username__exact=f_post.cleaned_data['username'])
				isError_username_alreay_exist = True
				#let previously added data in form
				form = f_post
			except User.DoesNotExist:
				pass
			if not isError_username_alreay_exist:
				#first check if Game name already exist
				try:
					g = Game.objects.get(name__exact=f_post.cleaned_data['name'])
					isError_game_name_alreay_exist = True
					#let previously added data in form
					form = f_post
				except Game.DoesNotExist:
					pass
				if not isError_game_name_alreay_exist :
					#add a user
					u = User.objects.create_user(f_post.cleaned_data['username'], '*****@*****.**', f_post.cleaned_data['password'])
					u.first_name = f_post.cleaned_data['firstname']
					u.last_name = f_post.cleaned_data['lastname']
					u.save()
					#add a Game
					g = Game()
					g.name = f_post.cleaned_data['name']
					g.iscap = 0;
					g.save()
					#load added Game to retrieve id
					g = Game.objects.get(name__exact=f_post.cleaned_data['name'])
					#add a Master
					m = Master()
					m.id = u.id
					m.gameId = g.id
					m.save()
					rpgEngineHelper.createGameStaticFolder(g.id)
		else:
			isError = True
			#let previously added data in form
			form = f_post
	game_list = rpgEngineHelper.getGameList(request.user)
	return render_to_response('rpgEngine/gameList.html', {
		'menu':menu,
		'games':game_list,
		'form':form,
		'isError':isError,
		'isError_username_alreay_exist':isError_username_alreay_exist,
		'isError_game_name_alreay_exist':isError_username_alreay_exist,
	}, context_instance=RequestContext(request))