コード例 #1
0
ファイル: views.py プロジェクト: SanthoshBala/TigerChat
def create_room(request):
	try:
		room_name = request.GET.get('name')
		room_jid = request.GET.get('jid')
	except:
		return HttpResponseBadRequest()
	try:
		room_private = request.GET.get('room_private')
	except:
		room_private = True
	try:
		room_persistent = request.GET.get('persistent')
	except:
		room_persistent = True

	# check that name won't conflict with real princetonian
	record = get_ldap_record(room_jid)
	if record is not None:
		response_dict = {
						'name_conflict': True, 
						'name': room_name,
						'jid': 'room_jid'
						}
		response = simplejson.dumps(response_dict, default=json_handler)
		return HttpResponse(response, mimetype='application/javascript')
	owner = request.user.person
	room, created = Room.objects.get_or_create(jid=room_jid, name=room_name, private=room_private, persistent=room_persistent)
	
	if not created:
		response_dict = {
						'name_conflict': True,
						'room_name': room_name,
						'created': 'False',
						'room_jid': room_jid,
						'persistent': room_persistent,
						'room_private':room_private
						}
		response = simplejson.dumps(response_dict, default=json_handler)
		return HttpResponse(response, mimetype='application/javascript')
	room.members.add(owner)
	room.admins.add(owner)
	
	response_dict = {
						'name_conflict': False,
						'room_name': room_name,
						'created': 'True',
						'room_jid': room_jid,
						'persistent': room_persistent,
						'room_private':room_private
					}
	response = simplejson.dumps(response_dict, default=json_handler)
	return HttpResponse(response, mimetype='application/javascript')
コード例 #2
0
ファイル: views.py プロジェクト: SanthoshBala/TigerChat
def register_new_user(request):
	#  if request.method == 'POST':
		# handle POST request
	#  else:
		# handle GET
	
	#  return render_to_response('new_user.html', {'form', form})
	
	person, created = Person.objects.get_or_create(jid=request.user.username)

	if (created):
		person.user = request.user
		person.has_jabber_acct = True
	else:
		return HttpResponseRedirect('/home/')

	# Check if a system invitation exists for this person

	invites = SystemInvitation.objects.filter(invitee_netid=person.jid)
	if len(invites) == 1:
		invite = invites[0]
		invite.delete()
	else:
		pass

	ldap_record = get_ldap_record(person.jid)
	try:
		# set first_name
		if 'first_name' in ldap_record:
			person.first_name = ldap_record['first_name']
		# set last_name
		if 'last_name' in ldap_record:
			person.last_name = ldap_record['last_name']
		# set dorm
		if 'dorm' in ldap_record:
			person.dorm = ldap_record['dorm']
		# set classyear
		if 'year' in ldap_record:
			person.year = ldap_record['year']
		# set department
		if 'major' in ldap_record:
			person.major = ldap_record['major']
	except:
		person.first_name = person.jid
	person.save()
	return render_to_response('newuser.html', {'user_name': person.jid, 'first_name': person.first_name, 'last_name': person.last_name})