示例#1
0
def create_event(request):
	if request.method=='POST':
		print request.POST
		#print request.body
		request_rec=ast.literal_eval(request.body)
		api_key=models.user_table.objects.filter(user_iden=request_rec['auth_token']).filter(isadmin=True).exists()
		if api_key is True:
			#request_rec=json.loads(request.POST['data'])
			user_iden=request_rec['auth_token']
			event_id=request_rec['event_id']
			event_name=request_rec['event_name']
			event_desc=request_rec['event_desc']
			event_location=request_rec['event_location']
			created_by=request_rec['created_by']
			updated_by=request_rec['updated_by']
			event_start_date=request_rec['event_start_date']
			event_end_date=request_rec['event_end_date']
			event_created_at=request_rec['event_created_at']
			event_updated_at=request_rec['event_updated_at']
			event_id_found=True
			while event_id_found is True:
				event_id=response_handling.generate_random(25)
				event_id=encrypting_hashing.hashing(user_iden,event_id)
				event_id_found=models.event_table.objects.filter(event_id=event_id).exists()
			event_created_at=int(time.time())
			(event_save,event_status)=models.event_table.objects.get_or_create(event_id=event_id,defaults={'event_name':event_name,'event_desc':event_desc,'event_location':event_location,'created_by':created_by,'updated_by':updated_by,'event_start_date':event_start_date,'event_end_date':event_end_date,'event_created_at':event_created_at,'event_updated_at':event_created_at})
			print (event_save,event_status)
			user_iden_obj=models.user_table.objects.get(user_iden=user_iden)
			event_id_obj=models.event_table.objects.get(event_id=event_id)		
			admin_status=models.event_member.objects.create(event_id=event_id_obj,user_iden=user_iden_obj,admin=True,event_gng=True,event_maybe=False,event_nt_gng=False,event_participated=False)
			print admin_status
			if event_status is True:
				data={'event_id':event_id}
				response_data=response_handling.send_response(data,iserror=False,error_code=200)
			else:
				response_data=response_handling.send_response(iserror=True,error_code=207)
		else:
			response_data=response_handling.send_response(not_found=True,error_code=203)
	else:
		response_data=response_handling.send_response(not_found=True,error_code=206)
	return HttpResponse(json.dumps(response_data), content_type="application/json")
示例#2
0
def first_page(request):
	if request.method=='POST':
		try:
			##print type(request.POST['data']),request.POST
			#print 25,request.POST['data']
			print request.body
			request_rec=ast.literal_eval(request.body)
			isemail=True
			##request_rec=json.loads(request.POST['data'])
			#print type(request_rec)
			#print 27,ast.literal_eval(request_rec)
			##print 28,json.loads(request_rec)
			#user_name=request_rec['user_id']
			f_name=request_rec['f_name']
			l_name=request_rec['l_name']
			email=request_rec['email']
			if email.lower()=='null':
				isemail=False
				email_rand_exist=True
				while email_rand_exist is True:
					email=response_handling.generate_random(10)
					email=encrypting_hashing.hashing(email,str(time.time()))
					email_rand_exist= models.user_table.objects.filter(email=email).exists()
			else:
				pass
			phone=request_rec['phone']
			if str(phone).lower()=='null':
				isemail=True
				phone_rand_exist=True
				while phone_rand_exist is True:
					phone=response_handling.generate_random(10)
					phone=encrypting_hashing.hashing(phone,str(time.time()))					
					phone_rand_exist= models.user_table.objects.filter(phone=phone).exists()
			else:
				pass
			password=request_rec['password']
			isadmin=request_rec['isadmin']
			under_admin=request_rec['under_admin']
			if under_admin is None:
				under_admin='None'
		except Exception as err:
			print 46,err
			print traceback.print_exc(file=sys.stdout)
			response_data=response_handling.send_response(iserror=True,error_code=202)
			return HttpResponse(json.dumps(response_data), content_type="application/json")
		email_phone_exists=models.user_table.objects.filter(Q(email=email) | Q(phone=phone)).exists()
		if email_phone_exists is True:
			print 'Duplicate email or phone'
			response_data=response_handling.send_response(iserror=True,error_code=204)
		elif email_phone_exists is False:
			user_iden_found=True
			while user_iden_found is True:
				user_iden=response_handling.generate_random(25)
				if isemail is True:
					user_iden=encrypting_hashing.hashing(email,user_iden)
				else:
					user_iden=encrypting_hashing.hashing(phone,user_iden)					
				user_iden_found=models.user_table.objects.filter(user_iden=user_iden).exists()
			created_at=int(time.time())
			(user_save,user_status)=models.user_table.objects.get_or_create(user_iden=user_iden,defaults={'f_name':f_name,'l_name':l_name,'email':email,'phone':phone,'password':password,'created_at':created_at,'updated_at':created_at,'isadmin':isadmin,'under_admin':under_admin})
			print (user_save,user_status)
			data={'auth_token':user_iden}
			response_data=response_handling.send_response(data,iserror=False,error_code=200)
		return HttpResponse(json.dumps(response_data), content_type="application/json")
	else:
		response_data=response_handling.send_response(not_found=True,error_code=206)
		return HttpResponse(json.dumps(response_data), content_type="application/json")
示例#3
0
def first_page(request):
    if request.method == 'POST':
        try:
            ##print type(request.POST['data']),request.POST
            #print 25,request.POST['data']
            print request.body
            request_rec = ast.literal_eval(request.body)
            isemail = True
            ##request_rec=json.loads(request.POST['data'])
            #print type(request_rec)
            #print 27,ast.literal_eval(request_rec)
            ##print 28,json.loads(request_rec)
            #user_name=request_rec['user_id']
            f_name = request_rec['f_name']
            l_name = request_rec['l_name']
            email = request_rec['email']
            if email.lower() == 'null':
                isemail = False
                email_rand_exist = True
                while email_rand_exist is True:
                    email = response_handling.generate_random(10)
                    email = encrypting_hashing.hashing(email, str(time.time()))
                    email_rand_exist = models.user_table.objects.filter(
                        email=email).exists()
            else:
                pass
            phone = request_rec['phone']
            if str(phone).lower() == 'null':
                isemail = True
                phone_rand_exist = True
                while phone_rand_exist is True:
                    phone = response_handling.generate_random(10)
                    phone = encrypting_hashing.hashing(phone, str(time.time()))
                    phone_rand_exist = models.user_table.objects.filter(
                        phone=phone).exists()
            else:
                pass
            password = request_rec['password']
            isadmin = request_rec['isadmin']
            under_admin = request_rec['under_admin']
            if under_admin is None:
                under_admin = 'None'
        except Exception as err:
            print 46, err
            print traceback.print_exc(file=sys.stdout)
            response_data = response_handling.send_response(iserror=True,
                                                            error_code=202)
            return HttpResponse(json.dumps(response_data),
                                content_type="application/json")
        email_phone_exists = models.user_table.objects.filter(
            Q(email=email) | Q(phone=phone)).exists()
        if email_phone_exists is True:
            print 'Duplicate email or phone'
            response_data = response_handling.send_response(iserror=True,
                                                            error_code=204)
        elif email_phone_exists is False:
            user_iden_found = True
            while user_iden_found is True:
                user_iden = response_handling.generate_random(25)
                if isemail is True:
                    user_iden = encrypting_hashing.hashing(email, user_iden)
                else:
                    user_iden = encrypting_hashing.hashing(phone, user_iden)
                user_iden_found = models.user_table.objects.filter(
                    user_iden=user_iden).exists()
            created_at = int(time.time())
            (user_save, user_status) = models.user_table.objects.get_or_create(
                user_iden=user_iden,
                defaults={
                    'f_name': f_name,
                    'l_name': l_name,
                    'email': email,
                    'phone': phone,
                    'password': password,
                    'created_at': created_at,
                    'updated_at': created_at,
                    'isadmin': isadmin,
                    'under_admin': under_admin
                })
            print(user_save, user_status)
            data = {'auth_token': user_iden}
            response_data = response_handling.send_response(data,
                                                            iserror=False,
                                                            error_code=200)
        return HttpResponse(json.dumps(response_data),
                            content_type="application/json")
    else:
        response_data = response_handling.send_response(not_found=True,
                                                        error_code=206)
        return HttpResponse(json.dumps(response_data),
                            content_type="application/json")
示例#4
0
def create_event(request):
    if request.method == 'POST':
        print request.POST
        #print request.body
        request_rec = ast.literal_eval(request.body)
        api_key = models.user_table.objects.filter(
            user_iden=request_rec['auth_token']).filter(isadmin=True).exists()
        if api_key is True:
            #request_rec=json.loads(request.POST['data'])
            user_iden = request_rec['auth_token']
            event_id = request_rec['event_id']
            event_name = request_rec['event_name']
            event_desc = request_rec['event_desc']
            event_location = request_rec['event_location']
            created_by = request_rec['created_by']
            updated_by = request_rec['updated_by']
            event_start_date = request_rec['event_start_date']
            event_end_date = request_rec['event_end_date']
            event_created_at = request_rec['event_created_at']
            event_updated_at = request_rec['event_updated_at']
            event_id_found = True
            while event_id_found is True:
                event_id = response_handling.generate_random(25)
                event_id = encrypting_hashing.hashing(user_iden, event_id)
                event_id_found = models.event_table.objects.filter(
                    event_id=event_id).exists()
            event_created_at = int(time.time())
            (event_save,
             event_status) = models.event_table.objects.get_or_create(
                 event_id=event_id,
                 defaults={
                     'event_name': event_name,
                     'event_desc': event_desc,
                     'event_location': event_location,
                     'created_by': created_by,
                     'updated_by': updated_by,
                     'event_start_date': event_start_date,
                     'event_end_date': event_end_date,
                     'event_created_at': event_created_at,
                     'event_updated_at': event_created_at
                 })
            print(event_save, event_status)
            user_iden_obj = models.user_table.objects.get(user_iden=user_iden)
            event_id_obj = models.event_table.objects.get(event_id=event_id)
            admin_status = models.event_member.objects.create(
                event_id=event_id_obj,
                user_iden=user_iden_obj,
                admin=True,
                event_gng=True,
                event_maybe=False,
                event_nt_gng=False,
                event_participated=False)
            print admin_status
            if event_status is True:
                data = {'event_id': event_id}
                response_data = response_handling.send_response(data,
                                                                iserror=False,
                                                                error_code=200)
            else:
                response_data = response_handling.send_response(iserror=True,
                                                                error_code=207)
        else:
            response_data = response_handling.send_response(not_found=True,
                                                            error_code=203)
    else:
        response_data = response_handling.send_response(not_found=True,
                                                        error_code=206)
    return HttpResponse(json.dumps(response_data),
                        content_type="application/json")