Example #1
0
def register_robot(request):
	data={}

	if request.method=='POST':
		logger.debug(str(request.POST))
		
		try:
			mobile=request.POST.get('mobile')
			password=request.POST.get('password')
			confirmpass=request.POST.get('confirmpass')
			own_imsi=request.POST.get('imsi')
			nick_name=request.POST.get('nick_name')
		except KeyError:
			data['status']=14
			data['error']='missing items'
			return HttpResponse(json.dumps(data,ensure_ascii=False),content_type='application/json') 
		
		if password!=confirmpass:
			data['status']=10
			data['error']='password not correct'
			return HttpResponse(json.dumps(data,ensure_ascii=False),content_type='application/json')
		# password=make_password(password)
		user_name=mobile
		logger.debug("[Register]:"+str(user_name)+" / "+str(password))
		try:
			check_user = User.objects.get(username=user_name)
			data['status']=16
			data['error']='mobile already used'
			return HttpResponse(json.dumps(data,ensure_ascii=False),content_type='application/json')
		except ObjectDoesNotExist:
			try:
				check_user_info = UserInfo.objects.get(imsi=own_imsi)
				data['status']=22
				data['error']='imsi already used'
				return HttpResponse(json.dumps(data,ensure_ascii=False),content_type='application/json')
			except ObjectDoesNotExist:
				user=User(username=user_name,password=password,is_staff=False,is_active=True,is_superuser=False)
				user.save()
				user=User.objects.get(username=user_name)
				userinfo=UserInfo(user=user)
				userinfo.imsi = own_imsi
				userinfo.nickname = nick_name
				userinfo.category = 1
				userinfo.save()
				data['status']=0
				return HttpResponse(json.dumps(data,ensure_ascii=False),content_type='application/json')

	data['status']=404
	return HttpResponse(json.dumps(data,ensure_ascii=False),content_type='application/json')	
Example #2
0
def boss_create(request):
	mobile = request.POST.get('mobile')
    	password = request.POST.get('password')
    	confirmpass = request.POST.get('confirmpass')
    	imsi = request.POST.get('imsi')
    	nick_name = request.POST.get('nick_name')
	lat = request.POST.get('lat')
	lng = request.POST.get('lng')
	desc = request.POST.get('desc')
	life = request.POST.get('life')
	reward = request.POST.get('reward')

	user=User(username=mobile,password=password,is_staff=False,is_active=True,is_superuser=False)
	user.save()

	boss = UserInfo(user=user,lat=lat, lng=lng, desc=desc, life_value=life, reward=reward)
	boss.imsi = own_imsi
	boss.nickname = nick_name
	boss.category = 3
	boss.save()